-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Do not consider import a.b as b
an explicit reexport
#14086
Conversation
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 <andersk@mit.edu>
8a6ea89
to
c444466
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the change itself looks great. However, I'm hoping that we can fix #13965 before merging, to reduce the impact on downstream users
This comment has been minimized.
This comment has been minimized.
#16129 should unblock this |
Diff from mypy_primer, showing the effect of this PR on open source code: pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/hookspec.py:267: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/hookspec.py:267: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/hookspec.py:288: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/hookspec.py:288: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/hookspec.py:360: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/hookspec.py:360: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/hookspec.py:747: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/hookspec.py:747: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/hookspec.py:778: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/hookspec.py:778: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/compat.py:30: error: Module "py" does not explicitly export attribute "path" [attr-defined]
+ src/_pytest/compat.py:34: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/compat.py:34: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/compat.py:36: error: Returning Any from function declared to return LEGACY_PATH? [no-any-return]
+ src/_pytest/nodes.py:97: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/nodes.py:97: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/nodes.py:108: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/nodes.py:108: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/nodes.py:111: error: Statement is unreachable [unreachable]
+ src/_pytest/nodes.py:119: error: Statement is unreachable [unreachable]
+ src/_pytest/nodes.py:123: error: Statement is unreachable [unreachable]
+ src/_pytest/nodes.py:172: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/nodes.py:172: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/nodes.py:193: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/nodes.py:193: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/nodes.py:587: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/nodes.py:587: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/nodes.py:644: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/nodes.py:644: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/config/compat.py:47: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/config/compat.py:47: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/config/compat.py:49: error: Statement is unreachable [unreachable]
+ src/_pytest/config/compat.py:57: error: Statement is unreachable [unreachable]
+ src/_pytest/config/compat.py:62: error: Statement is unreachable [unreachable]
+ src/_pytest/python.py:667: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/python.py:667: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:58: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:58: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:63: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:63: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:94: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:94: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:106: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:106: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:110: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:110: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:118: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:118: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:122: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:122: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:126: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:126: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:134: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:134: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:138: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:138: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:142: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:142: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:290: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:290: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:294: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:294: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:309: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:309: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:331: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:331: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:339: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:339: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:344: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:344: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:354: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:354: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:365: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:365: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:375: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:375: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:385: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:385: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:408: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:408: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ src/_pytest/legacypath.py:413: error: Variable "_pytest.compat.LEGACY_PATH" is not valid as a type [valid-type]
+ src/_pytest/legacypath.py:413: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ testing/test_legacypath.py:18: error: Unsupported left operand type for == (LEGACY_PATH?) [operator]
+ testing/test_legacypath.py:24: error: LEGACY_PATH? has no attribute "check" [attr-defined]
+ testing/test_legacypath.py:62: error: LEGACY_PATH? has no attribute "exists" [attr-defined]
+ testing/_py/test_local.py:10: error: Module "py" does not explicitly export attribute "error" [attr-defined]
|
I guess I was wrong that #16129 would fix, but glad this got me to make that PR. Looks like it would take a larger change to how we handle ModuleType, so I will call it good and merge this. |
The point of the
import a as a
andfrom a import b as b
syntax for explicit reexport is that it indicates an intention to do something different from the ordinaryimport a
andfrom a import b
.That is not the case with
import a.b as b
. Even mypy’s own code includesimport mypy.types as types
, which was not intended to be a reexport; if it were, it would be writtenfrom mypy import types as types
.Pyright agrees that
import a.b as b
should not reexport.