python / python/mypy

Cannot exclude __init__.py without excluding the entire dir

Open
#10,946 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report

To Reproduce

$ mkdir foo
$ cd foo
$ mkdir testpkg
$ echo "def f(): pass" > testpkg/__init__.py
$ echo "def g(): pass" > testpkg/foo.py

$  mypy --disallow-untyped-defs --exclude "fo" testpkg   # <--- excludes foo.py
testpkg/__init__.py:1: error: Function is missing a return type annotation
testpkg/__init__.py:1: note: Use "-> None" if function does not return a value
Found 1 error in 1 file (checked 1 source file)

$ mypy --disallow-untyped-defs --exclude "init" testpkg   # <---- should exclude __init__.py
testpkg/__init__.py:1: error: Function is missing a return type annotation
testpkg/__init__.py:1: note: Use "-> None" if function does not return a value
testpkg/foo.py:1: error: Function is missing a return type annotation
testpkg/foo.py:1: note: Use "-> None" if function does not return a value
Found 2 errors in 2 files (checked 1 source file)

Expected Behavior

__init__.py should be ignored in the last command

Actual Behavior

__init__.py was not ignored in the last command

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: see above
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.7.3
  • Operating system and version: Debian 10

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 two mypy commands using testpkg/init.py and testpkg/foo.py, comparing the --exclude "fo" and --exclude "init" results. Trace how the exclude pattern is applied to discovered files, then add coverage showing that __init__.py is ignored by the latter pattern while foo.py remains checked.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.