Skip to content
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

typing: set no_implicit_reexport #7593

Merged
merged 1 commit into from
Aug 1, 2020

Conversation

bluetech
Copy link
Member

In Python, if module A defines a name name, and module B does import name from A, then another module C can import name from B.

Sometimes it is intentional -- module B is meant to "reexport" name.
But sometimes it is just confusion/inconsistency on where name should be imported from.

mypy has a flag --no-implicit-reexport which puts some order into this. A name can only be imported from a module if

  1. The module defines the name
  2. The module's __all__ includes the name
  3. The module imports the name as from ... import .. as name.

This flag is included in mypy's --strict flag.

I like this flag, but I realize it is a bit controversial, and in particular item 3 above is a bit unfriendly to contributors who don't
know about it. So I didn't intend to add it to pytest.

But while investigating issue #7589 I came upon mypy issue python/mypy#8754 which causes --no-implicit-reexport to leak into installed libraries and causes some unexpected typing differences in pytest if the user uses this flag.

Since the diff mostly makes sense, let's just conform to it.

In Python, if module A defines a name `name`, and module B does `import
name from A`, then another module C can `import name from B`.

Sometimes it is intentional -- module B is meant to "reexport" `name`.
But sometimes it is just confusion/inconsistency on where `name` should
be imported from.

mypy has a flag `--no-implicit-reexport` which puts some order into
this. A name can only be imported from a module if

1. The module defines the name
2. The module's `__all__` includes the name
3. The module imports the name as `from ... import .. as name`.

This flag is included in mypy's `--strict` flag.

I like this flag, but I realize it is a bit controversial, and in
particular item 3 above is a bit unfriendly to contributors who don't
know about it. So I didn't intend to add it to pytest.

But while investigating issue 7589 I came upon mypy issue 8754 which
causes `--no-implicit-reexport` to leak into installed libraries and
causes some unexpected typing differences *in pytest* if the user uses
this flag.

Since the diff mostly makes sense, let's just conform to it.
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

I definitely like this flag. 👍

@nicoddemus nicoddemus merged commit 6882c03 into pytest-dev:master Aug 1, 2020
@bluetech bluetech deleted the typing-no-implicit-reexport branch August 24, 2020 15:06
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.

None yet

3 participants