KEMBAR78
Docs: show how `--no-implicit-reexport` handles `from X import Y as Z` by SyntaxColoring · Pull Request #11083 · python/mypy · GitHub
Skip to content

Conversation

SyntaxColoring
Copy link
Contributor

@SyntaxColoring SyntaxColoring commented Sep 9, 2021

Description

In our testing, mypy appears to treat code like this as an implicit re-export. If --no-implicit-reexport is given, mypy will disallow it.

from X import Y as Z  # Non-matching name.

Even though it treats code like this as an explicit re-export:

from X import Y as Y  # Matching name.

For stub files specifically, PEP 484 has this note, emphasis mine:

Modules and variables imported into the stub are not considered exported from the stub unless the import uses the import ... as ... form or the equivalent from ... import ... as ... form. (UPDATE: To clarify, the intention here is that only names imported using the form X as X will be exported, i.e. the name before and after as must be the same.)

I am therefore assuming that this mypy behavior is intentional. (Even though I find it unfortunate and surprising, and even though --no-implicit-reexport seems meant for more than just stub files.) So this PR documents it.

Test Plan

  • Verify that the rendered docs look good: Screen Shot 2021-09-09 at 2 42 41 PM
  • If anyone can authoritatively confirm that this is indeed intended behavior of --no-implicit-reexport, that would be helpful.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks, looks good. I can authoritatively confirm this is intentional behaviour. Some related discussion here: https://mail.python.org/archives/list/typing-sig@python.org/thread/YLJPWECBNPD2K4TRIBRIPISNUZJCRREY/#FPTLFORIBPKY36UO7PLO47HJDCLG2KD5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants