python / python/mypy

Type checking a system-install package yields erronous results

Open
#10,532 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

I'm working on todoman a cli app which I have installed on my system since, well, it's a cli app that I use interactively daily.

I'm working on adding type hints to this project, so I have it installed the development code a virtualenv (pip install -e .) and also installed mypy and other developer tools in that virtualenv.

When I run mypy, it seems to read type definitions from my system-installed version of todoman, so type checking does not match what's inside the repository checkout.

In other words, when there's a from todoman import X, mypy seems to read the system library, and not the $(pwd)/virtualenv one. That one lacks type definitions, so the results are skewed.

To Reproduce

  1. Install todoman using your system package manager (in my case pacman -S todoman ).
  2. git clone --branch typing2 https://github.com/pimutils/todoman.git
  3. cd todoman && mkvirtualenv todoman && pip install -e . && pip install mypy
  4. Make sure nothing in caching your $PATH here and run which mypy.
  5. mypy todoman.

Expected Behavior

mypy should fail here, since there's a type-checking error in the checked out brach.

Actual Behavior

mypy passes, since it seems to read the system install libraries which have no type hints.

Your Environment

➜ mypy --version
mypy 0.812

➜ cat .config/mypy/config
[mypy]
ignore_missing_imports = True
cache_dir = $HOME/.cache/mypy

➜ python --version
Python 3.9.5

➜ uname -srmo
Linux 5.12.6-arch1-1 x86_64 GNU/Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the listed pacman, editable-install, virtualenv, and mypy todoman steps, checking which mypy and the reported versions first. Trace why the system-installed package is selected instead of the checkout, and consider the issue done when the checked-out package is type-checked and the reported error is detected.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.