Skip to content

Make some minor fixes and improvements to the typedddicts_extra_items test #2073

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rchen152
Copy link
Collaborator

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.

  • The tests for setting closed=False when inheriting from a TypedDict with closed=True or extra_items were also adding an illegal extra item in the subclass. Pyright was correctly flagging the extra item but incorrectly not flagging closed=False, meaning it missed the expected error but generated an unexpected one on the same line. I changed the subclass bodies to pass so that the automated conformance checker can detect the missing errors.
  • Most of the errors on specific TypedDict items are marked as allowing to occur on either the class line or the key: type line. I found two that were marked as expected on only the class line, so I changed them to be allowed on either line.
  • I didn't see a test for closed=True being forbidden when subclassing a TypedDict with non-read-only extra items, so I added it. Pyright already passes it.
  • I also added a test verifying that a type checker flags the case of an item having a type that is incompatible with read-only extra items. Pyright passes this as well.
  • The update script emitted a warning about zuban not being installed, so I added zuban to requirements.txt.


class MovieWithYear(MovieBase): # OK
year: NotRequired[int | None]

class MovieWithDirector(MovieBase): # E[MovieWithDirector]: 'str' is not assignable to 'int | None'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed heresy ;) Done.

@srittau srittau added the topic: conformance tests Issues with the conformance test suite label Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: conformance tests Issues with the conformance test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants