Skip to content

Commit 749752d

Browse files
authored
Merge pull request #6435 from blueyed/type_checking
Use TYPE_CHECKING instead of False
2 parents b91c721 + 4630e27 commit 749752d

15 files changed

+37
-15
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ exclude_lines =
2424
\#\s*pragma: no cover
2525
^\s*raise NotImplementedError\b
2626
^\s*return NotImplemented\b
27+
28+
^\s*if TYPE_CHECKING:

doc/en/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
import sys
2020

2121
from _pytest import __version__ as version
22+
from _pytest.compat import TYPE_CHECKING
2223

23-
if False: # TYPE_CHECKING
24+
if TYPE_CHECKING:
2425
import sphinx.application
2526

2627

src/_pytest/_code/code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
from _pytest._io.saferepr import safeformat
3333
from _pytest._io.saferepr import saferepr
3434
from _pytest.compat import overload
35+
from _pytest.compat import TYPE_CHECKING
3536

36-
if False: # TYPE_CHECKING
37+
if TYPE_CHECKING:
3738
from typing import Type
3839
from typing_extensions import Literal
3940
from weakref import ReferenceType # noqa: F401

src/_pytest/compat.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
from _pytest.outcomes import fail
2828
from _pytest.outcomes import TEST_OUTCOME
2929

30-
if False: # TYPE_CHECKING
30+
if sys.version_info < (3, 5, 2):
31+
TYPE_CHECKING = False # type: bool
32+
else:
33+
from typing import TYPE_CHECKING
34+
35+
36+
if TYPE_CHECKING:
3137
from typing import Type # noqa: F401 (used in type string)
3238

3339

src/_pytest/config/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737
from _pytest._code import ExceptionInfo
3838
from _pytest._code import filter_traceback
3939
from _pytest.compat import importlib_metadata
40+
from _pytest.compat import TYPE_CHECKING
4041
from _pytest.outcomes import fail
4142
from _pytest.outcomes import Skipped
4243
from _pytest.pathlib import Path
4344
from _pytest.warning_types import PytestConfigWarning
4445

45-
if False: # TYPE_CHECKING
46+
if TYPE_CHECKING:
4647
from typing import Type
4748

4849

src/_pytest/config/findpaths.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import py
66

77
from .exceptions import UsageError
8+
from _pytest.compat import TYPE_CHECKING
89
from _pytest.outcomes import fail
910

10-
if False:
11+
if TYPE_CHECKING:
1112
from . import Config # noqa: F401
1213

1314

src/_pytest/doctest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
from _pytest._code.code import ReprFileLocation
2020
from _pytest._code.code import TerminalRepr
2121
from _pytest.compat import safe_getattr
22+
from _pytest.compat import TYPE_CHECKING
2223
from _pytest.fixtures import FixtureRequest
2324
from _pytest.outcomes import Skipped
2425
from _pytest.python_api import approx
2526
from _pytest.warning_types import PytestWarning
2627

27-
if False: # TYPE_CHECKING
28+
if TYPE_CHECKING:
2829
import doctest
2930
from typing import Type
3031

src/_pytest/fixtures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727
from _pytest.compat import is_generator
2828
from _pytest.compat import NOTSET
2929
from _pytest.compat import safe_getattr
30+
from _pytest.compat import TYPE_CHECKING
3031
from _pytest.deprecated import FIXTURE_POSITIONAL_ARGUMENTS
3132
from _pytest.deprecated import FUNCARGNAMES
3233
from _pytest.outcomes import fail
3334
from _pytest.outcomes import TEST_OUTCOME
3435

35-
if False: # TYPE_CHECKING
36+
if TYPE_CHECKING:
3637
from typing import Type
3738

3839
from _pytest import nodes

src/_pytest/nodes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from _pytest._code.code import ReprExceptionInfo
1818
from _pytest.compat import cached_property
1919
from _pytest.compat import getfslineno
20+
from _pytest.compat import TYPE_CHECKING
2021
from _pytest.config import Config
2122
from _pytest.fixtures import FixtureDef
2223
from _pytest.fixtures import FixtureLookupError
@@ -26,7 +27,7 @@
2627
from _pytest.mark.structures import NodeKeywords
2728
from _pytest.outcomes import Failed
2829

29-
if False: # TYPE_CHECKING
30+
if TYPE_CHECKING:
3031
# Imported here due to circular import.
3132
from _pytest.main import Session # noqa: F401
3233

src/_pytest/outcomes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
from packaging.version import Version
1010

11-
if False: # TYPE_CHECKING
11+
TYPE_CHECKING = False # avoid circular import through compat
12+
13+
if TYPE_CHECKING:
1214
from typing import NoReturn
1315

1416

src/_pytest/pytester.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828
from _pytest._io.saferepr import saferepr
2929
from _pytest.capture import MultiCapture
3030
from _pytest.capture import SysCapture
31+
from _pytest.compat import TYPE_CHECKING
3132
from _pytest.fixtures import FixtureRequest
3233
from _pytest.main import ExitCode
3334
from _pytest.main import Session
3435
from _pytest.monkeypatch import MonkeyPatch
3536
from _pytest.pathlib import Path
3637
from _pytest.reports import TestReport
3738

38-
if False: # TYPE_CHECKING
39+
if TYPE_CHECKING:
3940
from typing import Type
4041

4142

@@ -189,7 +190,7 @@ def __repr__(self):
189190
del d["_name"]
190191
return "<ParsedCall {!r}(**{!r})>".format(self._name, d)
191192

192-
if False: # TYPE_CHECKING
193+
if TYPE_CHECKING:
193194
# The class has undetermined attributes, this tells mypy about it.
194195
def __getattr__(self, key):
195196
raise NotImplementedError()

src/_pytest/python_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
import _pytest._code
2424
from _pytest.compat import overload
2525
from _pytest.compat import STRING_TYPES
26+
from _pytest.compat import TYPE_CHECKING
2627
from _pytest.outcomes import fail
2728

28-
if False: # TYPE_CHECKING
29+
if TYPE_CHECKING:
2930
from typing import Type # noqa: F401 (used in type string)
3031

3132

src/_pytest/recwarn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
from typing import Union
1313

1414
from _pytest.compat import overload
15+
from _pytest.compat import TYPE_CHECKING
1516
from _pytest.fixtures import yield_fixture
1617
from _pytest.outcomes import fail
1718

18-
if False: # TYPE_CHECKING
19+
if TYPE_CHECKING:
1920
from typing import Type
2021

2122

src/_pytest/runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
from .reports import CollectReport
1616
from .reports import TestReport
1717
from _pytest._code.code import ExceptionInfo
18+
from _pytest.compat import TYPE_CHECKING
1819
from _pytest.nodes import Node
1920
from _pytest.outcomes import Exit
2021
from _pytest.outcomes import Skipped
2122
from _pytest.outcomes import TEST_OUTCOME
2223

23-
if False: # TYPE_CHECKING
24+
if TYPE_CHECKING:
2425
from typing import Type
2526

2627
#

src/_pytest/warning_types.py

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

55
import attr
66

7+
from _pytest.compat import TYPE_CHECKING
78

8-
if False: # TYPE_CHECKING
9+
if TYPE_CHECKING:
910
from typing import Type # noqa: F401 (used in type string)
1011

1112

0 commit comments

Comments
 (0)