Skip to content

Commit 63a93f1

Browse files
author
hauntsaninja
committed
Make --namespace-packages the default
Unfortunately, a number of tests fail. Please help fixing them :-) Especially the ones to do with cache inconsistencies... There's at least one known bug here: #7276
1 parent a0542c1 commit 63a93f1

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

mypy/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def add_invertible_flag(flag: str,
444444
title='Import discovery',
445445
description="Configure how imports are discovered and followed.")
446446
add_invertible_flag(
447-
'--namespace-packages', default=False,
447+
'--no-namespace-packages', dest="namespace_packages", default=True,
448448
help="Support namespace packages (PEP 420, __init__.py-less)",
449449
group=imports_group)
450450
imports_group.add_argument(

mypy/options.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(self) -> None:
8787
# Intended to be used for disabling specific stubs.
8888
self.follow_imports_for_stubs = False
8989
# PEP 420 namespace packages
90-
self.namespace_packages = False
90+
self.namespace_packages = True
9191

9292
# disallow_any options
9393
self.disallow_any_generics = False

test-data/unit/check-modules.test

+3-2
Original file line numberDiff line numberDiff line change
@@ -2617,12 +2617,13 @@ from foo.bar import x
26172617
x = 0
26182618

26192619
[case testClassicNotPackage]
2620+
# flags: --no-namespace-packages
26202621
from foo.bar import x
26212622
[file foo/bar.py]
26222623
x = 0
26232624
[out]
2624-
main:1: error: Cannot find implementation or library stub for module named 'foo.bar'
2625-
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
2625+
main:2: error: Cannot find implementation or library stub for module named 'foo.bar'
2626+
main:2: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
26262627

26272628
[case testNamespacePackage]
26282629
# flags: --namespace-packages

test-data/unit/fine-grained-modules.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str"
845845
==
846846
main:1: error: Cannot find implementation or library stub for module named 'p.a'
847847
main:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
848-
main:1: error: Cannot find implementation or library stub for module named 'p'
848+
main:2: error: "object" has no attribute "a"
849849

850850
[case testDeletePackage2]
851851
import p

test-data/unit/semanal-errors.test

+4-3
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,16 @@ x = y
316316
tmp/k.py:2: error: Name 'y' is not defined
317317

318318
[case testPackageWithoutInitFile]
319+
# flags: --no-namespace-packages
319320
import typing
320321
import m.n
321322
m.n.x
322323
[file m/n.py]
323324
x = 1
324325
[out]
325-
main:2: error: Cannot find implementation or library stub for module named 'm.n'
326-
main:2: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
327-
main:2: error: Cannot find implementation or library stub for module named 'm'
326+
main:3: error: Cannot find implementation or library stub for module named 'm.n'
327+
main:3: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
328+
main:3: error: Cannot find implementation or library stub for module named 'm'
328329

329330
[case testBreakOutsideLoop]
330331
break

0 commit comments

Comments
 (0)