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

Mypy with in-project virtualenv misses type errors on full path to file #7026

Closed
4 tasks done
Doekeb opened this issue Nov 14, 2022 · 2 comments
Closed
4 tasks done
Labels
status/external-issue Issue is caused by external project (platform, dep, etc)

Comments

@Doekeb
Copy link

Doekeb commented Nov 14, 2022

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:

  1. Create a new poetry project with poetry new.
  2. poetry config virtualenvs.in-project true --local.
  3. Create a simple main.py file inside the package with type annotations and an obvious violation.
  4. poetry install.
  5. Verify that poetry run mypy poetry_mypy_demo/main.py correctly produces a type error.
  6. Either poetry run mypy /full/path/to/package/main.py or poetry shell then mypy /full/path/to/package/main.py.

From MWE:

  1. Clone the MWE https://github.com/Doekeb/poetry-mypy-demo.
  2. Note, crucially, the setting virtualenvs.in-project = true as defined in poetry.toml.
  3. Note, also crucially, that poetry_mypy_demo/main.py has an obvious type violation.
  4. poetry install.
  5. Verify that poetry run mypy poetry_mypy_demo/main.py correctly produces a type error.
  6. 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.

Output of mypy -vvv ...

After poetry shell...

@Doekeb Doekeb added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Nov 14, 2022
@neersighted
Copy link
Member

neersighted commented Nov 14, 2022

Duplicate of a mypy issue: python/mypy#14042

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.

@neersighted neersighted closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2022
@neersighted neersighted added status/external-issue Issue is caused by external project (platform, dep, etc) and removed kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Nov 14, 2022
Copy link

github-actions bot commented Mar 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status/external-issue Issue is caused by external project (platform, dep, etc)
Projects
None yet
Development

No branches or pull requests

2 participants