Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a6ea89

Browse files
committed
Do not consider ‘import a.b as b’ an explicit reexport
The point of the ‘import a as a’ and ‘from a import b as b’ syntax for explicit reexport is that it indicates an intention to do something different from the ordinary ‘import a’ and ‘from a import b’. That is not the case with ‘import a.b as b’. Even mypy’s own code includes ‘import mypy.types as types’, which was not intended to be a reexport; if it were, it would be written ‘from mypy import types as types’. Pyright agrees that ‘import a.b as b’ should not reexport. Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 47a435f commit 8a6ea89

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2230,7 +2230,7 @@ def visit_import(self, i: Import) -> None:
22302230
if as_id is not None:
22312231
base_id = id
22322232
imported_id = as_id
2233-
module_public = use_implicit_reexport or id.split(".")[-1] == as_id
2233+
module_public = use_implicit_reexport or id == as_id
22342234
else:
22352235
base_id = id.split(".")[0]
22362236
imported_id = base_id

test-data/unit/check-modules.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,7 @@ m = n # E: Cannot assign multiple modules to name "m" without explicit "types.M
18091809
from stub import Iterable # E: Module "stub" does not explicitly export attribute "Iterable"
18101810
from stub import D # E: Module "stub" does not explicitly export attribute "D"
18111811
from stub import C
1812+
from stub import path # E: Module "stub" does not explicitly export attribute "path"
18121813

18131814
c = C()
18141815
reveal_type(c.x) # N: Revealed type is "builtins.int"
@@ -1819,6 +1820,7 @@ reveal_type(it) # N: Revealed type is "typing.Iterable[builtins.int]"
18191820
from typing import Iterable
18201821
from substub import C as C
18211822
from substub import C as D
1823+
import os.path as path
18221824

18231825
def fun(x: Iterable[str]) -> Iterable[int]: pass
18241826

0 commit comments

Comments
 (0)