I'm hoping to get started on the mypy implementation later this weekend, after integrating the previous week's feedback into the PEP draft.
Famous last words. :) I've managed to clear everything off my plate now and so am now actually starting the mypy implementation of Required[] / NotRequired[]. AKA PEP 655. However I am mindful of some upcoming timelines: * Python 3.10a7 (the last alpha) is scheduled for April 5th (in 4 days). I think this may be a last point where a new feature like Required[] can be introduced for Python 3.10. * The Steering Council will need to ultimately review PEP 655 before this feature is merged into CPython/mypy. I understand they have about a month of backlog in reviewing items at this busy time. There is a small amount of feedback that ideally I'd like to integrate before submitting the PEP to the Steering Council but I'm running out of time: * > Are `Required` and `NotRequired` supported only in the class form of a TypedDict? - I'm leaning toward allowing it in the alternative syntax but I really want experience implementing in mypy first before making a decision. If it looks at all challenging to implement, I may lean toward no, since the alternative syntax is effectively deprecated in most new code anyway. * I'm wondering if updating the introspective functions of the "typing" module [1] might involve non-trivial changes that should be discussed in the PEP. I don't have enough experience with this code to discover issues before attempting implementation. Would folks recommend that I submit the current draft of PEP 655 to the Steering Council while I'm still working on the mypy implementation, potentially discovering small issues to integrate into the PEP later, or should I wait until I finish the implementation and thus have very high confidence that all issues have been addressed in the PEP? [1]: https://docs.python.org/3/library/typing.html#introspection-helpers -- David Foster | Seattle, WA, USA Contributor to TypedDict support for mypy On 3/6/21 9:01 AM, David Foster wrote:
On 3/2/21 1:17 PM, Eric Traut wrote:
David, the PEP is looking good.
I just published a version of pyright (1.1.117) that has support for the latest draft of the PEP. It was pretty straightforward to implement. Here's a [link to the change](https://github.com/microsoft/pyright/commit/7ed245b1845173090c6404e49912e8cb...) in case maintainers of other type checkers would like to take a look at the test cases or implementation details.
Fantastic!
I'm hoping to get started on the mypy implementation later this weekend, after integrating the previous week's feedback into the PEP draft.
There were a few questions that I ran across in the implementation that were not answered in the latest draft of the PEP.
1. How do `Required` and `NotRequired` interact with `Annotated` (PEP 593)? I assume that an `Annotated` can be contained within a `Required` or `NotRequired`, but the converse is not true.
Agreed. That makes sense to me.
2. Are `Required` and `NotRequired` supported only in the class form of a TypedDict? Or are they supported in the alternative syntax? For now, I have implemented it such that any use of `Required` and `NotRequired` outside of a TypedDict class definition is considered an error, so it is not allowed in the alternative syntax.
I'm leaning toward allowing Required[] and NotRequired[] in the alternative syntax [1] since it already supports specifying totality.
[1]: https://www.python.org/dev/peps/pep-0589/#alternative-syntax