-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Plugin initialization hook #5911
Comments
It looks like you have a wrong impression about how mypy works. One does not simply parse a random file :-) We have considered some possible solutions for foreign keys. There are essentially two options:
Taking into account that both solutions will require some action from a user, and the second option already works, this is what we are going to do in short term. Later we can consider another options when we will have more experience with real code. A general comment/suggestion: don't try to implement everything at once, I would recommend releasing some 0.1-alpha version of the stubs/plugins package with some basic functionality to gather some feedback from users. Then we can adjust plugin API accordingly. |
Yes, I've realized it already. The problem is worse, those
Then, settings file could be parsed, and installed apps retrieved from a hook. It's all sounds like a lot of new features to allow only one Django plugin to work, though. Guess I'll just patch mypy submodule in the repo for now. Regarding the suggestion: I'm trying to get to a false-positive free state on the internal project in my company, 95% of the errors are those related to the |
Arghh, second option requires #5909 to be implemented and modules to parse be available in the |
You can also just put some (Also patching your local submodule is great for experiments but will have not effect for users who use "stock" mypy.) |
I have already asked about augmenting AST with new nodes in the initialization hook for plugins in
#5910
I was able to figure it out with
get_back_class_hook
and dummy base class like herehttps://github.com/mkurnikov/django-stubs/blob/master/django-stubs/conf/__init__.pyi#L7
There's another use case.
In Django there's an
INSTALLED_APPS
setting:which specifies apps to use to retrieve model definitions for database schema (using
models.py
files).Those could be used in the model definition code like this
In plugin, I can parse
to=
value, figure out the right type of a model, and set as return type of__get__
to have a proper value formember
attribute.For that I need to use
lookup_fully_qualified
https://github.com/python/mypy/blob/master/mypy/semanal.py#L3453
and this requires module to be present in the
self.modules
list.I need to create new
MypyFile
instances to populate that attr myself, butparse_file()
method belongs toBuildManager
classhttps://github.com/python/mypy/blob/master/mypy/build.py#L648
and I wasn't able to find how to access it from the
ClassDefContext
.The text was updated successfully, but these errors were encountered: