typing: set no_implicit_reexport

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.
This commit is contained in:
Ran Benita
2020-07-31 09:46:56 +03:00
parent 645cbc91fc
commit 8d98de8f8a
11 changed files with 39 additions and 28 deletions

View File

@@ -3,6 +3,7 @@ import textwrap
import pytest
from _pytest import fixtures
from _pytest.compat import getfuncargnames
from _pytest.config import ExitCode
from _pytest.fixtures import FixtureRequest
from _pytest.pathlib import Path
@@ -15,22 +16,22 @@ def test_getfuncargnames_functions():
def f():
raise NotImplementedError()
assert not fixtures.getfuncargnames(f)
assert not getfuncargnames(f)
def g(arg):
raise NotImplementedError()
assert fixtures.getfuncargnames(g) == ("arg",)
assert getfuncargnames(g) == ("arg",)
def h(arg1, arg2="hello"):
raise NotImplementedError()
assert fixtures.getfuncargnames(h) == ("arg1",)
assert getfuncargnames(h) == ("arg1",)
def j(arg1, arg2, arg3="hello"):
raise NotImplementedError()
assert fixtures.getfuncargnames(j) == ("arg1", "arg2")
assert getfuncargnames(j) == ("arg1", "arg2")
def test_getfuncargnames_methods():
@@ -40,7 +41,7 @@ def test_getfuncargnames_methods():
def f(self, arg1, arg2="hello"):
raise NotImplementedError()
assert fixtures.getfuncargnames(A().f) == ("arg1",)
assert getfuncargnames(A().f) == ("arg1",)
def test_getfuncargnames_staticmethod():
@@ -51,7 +52,7 @@ def test_getfuncargnames_staticmethod():
def static(arg1, arg2, x=1):
raise NotImplementedError()
assert fixtures.getfuncargnames(A.static, cls=A) == ("arg1", "arg2")
assert getfuncargnames(A.static, cls=A) == ("arg1", "arg2")
def test_getfuncargnames_partial():
@@ -64,7 +65,7 @@ def test_getfuncargnames_partial():
class T:
test_ok = functools.partial(check, i=2)
values = fixtures.getfuncargnames(T().test_ok, name="test_ok")
values = getfuncargnames(T().test_ok, name="test_ok")
assert values == ("arg1", "arg2")
@@ -78,7 +79,7 @@ def test_getfuncargnames_staticmethod_partial():
class T:
test_ok = staticmethod(functools.partial(check, i=2))
values = fixtures.getfuncargnames(T().test_ok, name="test_ok")
values = getfuncargnames(T().test_ok, name="test_ok")
assert values == ("arg1", "arg2")