Skip to content

Commit

Permalink
Recognize -stubs directories as valid package directories (#9445)
Browse files Browse the repository at this point in the history
Fixes #8229
  • Loading branch information
bryanforbes committed Sep 16, 2020
1 parent 4325aae commit b707d29
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mypy/find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def crawl_up_dir(self, dir: str) -> Tuple[str, str]:
base_dir = dir or '.'
else:
# Ensure that base is a valid python module name
if base.endswith('-stubs'):
base = base[:-6] # PEP-561 stub-only directory
if not base.isidentifier():
raise InvalidSourceList('{} is not a valid Python package name'.format(base))
parent, base_dir = self.crawl_up_dir(parent_dir)
Expand Down
36 changes: 36 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -1176,3 +1176,39 @@ usage: mypy [-h] [-v] [-V] [more options; see below]
[-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
mypy: error: Invalid error code(s): YOLO
== Return code: 2

[case testStubsDirectory]
# cmd: mypy --error-summary pkg-stubs
[file pkg-stubs/__init__.pyi]
[file pkg-stubs/thing.pyi]
class Thing: ...
[out]
Success: no issues found in 2 source files
== Return code: 0

[case testStubsDirectoryFile]
# cmd: mypy --error-summary pkg-stubs/thing.pyi
[file pkg-stubs/__init__.pyi]
[file pkg-stubs/thing.pyi]
class Thing: ...
[out]
Success: no issues found in 1 source file
== Return code: 0

[case testStubsSubDirectory]
# cmd: mypy --error-summary src/pkg-stubs
[file src/pkg-stubs/__init__.pyi]
[file src/pkg-stubs/thing.pyi]
class Thing: ...
[out]
Success: no issues found in 2 source files
== Return code: 0

[case testStubsSubDirectoryFile]
# cmd: mypy --error-summary src/pkg-stubs/thing.pyi
[file src/pkg-stubs/__init__.pyi]
[file src/pkg-stubs/thing.pyi]
class Thing: ...
[out]
Success: no issues found in 1 source file
== Return code: 0

0 comments on commit b707d29

Please sign in to comment.