Do not consider import a.b as b an explicit reexport#14086
Merged
hauntsaninja merged 3 commits intopython:masterfrom Sep 20, 2023
Merged
Do not consider import a.b as b an explicit reexport#14086hauntsaninja merged 3 commits intopython:masterfrom
import a.b as b an explicit reexport#14086hauntsaninja merged 3 commits intopython:masterfrom
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.
hauntsaninja
approved these changes
Jan 10, 2023
Collaborator
hauntsaninja
left a comment
There was a problem hiding this comment.
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.
Collaborator
|
#16129 should unblock this |
Contributor
|
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]
|
Collaborator
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The point of the
import a as aandfrom a import b as bsyntax for explicit reexport is that it indicates an intention to do something different from the ordinaryimport aandfrom 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 bshould not reexport.