Skip to content

Deprecate keyword args syntax for TypedDict definition #90224

Description

@97littleleaf11
BPO 46066
Nosy @gvanrossum, @JelleZijlstra, @tirkarthi, @sobolevn, @Fidget-Spinner, @AlexWaygood, @97littleleaf11
PRs
  • bpo-46066: Deprecate kwargs syntax for TypedDict definitions #31126
  • bpo-46066: catch DeprecationWarning #31428
  • 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 = <Date 2022-02-17.03:26:40.796>
    created_at = <Date 2021-12-13.15:36:57.408>
    labels = ['type-bug', 'library', '3.11']
    title = 'Deprecate keyword args syntax for TypedDict definition'
    updated_at = <Date 2022-02-20.01:44:58.632>
    user = 'https://github.com/97littleleaf11'

    bugs.python.org fields:

    activity = <Date 2022-02-20.01:44:58.632>
    actor = 'JelleZijlstra'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-17.03:26:40.796>
    closer = 'JelleZijlstra'
    components = ['Library (Lib)']
    creation = <Date 2021-12-13.15:36:57.408>
    creator = '97littleleaf11'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46066
    keywords = ['patch']
    message_count = 11.0
    messages = ['408458', '408476', '408547', '412990', '413013', '413014', '413016', '413379', '413531', '413535', '413562']
    nosy_count = 7.0
    nosy_names = ['gvanrossum', 'JelleZijlstra', 'xtreak', 'sobolevn', 'kj', 'AlexWaygood', '97littleleaf11']
    pr_nums = ['31126', '31428']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46066'
    versions = ['Python 3.11']

    Activity

    1. 97littleleaf11 commented on Dec 13, 2021

      97littleleaf11mannequin
      MannequinAuthor

      According to the docs: https://docs.python.org/3/library/typing.html?#typing.TypedDict, there are two additional equivalent syntax for TypedDict definition.

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

      However, the former one is quite confusing since we have the total keyword arg for TypedDict. In addition, PEP-589(https://www.python.org/dev/peps/pep-0589/#id19) doesn't have this.

      I think we could discard the definition syntax using keyword args in the doc.

    2. changed the title [-]Docs: TypedDict alternative definition syntax with keyword args is confusing[/-] [+][doc] TypedDict alternative definition syntax with keyword args is confusing[/+] on Dec 13, 2021
    3. changed the title [-]Docs: TypedDict alternative definition syntax with keyword args is confusing[/-] [+][doc] TypedDict alternative definition syntax with keyword args is confusing[/+] on Dec 13, 2021
    4. gvanrossum commented on Dec 13, 2021

      @gvanrossum
      Member

      This is not really just a doc issue then, is it? Maybe we should just deprecate the feature?

    5. changed the title [-][doc] TypedDict alternative definition syntax with keyword args is confusing[/-] [+]TypedDict alternative definition syntax with keyword args is confusing[/+] on Dec 14, 2021
    6. 20 remaining items

    7. AlexWaygood commented on Feb 10, 2022

      @AlexWaygood
      Member

      Just so that all the discussion related to this issue can be found in one place, here's a summary:

    8. gvanrossum commented on Feb 10, 2022

      @gvanrossum
      Member

      Go ahead and send a or to deprecate it.--
      --Guido (mobile)

    9. gvanrossum commented on Feb 10, 2022

      @gvanrossum
      Member

      "PR"

    10. AlexWaygood commented on Feb 10, 2022

      @AlexWaygood
      Member

      @guido, OP already has — Jelle and I have both reviewed and approved it :)

    11. JelleZijlstra commented on Feb 17, 2022

      @JelleZijlstra
      Member

      New changeset de6043e by 97littleleaf11 in branch 'main':
      bpo-46066: Deprecate kwargs syntax for TypedDict definitions (GH-31126)
      de6043e

    12. tirkarthi commented on Feb 19, 2022

      @tirkarthi
      Member

      This change has introduced deprecation warning in tests

      PYTHONWARNINGS=always ./python -Wall -X dev -m test.test_typing     
      ........................................................................................................................................................................................................................s................................................................................................................................................................................................./home/karthikeyan/stuff/python/cpython/Lib/test/test_typing.py:4589: DeprecationWarning: The kwargs-based syntax for TypedDict definitions is deprecated in Python 3.11, will be removed in Python 3.13, and may not be understood by third-party type checkers.
        TypedDict('Emp', _fields={'name': str, 'id': int})
      ./home/karthikeyan/stuff/python/cpython/Lib/test/test_typing.py:4602: DeprecationWarning: The kwargs-based syntax for TypedDict definitions is deprecated in Python 3.11, will be removed in Python 3.13, and may not be understood by third-party type checkers.
        TypedDict('Hi', x=1)
      ........................................

      Ran 451 tests in 0.105s

      OK (skipped=1)

    13. JelleZijlstra commented on Feb 19, 2022

      @JelleZijlstra
      Member

      Thanks, I'll send a PR.

    14. JelleZijlstra commented on Feb 20, 2022

      @JelleZijlstra
      Member

      New changeset 0a8a8e7 by Jelle Zijlstra in branch 'main':
      bpo-46066: Check DeprecationWarning in test_typing (GH-31428)
      0a8a8e7

    15. transferred this issue fromon Apr 10, 2022
    16. gvanrossum commented on Dec 22, 2022

      @gvanrossum
      Member

      @labrys

      Doesn't this cause issues for keys that are valid as keys but not as identifiers?

      To the contrary, the deprecated syntax caused issues for such keys. The syntax that isn't deprecated works fine, e.g.

      Point2D = TypedDict('Point2D', {'x': int, 'y': int, '$label$': str})
    17. labrys commented on Dec 22, 2022

      @labrys

      @gvanrossum Thanks for the quick response. I deleted my previous comment right after I posted it realizing I had entirely misread it as if the kwargs method was the one being retained.

    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 fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions