You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note, crucially, the setting virtualenvs.in-project = true as defined in poetry.toml.
Note, also crucially, that poetry_mypy_demo/main.py has an obvious type violation.
poetry install.
Verify that poetry run mypy poetry_mypy_demo/main.py correctly produces a type error.
Either poetry run mypy /full/path/to/directory/poetry_mypy_demo/main.py or poetry shell then mypy /full/path/to/directory/poetry_mypy_demo/main.py.
Expected Behavior:
Mypy produces the same type error as in step 5.
Actual Behavior:
Mypy finishes successfully without producing any type errors with the message Success: no issues found in 1 source file.
Notes
There is no bug if step 2 is omitted. In this case, mypy correctly produces a type error when using either the relative or absolute path.
There is no bug if mypy is installed into an old-school virtual environment (pyenv + virtualenv + pip). This is the main reason that I suspect this is an issue with poetry and not with mypy.
While the conditions to reproduce this bug are very specific, this situation arises in a very typical workflow: when using VSCode, it is convenient to have virtual environments in-project since they are more easily discovered by the editor. From there, when using mypy as a linter, VSCode calls mypy in the virtual environment on the full path to the file rather than the relative path, and therefore all the conditions to reproduce the bug are present so no linting occurs even with obvious type errors.
This reproduces without Poetry in the loop; simply poetry install then source .venv/bin/activate; the same symptoms will be exhibited. The same is also the case if you poetry export and install into a virtual environment created with venv and pip.
Prerequisites
Poetry version: 1.2.2
Python version: 3.10.7
OS version and name: Manjaro Linux (rolling release)
pyproject.toml: https://gist.github.com/Doekeb/587f55d167c48654b279fde4e7334efb
Full MWE: Here
I am on the latest stable Poetry version, installed using a recommended method.
I have searched the issues of this repo and believe that this is not a duplicate.
I have consulted the FAQ and blog for any relevant entries or release notes.
If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option) and have included the output below.Issue
Under specific, but not-so-rare conditions, mypy mistakenly reports that there are no issues in the source file.
Steps to reproduce:
From Scratch:
poetry new
.poetry config virtualenvs.in-project true --local
.main.py
file inside the package with type annotations and an obvious violation.poetry install
.poetry run mypy poetry_mypy_demo/main.py
correctly produces a type error.poetry run mypy /full/path/to/package/main.py
orpoetry shell
thenmypy /full/path/to/package/main.py
.From MWE:
virtualenvs.in-project = true
as defined inpoetry.toml
.poetry_mypy_demo/main.py
has an obvious type violation.poetry install
.poetry run mypy poetry_mypy_demo/main.py
correctly produces a type error.poetry run mypy /full/path/to/directory/poetry_mypy_demo/main.py
orpoetry shell
thenmypy /full/path/to/directory/poetry_mypy_demo/main.py
.Expected Behavior:
Mypy produces the same type error as in step 5.
Actual Behavior:
Mypy finishes successfully without producing any type errors with the message
Success: no issues found in 1 source file
.Notes
pyenv
+virtualenv
+pip
). This is the main reason that I suspect this is an issue with poetry and not with mypy.Output of
mypy -vvv ...
After
poetry shell
...rm -r .mypy_cache
: output ofmypy -vvv /full/path/to/directory/poetry_mypy_demo/main.py
: https://gist.github.com/Doekeb/9063526e8dce99e5e089ef8f06655a5crm -r .mypy_cache
: output ofmypy -vvv poetry_mypy_demo/main.py
: https://gist.github.com/Doekeb/b3e8d112e531cdf3d82237e568d1c30bThe text was updated successfully, but these errors were encountered: