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

Generate an error if trying to use @final with TypedDict #7865

Merged
merged 5 commits into from
Nov 4, 2019
Merged

Generate an error if trying to use @final with TypedDict #7865

merged 5 commits into from
Nov 4, 2019

Conversation

TH3CHARLie
Copy link
Collaborator

Fixes #7849

This fix modifies function analyze_class in mypy/semanal.py, if the analyzer identifies a TypedDict, it then traverses all decorators and checks if @final exists, and if so, generate an error.

The code is very straightforward, but I think it has room for potential improvement in terms of clarity.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good, could you please add a test case for this (see test-data/unit/check-typeddict.test)

mypy/semanal.py Outdated Show resolved Hide resolved
@TH3CHARLie
Copy link
Collaborator Author

@ilevkivskyi I add a test case called testCannotUseFinalDecoratorWithTypedDict, please take a look

str_val: str

[builtins fixtures/dict.pyi]
[typing fixtures/typing-full.pyi]
Copy link
Member

Choose a reason for hiding this comment

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

Please add a newline at the end of file.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

👍

@ilevkivskyi ilevkivskyi merged commit 87720fe into python:master Nov 4, 2019
@crusaderky crusaderky mentioned this pull request Nov 20, 2019
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.

Generate an error if trying to use @final with TypedDict
2 participants