-
-
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
Cannot determine type of attribute class in base class #4956
Comments
This is not a bug but how mypy works. The error message can be made clearer however. The point is that inner classes are treated as types, not variables (i.e. as statically known), they cannot be re-assigned, but can be used in type annotations. On the contrary, an instance variable with type |
@ilevkivskyi Many thanks for your reply. I think it might help to explain why this is causing me a problem. My The problem then is that, with class IdMeta:
abstract = True
ordering = ('id,')
class Id(Model):
Meta = IdMeta
id = IntegerField(...)
class CreatedMeta:
abstract = True
class Created(Model):
Meta = CreatedMeta
created = DateTimeField(...)
class RealModel(Model, Id, Created):
...
|
Support of Django is a separate project and will require writing a plugin, see #3539 (there are too much magic to typecheck normally). Also it looks like we already have a very similar issue to yours #3855 with a similar motivation. So I think we can close this, feel free to re-open if you think this is a separate issue. |
Thanks; apologies - it's certainly a duplicate. Is there any way to workaround this though? At this point I would be quite happy with |
I think |
|
Can you put |
Oh no - sorry - I'm not sure how I screwed that up, that does work. Many thanks! |
Adding
object
doesn't help, nor#type: ignore
as shown above.However,
Bar.Thing
does type check; so there seems only to be a problem typing literal class-valued class attributes, when inherited. (Aside: many thanks if you can tell me the proper terminology for theseBar.Thing
andFoo.Thing
s - it's not easy to search for!)Note
Foo.Thing
is not a problem until the inheriting class is introduced on L11.The text was updated successfully, but these errors were encountered: