Skip to content

Commit 6882c03

Browse files
authored
Merge pull request #7593 from bluetech/typing-no-implicit-reexport
typing: set no_implicit_reexport
2 parents 07f7372 + 8d98de8 commit 6882c03

File tree

11 files changed

+39
-28
lines changed

11 files changed

+39
-28
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,4 @@ strict_equality = True
103103
warn_redundant_casts = True
104104
warn_return_any = True
105105
warn_unused_configs = True
106+
no_implicit_reexport = True

src/_pytest/_code/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from .code import filter_traceback
55
from .code import Frame
66
from .code import getfslineno
7-
from .code import getrawcode
87
from .code import Traceback
98
from .code import TracebackEntry
9+
from .source import getrawcode
1010
from .source import Source
1111

1212
__all__ = [

src/_pytest/compat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from typing import Callable
1515
from typing import Generic
1616
from typing import Optional
17-
from typing import overload
17+
from typing import overload as overload
1818
from typing import Tuple
1919
from typing import TypeVar
2020
from typing import Union
@@ -208,7 +208,7 @@ def nullcontext():
208208

209209

210210
else:
211-
from contextlib import nullcontext # noqa
211+
from contextlib import nullcontext as nullcontext # noqa: F401
212212

213213

214214
def get_default_arg_names(function: Callable[..., Any]) -> Tuple[str, ...]:
@@ -363,7 +363,7 @@ def overload(f): # noqa: F811
363363

364364

365365
if sys.version_info >= (3, 8):
366-
from functools import cached_property
366+
from functools import cached_property as cached_property
367367
else:
368368

369369
class cached_property(Generic[_S, _T]):

src/_pytest/config/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import _pytest._code
3636
import _pytest.deprecated
3737
import _pytest.hookspec # the extension point definitions
38-
from .exceptions import PrintHelp
39-
from .exceptions import UsageError
38+
from .exceptions import PrintHelp as PrintHelp
39+
from .exceptions import UsageError as UsageError
4040
from .findpaths import determine_setup
4141
from _pytest._code import ExceptionInfo
4242
from _pytest._code import filter_traceback

src/_pytest/mark/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
from _pytest.nodes import Item
2929

3030

31-
__all__ = ["Mark", "MarkDecorator", "MarkGenerator", "get_empty_parameterset_mark"]
31+
__all__ = [
32+
"MARK_GEN",
33+
"Mark",
34+
"MarkDecorator",
35+
"MarkGenerator",
36+
"ParameterSet",
37+
"get_empty_parameterset_mark",
38+
]
3239

3340

3441
old_mark_config_key = StoreKey[Optional[Config]]()

src/_pytest/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from _pytest._code import filter_traceback
3333
from _pytest._code import getfslineno
3434
from _pytest._code.code import ExceptionInfo
35+
from _pytest._code.code import TerminalRepr
3536
from _pytest._io import TerminalWriter
3637
from _pytest._io.saferepr import saferepr
3738
from _pytest.compat import ascii_escaped
@@ -66,7 +67,6 @@
6667
from _pytest.pathlib import ImportPathMismatchError
6768
from _pytest.pathlib import parts
6869
from _pytest.pathlib import visit
69-
from _pytest.reports import TerminalRepr
7070
from _pytest.warning_types import PytestCollectionWarning
7171
from _pytest.warning_types import PytestUnhandledCoroutineWarning
7272

@@ -581,7 +581,7 @@ def _importtestmodule(self):
581581
"Traceback:\n"
582582
"{traceback}".format(fspath=self.fspath, traceback=formatted_tb)
583583
) from e
584-
except _pytest.runner.Skipped as e:
584+
except skip.Exception as e:
585585
if e.allow_module_level:
586586
raise
587587
raise self.CollectError(

testing/python/collect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ def test_filter_traceback_generated_code(self) -> None:
10181018
See: https://bitbucket.org/pytest-dev/py/issues/71
10191019
This fixes #995.
10201020
"""
1021-
from _pytest.python import filter_traceback
1021+
from _pytest._code import filter_traceback
10221022

10231023
try:
10241024
ns = {} # type: Dict[str, Any]
@@ -1038,7 +1038,7 @@ def test_filter_traceback_path_no_longer_valid(self, testdir) -> None:
10381038
In this case, one of the files in the traceback no longer exists.
10391039
This fixes #1133.
10401040
"""
1041-
from _pytest.python import filter_traceback
1041+
from _pytest._code import filter_traceback
10421042

10431043
testdir.syspathinsert()
10441044
testdir.makepyfile(

testing/python/fixtures.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55
from _pytest import fixtures
6+
from _pytest.compat import getfuncargnames
67
from _pytest.config import ExitCode
78
from _pytest.fixtures import FixtureRequest
89
from _pytest.pathlib import Path
@@ -15,22 +16,22 @@ def test_getfuncargnames_functions():
1516
def f():
1617
raise NotImplementedError()
1718

18-
assert not fixtures.getfuncargnames(f)
19+
assert not getfuncargnames(f)
1920

2021
def g(arg):
2122
raise NotImplementedError()
2223

23-
assert fixtures.getfuncargnames(g) == ("arg",)
24+
assert getfuncargnames(g) == ("arg",)
2425

2526
def h(arg1, arg2="hello"):
2627
raise NotImplementedError()
2728

28-
assert fixtures.getfuncargnames(h) == ("arg1",)
29+
assert getfuncargnames(h) == ("arg1",)
2930

3031
def j(arg1, arg2, arg3="hello"):
3132
raise NotImplementedError()
3233

33-
assert fixtures.getfuncargnames(j) == ("arg1", "arg2")
34+
assert getfuncargnames(j) == ("arg1", "arg2")
3435

3536

3637
def test_getfuncargnames_methods():
@@ -40,7 +41,7 @@ class A:
4041
def f(self, arg1, arg2="hello"):
4142
raise NotImplementedError()
4243

43-
assert fixtures.getfuncargnames(A().f) == ("arg1",)
44+
assert getfuncargnames(A().f) == ("arg1",)
4445

4546

4647
def test_getfuncargnames_staticmethod():
@@ -51,7 +52,7 @@ class A:
5152
def static(arg1, arg2, x=1):
5253
raise NotImplementedError()
5354

54-
assert fixtures.getfuncargnames(A.static, cls=A) == ("arg1", "arg2")
55+
assert getfuncargnames(A.static, cls=A) == ("arg1", "arg2")
5556

5657

5758
def test_getfuncargnames_partial():
@@ -64,7 +65,7 @@ def check(arg1, arg2, i):
6465
class T:
6566
test_ok = functools.partial(check, i=2)
6667

67-
values = fixtures.getfuncargnames(T().test_ok, name="test_ok")
68+
values = getfuncargnames(T().test_ok, name="test_ok")
6869
assert values == ("arg1", "arg2")
6970

7071

@@ -78,7 +79,7 @@ def check(arg1, arg2, i):
7879
class T:
7980
test_ok = staticmethod(functools.partial(check, i=2))
8081

81-
values = fixtures.getfuncargnames(T().test_ok, name="test_ok")
82+
values = getfuncargnames(T().test_ok, name="test_ok")
8283
assert values == ("arg1", "arg2")
8384

8485

testing/python/integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Any
22

33
import pytest
4-
from _pytest import python
54
from _pytest import runner
5+
from _pytest._code import getfslineno
66

77

88
class TestOEJSKITSpecials:
@@ -87,8 +87,8 @@ def wrap(f):
8787
def wrapped_func(x, y, z):
8888
pass
8989

90-
fs, lineno = python.getfslineno(wrapped_func)
91-
fs2, lineno2 = python.getfslineno(wrap)
90+
fs, lineno = getfslineno(wrapped_func)
91+
fs2, lineno2 = getfslineno(wrap)
9292
assert lineno > lineno2, "getfslineno does not unwrap correctly"
9393

9494

testing/python/metafunc.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import pytest
2020
from _pytest import fixtures
2121
from _pytest import python
22+
from _pytest.compat import _format_args
23+
from _pytest.compat import getfuncargnames
2224
from _pytest.outcomes import fail
2325
from _pytest.pytester import Testdir
2426
from _pytest.python import _idval
@@ -41,7 +43,7 @@ class DefinitionMock(python.FunctionDefinition):
4143
obj = attr.ib()
4244
_nodeid = attr.ib()
4345

44-
names = fixtures.getfuncargnames(func)
46+
names = getfuncargnames(func)
4547
fixtureinfo = FuncFixtureInfoMock(names) # type: Any
4648
definition = DefinitionMock._create(func, "mock::nodeid") # type: Any
4749
return python.Metafunc(definition, fixtureinfo, config)
@@ -954,22 +956,22 @@ def test_format_args(self) -> None:
954956
def function1():
955957
pass
956958

957-
assert fixtures._format_args(function1) == "()"
959+
assert _format_args(function1) == "()"
958960

959961
def function2(arg1):
960962
pass
961963

962-
assert fixtures._format_args(function2) == "(arg1)"
964+
assert _format_args(function2) == "(arg1)"
963965

964966
def function3(arg1, arg2="qwe"):
965967
pass
966968

967-
assert fixtures._format_args(function3) == "(arg1, arg2='qwe')"
969+
assert _format_args(function3) == "(arg1, arg2='qwe')"
968970

969971
def function4(arg1, *args, **kwargs):
970972
pass
971973

972-
assert fixtures._format_args(function4) == "(arg1, *args, **kwargs)"
974+
assert _format_args(function4) == "(arg1, *args, **kwargs)"
973975

974976

975977
class TestMetafuncFunctional:

testing/test_mark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import pytest
66
from _pytest.config import ExitCode
7-
from _pytest.mark import EMPTY_PARAMETERSET_OPTION
87
from _pytest.mark import MarkGenerator as Mark
8+
from _pytest.mark.structures import EMPTY_PARAMETERSET_OPTION
99
from _pytest.nodes import Collector
1010
from _pytest.nodes import Node
1111

0 commit comments

Comments
 (0)