Skip to content

Commit

Permalink
Use TYPE_CHECKING instead of False
Browse files Browse the repository at this point in the history
This allows for e.g. Jedi to infer types.

It was only used to support Python 3.5.0/3.5.1, where this is available
in `typing_extensions`.

Ref: davidhalter/jedi#1472
  • Loading branch information
blueyed committed Jan 10, 2020
1 parent 2d488f7 commit 66d42ef
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 15 deletions.
6 changes: 5 additions & 1 deletion doc/en/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

from _pytest import __version__ as version

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
import sphinx.application


Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
from _pytest._io.saferepr import saferepr
from _pytest.compat import overload

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type
from typing_extensions import Literal
from weakref import ReferenceType # noqa: F401
Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
from _pytest.outcomes import fail
from _pytest.outcomes import TEST_OUTCOME

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type # noqa: F401 (used in type string)


Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
from _pytest.pathlib import Path
from _pytest.warning_types import PytestConfigWarning

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type

from .argparsing import Argument
Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/config/argparsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

from _pytest.config.exceptions import UsageError

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from typing import NoReturn
from typing_extensions import Literal # noqa: F401

Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
from _pytest.python_api import approx
from _pytest.warning_types import PytestWarning

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
import doctest
from typing import Type

Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
from _pytest.outcomes import fail
from _pytest.outcomes import TEST_OUTCOME

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type

from _pytest import nodes
Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
from _pytest.mark.structures import NodeKeywords
from _pytest.outcomes import Failed

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
# Imported here due to circular import.
from _pytest.main import Session # noqa: F401

Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

from packaging.version import Version

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from typing import NoReturn


Expand Down
8 changes: 6 additions & 2 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
from _pytest.pathlib import Path
from _pytest.reports import TestReport

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type


Expand Down Expand Up @@ -189,7 +193,7 @@ def __repr__(self):
del d["_name"]
return "<ParsedCall {!r}(**{!r})>".format(self._name, d)

if False: # TYPE_CHECKING
if TYPE_CHECKING:
# The class has undetermined attributes, this tells mypy about it.
def __getattr__(self, key):
raise NotImplementedError()
Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
from _pytest.compat import STRING_TYPES
from _pytest.outcomes import fail

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type # noqa: F401 (used in type string)


Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/recwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
from _pytest.fixtures import yield_fixture
from _pytest.outcomes import fail

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type


Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
from _pytest.outcomes import Skipped
from _pytest.outcomes import TEST_OUTCOME

if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type

#
Expand Down
6 changes: 5 additions & 1 deletion src/_pytest/warning_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import attr


if False: # TYPE_CHECKING
try:
from typing import TYPE_CHECKING
except ImportError:
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type # noqa: F401 (used in type string)


Expand Down

0 comments on commit 66d42ef

Please sign in to comment.