Skip to content

PEP 655 (Required TypedDict items) tracker #6301

Closed

Description

@srittau

This issue is supposed to track when we can start to use Required/NotRequired (PEP 655) in typeshed. Support is needed in released versions of:

Activity

  1. JelleZijlstra commented on Nov 15, 2021

    @JelleZijlstra
    Member

    I feel like we should also wait for the PEP to be accepted. typing-extensions can include experimental features that may be rejected, but typeshed should not.

  2. srittau commented on Dec 22, 2021

    @srittau
    CollaboratorAuthor

    This is now fully supported in mypy.

  3. JelleZijlstra commented on Dec 22, 2021

    @JelleZijlstra
    Member

    I think it supports only one of Required and NotRequired? That's what the initial PR said but I haven't verified with the release.

  4. srittau commented on Dec 22, 2021

    @srittau
    CollaboratorAuthor

    Quick tests confirms that it works with both:

    from typing_extensions import TypedDict, Required, NotRequired
    
    class NonTotal(TypedDict, total=False):
        foo: int
        bar: Required[str]
        
    nt1: NonTotal = {"foo": 123, "bar": ""}
    nt2: NonTotal = {"foo": "", "bar": 123}  # incompatible types
    nt3: NonTotal = {"foo": 123}  # missing key "bar"
    nt4: NonTotal = {"bar": ""}
    
    class Total(TypedDict, total=True):
        foo: int
        bar: NotRequired[str]
        
    t1: Total = {"foo": 123, "bar": ""}
    t2: Total = {"foo": "", "bar": 123}  # incompatible types
    t3: Total = {"bar": ""}  # missing key "foo"
    t4: Total = {"foo": 123}  
  5. gregoiredx commented on Mar 31, 2022

    @gregoiredx

    Hello @srittau, just to let you know you can check the "PEP accepted" checkbox, see https://groups.google.com/g/dev-python/c/odKM_OpDES0 and https://peps.python.org/pep-0655/

  6. srittau commented on Mar 31, 2022

    @srittau
    CollaboratorAuthor

    Thanks, done!

  7. srittau commented on Jun 17, 2022

    @srittau
    CollaboratorAuthor

    I've used NotRequired in #8089 and our tests passed. So it seems that pytype at least accepts NotRequired, even if it doesn't fully support it, which would be enough for me. Cc @rchen152 for feedback.

    Also cc @pradeep90 and @shannonzhu: Does pyre support Required/NotRequired for TypedDict?

  8. pradeep90 commented on Jun 19, 2022

    @pradeep90
    Contributor

    I've used NotRequired in #8089 and our tests passed. So it seems that pytype at least accepts NotRequired, even if it doesn't fully support it, which would be enough for me. Cc @rchen152 for feedback.

    Also cc @pradeep90 and @shannonzhu: Does pyre support Required/NotRequired for TypedDict?

    @srittau No, we don't yet support Required/NotRequired. I'll implement it by the end of the month.

  9. lancelote commented on Jun 30, 2022

    @lancelote
    Contributor
  10. pradeep90 commented on Jun 30, 2022

    @pradeep90
    Contributor

    @srittau No, we don't yet support Required/NotRequired. I'll implement it by the end of the month.

    Added support in Pyre v0.9.15.

  11. srittau commented on Jun 30, 2022

    @srittau
    CollaboratorAuthor

    Since the pytype checks run against the zxcvbn stubs, which already use NotRequired successfully and all other type checkers support it, I'm closing this. 🎉

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

    project: feature trackerTracks whether a typing feature can be used in typeshed stubs

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions