Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize -stubs directories as valid package directories #9445

Merged
merged 2 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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