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

Add a get_additional_deps hook to Plugin to support django-stubs #6598

Merged
merged 3 commits into from
Mar 29, 2019

Conversation

msullivan
Copy link
Collaborator

django-stubs needs to be able to add in additional dependencies to
modules and is currently using monkeypatching to do it.

That is 1) not great and 2) breaks under mypyc.
Add a hook to support generating additional dependencies from a plugin.

One thing I'm unsure about with this PR is the handling of priorities. I'm not sure that being able to specify priorities is necessary, but I am reluctant to leave them out of the API and then need to either have two hooks or a breaking change when it turns out that something does need them. The priority constants are all defined in mypy.build, which plugins probably shouldn't be importing, but moving them to a new file seems like overkill for a super marginal plugin use case.

This should allow a fix for https://github.com/mkurnikov/django-stubs/issues/48. @mkurnikov could you try updating django-stubs to work with this PR so that we can validate it and cherry-pick it for the release?

django-stubs needs to be able to add in additional dependencies to
modules and is currently using monkeypatching to do it.

That is 1) not great and 2) breaks under mypyc.
Add a hook to support generating additional dependencies from a plugin.
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left just a few minor comments.

This is good to merge, but let's wait a bit to see if this helps with the django plugin.

test-data/unit/check-custom-plugin.test Outdated Show resolved Hide resolved
mypy/plugin.py Show resolved Hide resolved
mypy/plugin.py Outdated Show resolved Hide resolved
@mkurnikov
Copy link
Contributor

I've checked in https://github.com/mkurnikov/django-stubs/pull/60, all tests pass with new hook and disabled monkeypatches
(CI fails, it is configured for stock mypy).

@msullivan msullivan merged commit 465521b into master Mar 29, 2019
@msullivan msullivan deleted the deps-hook branch March 29, 2019 00:44
JukkaL pushed a commit that referenced this pull request Mar 29, 2019
django-stubs needs to be able to add in additional dependencies to
modules and is currently using monkeypatching to do it.

That is 1) not great and 2) breaks under mypyc.
Add a hook to support generating additional dependencies from a plugin.

Priorities are defined in mypy.build (but maybe shouldn't be).
10 is a good choice for priority.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (+ an example) should be also added to mypy/docs/source/extending_mypy.rst.

@msullivan Will you have time to make a PR? I suppose this will be announced in the release blog post, it would be great to have some docs to link to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants