-
-
Notifications
You must be signed in to change notification settings - Fork 500
Auto inherit from TypedModelMeta
#2788
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
Auto inherit from TypedModelMeta
#2788
Conversation
b12ec1a
to
8d06a49
Compare
8d06a49
to
7610690
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, see why test is failing
typed_model_meta_info = self.lookup_typeinfo(fullnames.TYPED_MODEL_META_FULLNAME) | ||
if typed_model_meta_info and not meta_node.has_base(fullnames.TYPED_MODEL_META_FULLNAME): | ||
# Insert TypedModelMeta just before `object` to leverage mypy's class-body semantic analysis. | ||
meta_node.mro.insert(-1, typed_model_meta_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add this base class to ClassDef
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think because we could endup with multiple TypedModelMeta
in the mro for multiple inheritance cases.
I think I found the issue, this was because So depending on how mypy was resolving the module deps, we could sometime check a file before I've updated the test to have concrete models at some point. Supporting dangling abstract model will add too much complexity, I don't think it's worth it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff! Thanks again!
I have made things!
(Review per commit advised, the first one is a minor cleanup)
Implement the suggestion in #1375 (comment) providing automatic type-checking of Django models
Meta
class by artificially insertingTypedModelMeta
in the mro.The error message might be slightly confusing since the user did not add an explicit base class but I think is comprehensible enough and that the value outweigh the slightly weird message. For ex:
I've also tested this change on a rather large Django codebase (1M python LoC) adding errors that were all caught properly.