Make some minor fixes and improvements to the typedddicts_extra_items test#2073
Make some minor fixes and improvements to the typedddicts_extra_items test#2073rchen152 merged 2 commits intopython:mainfrom
Conversation
| class MovieWithYear(MovieBase): # OK | ||
| year: NotRequired[int | None] | ||
|
|
||
| class MovieWithDirector(MovieBase): # E[MovieWithDirector]: 'str' is not assignable to 'int | None' |
There was a problem hiding this comment.
Maybe use MovieBase2? MovieBase was defined a long way up (line 33) and has ReadOnly extra items, which adds an additional complication. The test immediately above this one probably should also have used MovieBase2.
There was a problem hiding this comment.
I intentionally used MovieBase in order to test ReadOnly extra items; the non-ReadOnly variant is already covered. Do you think it would be better to define a MovieBase3 instead of reusing MovieBase?
There was a problem hiding this comment.
I think so, it's hard to follow the tests when we reuse something that is defined so far up.
We could also use something other than movies in the test (heresy?).
There was a problem hiding this comment.
Indeed heresy ;) Done.
Summary: With this, PEP 728 support is complete! The remaining conformance failures will be fixed by python/typing#2073. Fixes #946. Reviewed By: PIG208, samwgoldman Differential Revision: D80870312 fbshipit-source-id: 7fcbfbc9e099ca1bbf9cc3ea0e06db793493293e
I'm in the process of implementing PEP 728 in Pyrefly and noticed a few things that could be improved in the corresponding conformance test.
closed=Falsewhen inheriting from a TypedDict withclosed=Trueorextra_itemswere also adding an illegal extra item in the subclass. Pyright was correctly flagging the extra item but incorrectly not flaggingclosed=False, meaning it missed the expected error but generated an unexpected one on the same line. I changed the subclass bodies topassso that the automated conformance checker can detect the missing errors.classline or thekey: typeline. I found two that were marked as expected on only theclassline, so I changed them to be allowed on either line.closed=Truebeing forbidden when subclassing a TypedDict with non-read-only extra items, so I added it. Pyright already passes it.zubannot being installed, so I addedzubanto requirements.txt.