Skip to content

Docs: TypedDict is now of type function instead of class #86139

Closed

Description

@gaborbernat
BPO 41973
Nosy @gvanrossum, @ssbarnea, @serhiy-storchaka, @asottile, @gaborbernat, @Fidget-Spinner, @akulakov

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 2020-10-08.06:26:46.964>
labels = ['3.11', '3.9', '3.10', 'docs']
title = 'Docs: TypedDict is now of type function instead of class'
updated_at = <Date 2021-08-01.18:01:50.338>
user = 'https://github.com/gaborbernat'

bugs.python.org fields:

activity = <Date 2021-08-01.18:01:50.338>
actor = 'serhiy.storchaka'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation = <Date 2020-10-08.06:26:46.964>
creator = 'gaborjbernat'
dependencies = []
files = []
hgrepos = []
issue_num = 41973
keywords = []
message_count = 7.0
messages = ['378212', '378213', '378216', '378217', '398707', '398717', '398718']
nosy_count = 8.0
nosy_names = ['gvanrossum', 'ssbarnea', 'docs@python', 'serhiy.storchaka', 'Anthony Sottile', 'gaborjbernat', 'kj', 'andrei.avk']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue41973'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

Linked PRs

Activity

  1. gaborbernat commented on Oct 8, 2020

    gaborbernatmannequin
    MannequinAuthor

    ❯ py -3.8 -c 'from typing import TypedDict; print(type(TypedDict))'
    <class 'typing._TypedDictMeta'>

    ❯ py -3.9 -c 'from typing import TypedDict; print(type(TypedDict))'
    <class 'function'>

    Python 3.9 changed the type of the TypedDict but the documentation still says it's a class - see https://docs.python.org/3.9/library/typing.html#typing.TypedDict. I must also say I'm suprised you can inherit from a function, but we should update the documentation to reflect that the type of the element in question is no longer class.

  2. added
    3.10 (EOL)
    3.9 (EOL)
    on Oct 8, 2020
  3. asottile commented on Oct 8, 2020

    asottilemannequin
    Mannequin
  4. gaborbernat commented on Oct 8, 2020

    gaborbernatmannequin
    MannequinAuthor

    Static checkers/linters (see e.g. pylint-dev/pylint#3884) are caught of guard by being able to inherit from functions. They'll need to adapt, but let's update the documentation to reflect this.

  5. gaborbernat commented on Oct 8, 2020

    gaborbernatmannequin
    MannequinAuthor

    This seem to apply to typing.NamedTuple too.

  6. akulakov commented on Aug 1, 2021

    @akulakov
    Contributor

    I haven't looked too much into typing module, so take this with a grain of salt, but my understanding is that TypedDict is a special construct (as the first sentence in the docs defines it), which can be used as a base. I think most users would consider something a kind of a class if it can be inherited from by a user-defined class, so this classification in the docs is useful.

    Normally functions can't be used as a base of course. There's no "inheritable from" abc or anything like that and functions are not inherited from "function type". You generally don't care if something is a function, you care if it's a callable and test for that with callable().

    So in a sense a function is the most inherently duck typed object in Python.

    The only way for a specific check of a function type is AFAIK type(known_function) == type(myobj), but this type of checking is discouraged.

    So static checkers that run into a problem with this are probably assuming too much about what a function is or should be in Python.

    To sum up, TypedDict is a kind of a construct between a class and a function that's more usefully documented as, and used as, a class. The docs make it very clear that it's not your usual, run of the mill class.

  7. serhiy-storchaka commented on Aug 1, 2021

    @serhiy-storchaka
    Member

    TypeDict is a callable, it can be used as

        Point2D = TypedDict('Point2D', x=int, y=int, label=str)

    It can also be used as a base in class definition, but is is not a class itself. It does not occur in __bases__ of the created class, and it cannot be used in isinstance() and issubclass() checks. It is just yet one weird way to customize class creation.

    I agree that documenting it as class is not correct. Perhaps it should be declared as a function (with specifying its signature when used as a function) and referred with the :data: role.

  8. serhiy-storchaka commented on Aug 1, 2021

    @serhiy-storchaka
    Member

    Actually most names defined in typing are no longer classes.

  9. added
    docs
    3.11
    on Aug 1, 2021
  10. added
    docs
    on Aug 1, 2021
  11. 5 remaining items

  12. added
    3.12
    3.13
    on Jun 27, 2023
  13. added a commit that references this issue on Jan 11, 2026
  14. added 2 commits that reference this issue on Jan 11, 2026
  15. added 2 commits that reference this issue on Jan 11, 2026
  16. StanFromIreland commented on Jan 12, 2026

    @StanFromIreland
    Member

    This introduced a regression in the docs #143728.

  17. added a commit that references this issue on Jan 12, 2026
  18. AlexWaygood commented on Jan 13, 2026

    @AlexWaygood
    Member

    This introduced a regression in the docs #143728.

    Yes, we had to revert using the .. function:: role for these symbols in the docs, because it meant that the TypedDict.__total__ attribute, for example, was incorrectly rendered by Sphinx. But that means that there's nothing more to be done here.

  19. added a commit that references this issue on Feb 15, 2026
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.113.123.13docstopic-typing

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions