python / python/mypy

Ignore CWD for explicit package bases

Open
#14,269 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-configuration topic-usability
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Feature

Add an option (name TBD) to ignore the current directory when looking for namespace package bases.

As far as I can tell, the behavior would have to be modified here (optionally leaving out [os.getcwd()]: https://github.com/python/mypy/blob/695ea3017fee084c9d2ec17d9b28f8af905e3b63/mypy/find_sources.py#L87

Pitch

When type-checking a repository with src/ structure, there can be conflicts between installed Python modules, and directories which are located at the root of the repository (assuming that is the CWD for running mypy).
I stumbled upon this by having a directory called docker/, while also having https://pypi.org/project/docker/ installed.

As far as I could tell, there's currently no satisfactory way for mypy to accept this, besides renaming the directory.

Happy to take a stab at implementing this, if you feel it's worth adding.

Related discussion: #8584

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 in mypy/find_sources.py around line 87, where the current directory is included when finding namespace package bases. Read related discussion #8584 before deciding how the new option should be named and scoped. Done means an explicit package-base configuration can ignore the current directory without losing the intended source discovery behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.