GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Allow TypedDict to inherit from Generics · Issue #89026 · python/cpython

Allow TypedDict to inherit from Generics #89026

New issue
Copy link
New issue
Copy link
Closed
Closed
Allow TypedDict to inherit from Generics#89026
Copy link
Labels
3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancementA feature request or enhancement

Description

sransara
mannequin
opened on Aug 7, 2021
Issue body actions
BPO 44863
Nosy @gvanrossum, @rhettinger, @serhiy-storchaka, @graingert, @JelleZijlstra, @sobolevn, @Fidget-Spinner, @AlexWaygood, @sransara, @cdce8p, @toburger
PRs
  • bpo-44863: In TypedDict allow inherit from Generic and preserve bases #27663
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2021-08-07.19:04:47.278>
    labels = ['type-feature', 'library', '3.11']
    title = 'Allow TypedDict to inherit from Generics'
    updated_at = <Date 2022-03-07.00:48:26.270>
    user = 'https://github.com/sransara'

    bugs.python.org fields:

    activity = <Date 2022-03-07.00:48:26.270>
    actor = 'rhettinger'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2021-08-07.19:04:47.278>
    creator = 'sransara'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44863
    keywords = ['patch']
    message_count = 8.0
    messages = ['399201', '399579', '401077', '401087', '401134', '401138', '412439', '414631']
    nosy_count = 12.0
    nosy_names = ['gvanrossum', 'rhettinger', 'python-dev', 'serhiy.storchaka', 'graingert', 'JelleZijlstra', 'sobolevn', 'kj', 'AlexWaygood', 'sransara', 'cdce8p', 'toburger']
    pr_nums = ['27663']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue44863'
    versions = ['Python 3.11']

    Reacted by Felipe S. S. Schneider and Jacob Stevens-Haas

    Activity

    1. sransara commented on Aug 7, 2021

      @sransara
      sransaramannequin
      on Aug 7, 2021
      MannequinAuthor
      More actions

      TypedDict PEP-589 says:
      A TypedDict cannot inherit from both a TypedDict type and a non-TypedDict base class.

      So the current implementation has:
      if type(base) is not _TypedDictMeta: raise TypeError(...)

      This restricts the user from defining generic TypedDicts in the natural class based syntax:
      class Pager(TypedDict, Generic[T]): ...

      Although PEP-589 doesn't explicitly state generic support, I believe it is complete in covering the specification even if generics were involved (at least for the class based syntax).

      I have tried putting together a PEP from guidance of typing-sig <https://github.com/sransara/py-generic-typeddict/blob/master/pep-9999.rst\>. There is not much new contributions by that draft, except for specifying the alternative syntax and being more explicit about Generics.

      So I'm wondering if it would be possible to relax the constraint: TypedDict inheritance to include Generic. In my point of view Generic is more of a mixin, so it doesn't go against the PEP-589. Or is this change big enough to warrant a PEP?

    2. sransara
      added
      3.10 (EOL)end of lifeend of life
      3.11only security fixesonly security fixes
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancementA feature request or enhancement
      on Aug 7, 2021
    3. gvanrossum commented on Aug 14, 2021

      @gvanrossum
      gvanrossum
      on Aug 14, 2021
      Member
      More actions

      See also python/mypy#3863

    4. Fidget-Spinner commented on Sep 5, 2021

      @Fidget-Spinner
      Fidget-Spinner
      on Sep 5, 2021
      Member
      More actions

      Guido, OP has kindly written a mini PEP for this. Do you think just updating PEP-589 is sufficient, or do we need a full PEP?

      (PS. Changed version to 3.11 since we've missed the train for 3.10 enhancements).

    5. Fidget-Spinner
      removed
      3.10 (EOL)end of lifeend of life
      on Sep 5, 2021
    6. gvanrossum commented on Sep 5, 2021

      @gvanrossum
      gvanrossum
      on Sep 5, 2021
      Member
      More actions

      Updating an existing (standards track) PEP significantly is not
      traditional. I recommend writing a new PEP.

      On Sun, Sep 5, 2021 at 01:24 Ken Jin <[email protected]> wrote:

      Ken Jin <[email protected]> added the comment:

      Guido, OP has kindly written a mini PEP for this. Do you think just
      updating PEP-589 is sufficient, or do we need a full PEP?

      (PS. Changed version to 3.11 since we've missed the train for 3.10
      enhancements).

      ----------
      versions: -Python 3.10


      Python tracker <[email protected]>
      <https://bugs.python.org/issue44863\>


      --
      --Guido (mobile)

    7. sransara commented on Sep 6, 2021

      @sransara
      sransaramannequin
      on Sep 6, 2021
      MannequinAuthor
      More actions

      My initial intention to create this ticket was to explore the idea that if we could side step from creating a PEP or updating PEP-589.

      IMO only contribution from a new PEP will be:

      1. relaxing this line from PEP-589 and be explicit to include Generic: "A TypedDict cannot inherit from both a TypedDict type and a non-TypedDict base class." (IMO by thinking Generic as a mixin even this is not needed)
      2. may be syntax for generic in the alternative syntax (side note: collecting typevars from the values is hard to implement because of forward refs)
      3. Some explicit generic examples for good measure

      I believe PEP-589 is complete in covering all semantic details even with Generics. Even structural subtyping because it says: "Value types behave invariantly, since TypedDict objects are mutable."

      My understanding was that during initial implementation this was not done for the sake of implementation simplicity (days before PEP-560).

      All that said, a new PEP would be a good way to notify the type checkers of this capability.

      Is there a better place to have this conversation?

    8. gvanrossum commented on Sep 6, 2021

      @gvanrossum
      gvanrossum
      on Sep 6, 2021
      Member
      More actions

      Since this primarily affects static type checkers such as mypy, Pyre and pyright, it’s best to discuss it on typing-sig.

    9. graingert commented on Feb 3, 2022

      @graingert
      graingertmannequin
      on Feb 3, 2022
      Mannequin
      More actions

      there's a thread on typing-sig for this now: https://mail.python.org/archives/list/[email protected]/thread/I7P3ER2NH7SENVMIXK74U6L4Z5JDLQGZ/#I7P3ER2NH7SENVMIXK74U6L4Z5JDLQGZ

      Reacted by Felipe S. S. Schneider
    10. rhettinger commented on Mar 7, 2022

      @rhettinger
      rhettinger
      on Mar 7, 2022
      Contributor
      More actions

      Related issue: https://bugs.python.org/issue43923

    11. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    12. AlexWaygood
      added
      topic-typing
      on Apr 13, 2022
    13. JelleZijlstra commented on May 3, 2022

      @JelleZijlstra
      JelleZijlstra
      on May 3, 2022
      Member
      More actions

      This will be in Python 3.11 (#27663). Thanks @sransara for the PR and @serhiy-storchaka, @uriyyo, @Fidget-Spinner, @davidfstr, and @sobolevn for reviewing it!

      Reacted by rego, Taine Zhao, Hoël Bagard, Balazs Erdos, Felipe S. S. Schneider, Oliver Mannion and Jacob Stevens-Haas
    14. JelleZijlstra
      closed this as completedon May 3, 2022
    15. Fatal1ty
      added a commit that references this issue on Jan 22, 2023

      Add support for generic TypedDict following python/cpython#89026

      985e91a
    16. olivm-fr
      added a commit that references this issue on Mar 23, 2026

      chore: add type annotations to woob.tools.value

      31eea21
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancementA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402520 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.