Skip to content

PEP 655 (Required TypedDict items) tracker #6301

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

Closed
5 of 6 tasks
srittau opened this issue Nov 15, 2021 · 11 comments
Closed
5 of 6 tasks

PEP 655 (Required TypedDict items) tracker #6301

srittau opened this issue Nov 15, 2021 · 11 comments
Labels
project: feature tracker Tracks whether a typing feature can be used in typeshed stubs

Comments

@srittau
Copy link
Collaborator

srittau commented Nov 15, 2021

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:

@srittau srittau added the project: feature tracker Tracks whether a typing feature can be used in typeshed stubs label Nov 15, 2021
@JelleZijlstra
Copy link
Member

JelleZijlstra commented Nov 15, 2021

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.

@srittau
Copy link
Collaborator Author

srittau commented Dec 22, 2021

This is now fully supported in mypy.

@JelleZijlstra
Copy link
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.

@srittau
Copy link
Collaborator Author

srittau commented Dec 22, 2021

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}  

@gregoiredx
Copy link

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/

@srittau
Copy link
Collaborator Author

srittau commented Mar 31, 2022

Thanks, done!

@srittau
Copy link
Collaborator Author

srittau commented Jun 17, 2022

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?

@pradeep90
Copy link
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.

@lancelote
Copy link
Contributor

Available in PyCharm >= 2022.2 EAP 4 https://youtrack.jetbrains.com/issue/PY-53611/Support-PEP-655-typingRequiredtypingNotRequired-for-TypedDicts

@pradeep90
Copy link
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.

@srittau
Copy link
Collaborator Author

srittau commented Jun 30, 2022

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. 🎉

@srittau srittau closed this as completed Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: feature tracker Tracks whether a typing feature can be used in typeshed stubs
Projects
None yet
Development

No branches or pull requests

5 participants