Skip to content

Option "install-types" breaks project version dependencies. #17852

Closed as not planned
@kubotty

Description

@kubotty

Bug Report

When running mypy with the "install-types" option and the project includes pandas, the pandas-stubs package is installed into the project, causing the installation of the latest version of numpy (numpy 2.1.1). This breaks my project's dependency on numpy version 1.21.6.

To Reproduce

I have provided the minimum environment to reproduce the issue.

  • pyproject.toml
[project]
name = "mypy-debug"
version = "0.1.0"
dependencies = [
    "numpy==1.21.6",
    "pandas==1.4.4",
]
requires-python = ">=3.10, <3.11"

[project.optional-dependencies]
dev = [
    "mypy>=1.11.2",
]
  • mypy.ini
[mypy]
strict_optional = True
disallow_any_generics = True
disallow_untyped_defs = True
install_types = True

[mypy.overrides]
module = ["scipy.*", "sklearn.*"]
ignore_missing_imports = True
  • __init__.py
import pandas as pd
  • Folder Structure
.
├── src/
│   └── mypy_debug/
│        └── __ini__.py
├── mypy.ini
└── pyproject.toml
  • Environment

    • OS: Windows 11
    • Python: 3.10.11
    • Mypy
    > mypy -V
    mypy 1.11.2 (compiled: yes)
    
  • Running Command

> pip install -e ./[dev]
> mypy .\src\
src\mypy_debug\__init__.py:1: error: Library stubs not installed for "pandas"  [import-untyped]
src\mypy_debug\__init__.py:1: note: Hint: "python3 -m pip install pandas-stubs"
src\mypy_debug\__init__.py:1: note: (or run "mypy --install-types" to install all missing stub packages)
src\mypy_debug\__init__.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

Installing missing stub packages:
D:\mypy_debug\.venv\Scripts\python.exe -m pip install pandas-stubs

Collecting pandas-stubs
  Using cached pandas_stubs-2.2.2.240909-py3-none-any.whl (157 kB)
Collecting numpy>=1.23.5
  Using cached numpy-2.1.1-cp310-cp310-win_amd64.whl (12.9 MB)
Collecting types-pytz>=2022.1.1
  Using cached types_pytz-2024.2.0.20240913-py3-none-any.whl (5.3 kB)
Installing collected packages: types-pytz, numpy, pandas-stubs
  Attempting uninstall: numpy
    Found existing installation: numpy 1.21.6
    Uninstalling numpy-1.21.6:
      Successfully uninstalled numpy-1.21.6
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
mypy-debug 0.1.0 requires numpy==1.21.6, but you have numpy 2.1.1 which is incompatible.
Successfully installed numpy-2.1.1 pandas-stubs-2.2.2.240909 types-pytz-2024.2.0.20240913

[notice] A new release of pip is available: 23.0.1 -> 24.2
[notice] To update, run: python.exe -m pip install --upgrade pip

note: Run mypy again for up-to-date results with installed types

Expected Behavior

The installation process should recognize the installed version of pandas and install the matching pandas-stubs package accordingly.

Actual Behavior

The installation process installs the latest version of pandas-stubs, which forces an update of numpy and breaks the project's dependencies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions