Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate keyword args syntax for TypedDict definition #90224

Closed
97littleleaf11 mannequin opened this issue Dec 13, 2021 · 13 comments
Closed

Deprecate keyword args syntax for TypedDict definition #90224

97littleleaf11 mannequin opened this issue Dec 13, 2021 · 13 comments
Labels
3.11 bug and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@97littleleaf11
Copy link
Mannequin

97littleleaf11 mannequin commented Dec 13, 2021

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']

    @97littleleaf11
    Copy link
    Mannequin Author

    97littleleaf11 mannequin commented Dec 13, 2021

    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.

    @97littleleaf11 97littleleaf11 mannequin added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir labels Dec 13, 2021
    @97littleleaf11 97littleleaf11 mannequin added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir labels Dec 13, 2021
    @97littleleaf11 97littleleaf11 mannequin changed the title Docs: TypedDict alternative definition syntax with keyword args is confusing [doc] TypedDict alternative definition syntax with keyword args is confusing Dec 13, 2021
    @97littleleaf11 97littleleaf11 mannequin changed the title Docs: TypedDict alternative definition syntax with keyword args is confusing [doc] TypedDict alternative definition syntax with keyword args is confusing Dec 13, 2021
    @gvanrossum
    Copy link
    Member

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

    @97littleleaf11 97littleleaf11 mannequin changed the title [doc] TypedDict alternative definition syntax with keyword args is confusing TypedDict alternative definition syntax with keyword args is confusing Dec 14, 2021
    @97littleleaf11 97littleleaf11 mannequin changed the title [doc] TypedDict alternative definition syntax with keyword args is confusing TypedDict alternative definition syntax with keyword args is confusing Dec 14, 2021
    @gvanrossum
    Copy link
    Member

    I recommend opening an issue here: https://github.com/python/typing/issues/new/choose

    @97littleleaf11 97littleleaf11 mannequin changed the title TypedDict alternative definition syntax with keyword args is confusing Remove keyword args syntax for TypedDict definition Feb 4, 2022
    @97littleleaf11 97littleleaf11 mannequin changed the title TypedDict alternative definition syntax with keyword args is confusing Remove keyword args syntax for TypedDict definition Feb 4, 2022
    @AlexWaygood AlexWaygood added 3.11 bug and security fixes stdlib Python modules in the Lib dir and removed 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir labels Feb 8, 2022
    @AlexWaygood AlexWaygood changed the title Remove keyword args syntax for TypedDict definition Deprecate keyword args syntax for TypedDict definition Feb 8, 2022
    @AlexWaygood AlexWaygood added the 3.11 bug and security fixes label Feb 8, 2022
    @AlexWaygood AlexWaygood added type-bug An unexpected behavior, bug, or error and removed 3.8 only security fixes labels Feb 8, 2022
    @AlexWaygood AlexWaygood added stdlib Python modules in the Lib dir and removed 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir labels Feb 8, 2022
    @AlexWaygood AlexWaygood changed the title Remove keyword args syntax for TypedDict definition Deprecate keyword args syntax for TypedDict definition Feb 8, 2022
    @AlexWaygood AlexWaygood added the type-bug An unexpected behavior, bug, or error label Feb 8, 2022
    @AlexWaygood
    Copy link
    Member

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

    @gvanrossum
    Copy link
    Member

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

    @gvanrossum
    Copy link
    Member

    "PR"

    @AlexWaygood
    Copy link
    Member

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

    @JelleZijlstra
    Copy link
    Member

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

    @tirkarthi
    Copy link
    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)

    @JelleZijlstra
    Copy link
    Member

    Thanks, I'll send a PR.

    @JelleZijlstra
    Copy link
    Member

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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @gvanrossum
    Copy link
    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})

    @labrys
    Copy link

    labrys commented Dec 22, 2022

    @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
    Labels
    3.11 bug and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants