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

Make --namespace-packages the default #9636

Merged
merged 17 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1325,8 +1325,10 @@ def validate_meta(meta: Optional[CacheMeta], id: str, path: Optional[str],
st = manager.get_stat(path)
except OSError:
return None
if not (stat.S_ISREG(st.st_mode) or stat.S_ISDIR(st.st_mode)):
manager.log('Metadata abandoned for {}: file {} does not exist'.format(id, path))
if not stat.S_ISDIR(st.st_mode) and not stat.S_ISREG(st.st_mode):
manager.log(
'Metadata abandoned for {}: file or directory {} does not exist'.format(id, path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems unrelated? Useful - but not related.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was a change here that was needed, but then got merged in another PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I think remove this from this commit/PR before landing.
Better to keep the diff scoped to what's necessary.

)
return None

manager.add_stats(validate_stat_time=time.time() - t0)
Expand Down
2 changes: 1 addition & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def add_invertible_flag(flag: str,
title='Import discovery',
description="Configure how imports are discovered and followed.")
add_invertible_flag(
'--namespace-packages', default=False,
'--no-namespace-packages', dest="namespace_packages", default=True,
help="Support namespace packages (PEP 420, __init__.py-less)",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated!

group=imports_group)
imports_group.add_argument(
Expand Down
2 changes: 1 addition & 1 deletion mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self) -> None:
# This allows definitions of packages without __init__.py and allows packages to span
# multiple directories. This flag affects both import discovery and the association of
# input files/modules/packages to the relevant file and fully qualified module name.
self.namespace_packages = False
self.namespace_packages = True
# Use current directory and MYPYPATH to determine fully qualified module names of files
# passed by automatically considering their subdirectories as packages. This is only
# relevant if namespace packages are enabled, since otherwise examining __init__.py's is
Expand Down
5 changes: 3 additions & 2 deletions test-data/unit/check-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -2655,12 +2655,13 @@ from foo.bar import x
x = 0

[case testClassicNotPackage]
# flags: --no-namespace-packages
from foo.bar import x
[file foo/bar.py]
x = 0
[out]
main:1: error: Cannot find implementation or library stub for module named "foo.bar"
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
main:2: error: Cannot find implementation or library stub for module named "foo.bar"
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

[case testNamespacePackage]
# flags: --namespace-packages
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/fine-grained-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str"
==
main:1: error: Cannot find implementation or library stub for module named "p.a"
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
main:1: error: Cannot find implementation or library stub for module named "p"
main:2: error: "object" has no attribute "a"

[case testDeletePackage2]
import p
Expand Down
7 changes: 4 additions & 3 deletions test-data/unit/semanal-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,16 @@ x = y
tmp/k.py:2: error: Name "y" is not defined

[case testPackageWithoutInitFile]
# flags: --no-namespace-packages
import typing
import m.n
m.n.x
[file m/n.py]
x = 1
[out]
main:2: error: Cannot find implementation or library stub for module named "m.n"
main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
main:2: error: Cannot find implementation or library stub for module named "m"
main:3: error: Cannot find implementation or library stub for module named "m.n"
main:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
main:3: error: Cannot find implementation or library stub for module named "m"

[case testBreakOutsideLoop]
break
Expand Down