If plugin has same name as top-level module which has been imported before mypy runs (e.g., you are using api), mypy picks up the wrong file
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
In some circumstances, a plugin which works fine from command line fails when run from the API with:
('Found 1 error in 1 file (errors prevented further checking)\n', '/data/users/ezyang/b/pytorch/mypy.ini:5:1: error: Plugin "/data/users/ezyang/b/pytorch/test/typing/../../mypy_plugins/sympy.py" does not define entry point function "plugin" [misc]\n', 2)
The problem appears to occur when the a filepath plugin is provided which has the same name as a top level module that has already been imported when mypy runs.
To Reproduce
- Create a plugin
mypy_plugins/sympy.py, any plugin code is fine, it doesn't matter (you will never hit/import the plugin code) - Direct mypy to use the plugin
plugins = mypy_plugins/sympy.py - Run mypy via the API on some test file (doesn't matter):
from mypy import api
import sympy
print(api.run(['--config-file', 'mypy.ini', 'test.py']))
Expected Behavior Plugin loads successfully, as it does when you call mypy directly
Actual Behavior Fails with "/data/users/ezyang/b/pytorch/test/typing/../../mypy_plugins/sympy.py" does not define entry point function "plugin"
Your Environment
- Mypy version used: 1.8.0
- Python version used: Python 3.10
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure by importing sympy before calling mypy.api.run with mypy.ini and mypy_plugins/sympy.py, then compare it with a direct mypy invocation. Trace how the filepath plugin is resolved when a same-named top-level module is already imported; done means both invocation paths load the plugin successfully and the reported entry-point error is gone.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100