Skip to content
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

Do not allow TypedDict classes with extra keywords #16438

Merged
merged 3 commits into from Nov 18, 2023

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Nov 9, 2023

I think that sometimes metaclass= can still be used in real code, when people write compatibility layers with other metaclasses. I think that I've seen this a couple of times, but I cannot remember where and why.

In this case, this error can be precisely silenced.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

LGTM

This comment has been minimized.

mypy/semanal.py Outdated Show resolved Hide resolved

This comment has been minimized.

This comment has been minimized.

@sobolevn
Copy link
Member Author

I realized that I want to reuse existing messages:

» mypy -c 'class A(a=1, b=2): ...'
<string>:1: error: Unexpected keyword argument "a" for "__init_subclass__" of "object"  [call-arg]
<string>:1: error: Unexpected keyword argument "b" for "__init_subclass__" of "object"  [call-arg]
Found 2 errors in 1 file (checked 1 source file)

@sobolevn sobolevn changed the title Do not allow TypedDict classes with metaclass= Do not allow TypedDict classes with extra keywords Nov 17, 2023
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JelleZijlstra JelleZijlstra merged commit 058f8fd into python:master Nov 18, 2023
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants