Skip to content

Please revert new source finding behaviour or add some way to exclude paths #9981

Closed
@intgr

Description

@intgr

Bug Report

I think the PR "find_sources: find build sources recursively" #9614 is a good and worthwhile change. But in practice it causes surprising regressions for many users. It's not just spurious warnings, mypy often refuses to run entirely ("Found 1 error in 1 file (errors prevented further checking)").

In many cases, there aren't good work-arounds, short of restructuring one's project directory tree.

I think the magnitude of this issue is large enough that the best course of action is to revert the change and issue a hotfix release, until some work-around for those cases is created.

There are many examples of common things that throw off mypy:

  1. Creating even an empty virtualenv causes mypy to fail to run.
  2. Having __init__.py files under any directory that's not a valid Python module name.
  3. Many npm packages include .py files, which get installed in node_modules directory, some of which may have Python 2.7 code that causes syntax errors.
  4. Having copies of directories or files with same .py file names.

Some more examples in comments here: #4675 (comment)

To Reproduce

% mkdir test1
% cd test1
% echo 'a: str = 10' > test.py
% mkdir -p test/invalid-module
% touch test/invalid-module/__init__.py
% mypy .
invalid-module is not a valid Python package name
% mkdir test2
% cd test2
% python3 -m venv ./venv
% echo 'a: str = 10' > test.py
% mypy .
venv/lib/python3.9/site-packages/setuptools/_distutils/command/bdist_msi.py:355: error: expected an indented block
Found 1 error in 1 file (errors prevented further checking)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
% mkdir test3
% cd test3
% echo 'a: str = 10' > test.py
% npm install gulp-sass
% mypy .
node_modules/node-sass/node_modules/node-gyp/gyp/pylib/gyp/__init__.py:37: error: invalid syntax
Found 1 error in 1 file (errors prevented further checking)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
% mkdir test4
% cd test4
% echo 'a: str = 10' > test.py
% mkdir backup
% cp test.py backup/
% mypy .
test.py: error: Duplicate module named 'test' (also at './backup/test.py')
test.py: error: Are you missing an __init__.py?
Found 2 errors in 1 file (errors prevented further checking)

Your Environment

  • Mypy version used: 0.800
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9
  • Operating system and version: macOS 10.15

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