python / python/mypy

`MYPYPATH` is not being used when no modules or packages are specified

Open
#16,775 4 comments 2 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 doing unit tests on some files where I make some assertions using typing.assert_type, and want to run mypy on these files. I need to specify a custom stubs directory, and I've tried using mypy_path with no success. It looks like it is only taken into account if modules (-m) or packages (-p) are being specified?

https://github.com/python/mypy/blob/1fd29ac54a2135ec1d1d30289c625d12e6198eac/mypy/main.py#L1405-L1410

I'm basically running mypy like the following: MYPYPATH=/path/to/custom/stubs mypy file_under_test.py

Is there a reason/technical limitation to not take it into account?

Thanks!

To Reproduce

See command above

Your Environment

  • Mypy version used: 1.8.0

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

Start by reproducing the command shown in the issue, then inspect mypy/main.py around lines 1405-1410 to trace how file arguments differ from module or package arguments. The work is done when MYPYPATH is honored for a direct file invocation and the behavior is covered by an appropriate regression check.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.