-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
class inside a class #3855
Comments
Hm, interesting. There is an ongoing project writing stubs for django (https://github.com/machinalis/mypy-django) -- maybe that has a solution already, or maybe someone on that project can help you if you file an issue there? |
Thank you for the tip. I opened an issue on there project. But I think this problem is not django specific. I don't know if classes in classes is a good style, but another projects may also use them. |
It's pretty uncommon outside Django's patterns. |
This one is actually quite straightforward to fix. The symbol table nodes for nested classes are created in the first pass (when little is known) so that their types are set to |
This is closed by #5926 that emits a better error message, and accepts safe use cases (e.g. when one nested class is a subclass of another nested class). Note that mypy still emits an error on the original example, because it is technically unsafe. Note however that @mkurnikov works on a mypy plugin for Django that will suppress this error for Django specific use cases. |
Also for those who don't want to use the Django mypy plugin, or if you want to silence this error for other reason you can either just put Unsafe: Any = object
class A:
class Sub(Unsafe):
pass
class B:
class Sub(Unsafe):
pass
class C(A, B): # no complains from mypy
pass Note however it will disable many checks for |
I am trying to use mypy on an existing django project. In Django models can have a special sub-class Meta and the Models can inherit from each other. Therefore I have a situation like this one:
mypy reports an error on the FooBar class definition:
I am not sure if a missed a feature that would solve this. I think there should be a way to define the type sub class. For example with:
The text was updated successfully, but these errors were encountered: