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

Many classes should be decorated as @final #11179

Open
sobolevn opened this issue Sep 23, 2021 · 0 comments
Open

Many classes should be decorated as @final #11179

sobolevn opened this issue Sep 23, 2021 · 0 comments
Labels
feature needs discussion topic-developer Issues relevant to mypy developers topic-final PEP 591

Comments

@sobolevn
Copy link
Member

sobolevn commented Sep 23, 2021

While working on several mypy plugins I had often step on the fact you cannot subclass any of the mypy classes, because they are compiled with mypyc. It caused runtime TypeError in the plugin's code.

But, when I was trying to run mypy on the plugin's code - it was fine, no error was shown. Because type are not @final and mypy is not able to understand that this is a problem.

So, I propose to add explicit @final annotations to almost all types, exception:

  • Types with allow_interpreted_subclasses
  • Types that are subclassed inside mypy itself: Node, Expression, TypeQuery, etc

One more strong point to making this change is that many classes are not "designed" to be subclassed.
So, this should not be a problem.

Related #10125
Related #9602

@AlexWaygood AlexWaygood added topic-developer Issues relevant to mypy developers topic-final PEP 591 labels Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature needs discussion topic-developer Issues relevant to mypy developers topic-final PEP 591
Projects
None yet
Development

No branches or pull requests

3 participants