Skip to content

Use TYPE_CHECKING instead of False #6435

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

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ exclude_lines =
\#\s*pragma: no cover
^\s*raise NotImplementedError\b
^\s*return NotImplemented\b

^\s*if TYPE_CHECKING:
3 changes: 2 additions & 1 deletion doc/en/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import sys

from _pytest import __version__ as version
from _pytest.compat import TYPE_CHECKING

if False: # TYPE_CHECKING
if TYPE_CHECKING:
import sphinx.application


Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
from _pytest._io.saferepr import safeformat
from _pytest._io.saferepr import saferepr
from _pytest.compat import overload
from _pytest.compat import TYPE_CHECKING

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

if False: # TYPE_CHECKING
if sys.version_info < (3, 5, 2):
TYPE_CHECKING = False # type: bool
else:
from typing import TYPE_CHECKING


if TYPE_CHECKING:
from typing import Type # noqa: F401 (used in type string)


Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
from _pytest._code import ExceptionInfo
from _pytest._code import filter_traceback
from _pytest.compat import importlib_metadata
from _pytest.compat import TYPE_CHECKING
from _pytest.outcomes import fail
from _pytest.outcomes import Skipped
from _pytest.pathlib import Path
from _pytest.warning_types import PytestConfigWarning

if False: # TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type


Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/config/findpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import py

from .exceptions import UsageError
from _pytest.compat import TYPE_CHECKING
from _pytest.outcomes import fail

if False:
if TYPE_CHECKING:
from . import Config # noqa: F401


Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
from _pytest._code.code import ReprFileLocation
from _pytest._code.code import TerminalRepr
from _pytest.compat import safe_getattr
from _pytest.compat import TYPE_CHECKING
from _pytest.fixtures import FixtureRequest
from _pytest.outcomes import Skipped
from _pytest.python_api import approx
from _pytest.warning_types import PytestWarning

if False: # TYPE_CHECKING
if TYPE_CHECKING:
import doctest
from typing import Type

Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
from _pytest.compat import is_generator
from _pytest.compat import NOTSET
from _pytest.compat import safe_getattr
from _pytest.compat import TYPE_CHECKING
from _pytest.deprecated import FIXTURE_POSITIONAL_ARGUMENTS
from _pytest.deprecated import FUNCARGNAMES
from _pytest.outcomes import fail
from _pytest.outcomes import TEST_OUTCOME

if False: # TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type

from _pytest import nodes
Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from _pytest._code.code import ReprExceptionInfo
from _pytest.compat import cached_property
from _pytest.compat import getfslineno
from _pytest.compat import TYPE_CHECKING
from _pytest.config import Config
from _pytest.fixtures import FixtureDef
from _pytest.fixtures import FixtureLookupError
Expand All @@ -26,7 +27,7 @@
from _pytest.mark.structures import NodeKeywords
from _pytest.outcomes import Failed

if False: # TYPE_CHECKING
if TYPE_CHECKING:
# Imported here due to circular import.
from _pytest.main import Session # noqa: F401

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

from packaging.version import Version

if False: # TYPE_CHECKING
TYPE_CHECKING = False # avoid circular import through compat

if TYPE_CHECKING:
from typing import NoReturn


Expand Down
5 changes: 3 additions & 2 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
from _pytest._io.saferepr import saferepr
from _pytest.capture import MultiCapture
from _pytest.capture import SysCapture
from _pytest.compat import TYPE_CHECKING
from _pytest.fixtures import FixtureRequest
from _pytest.main import ExitCode
from _pytest.main import Session
from _pytest.monkeypatch import MonkeyPatch
from _pytest.pathlib import Path
from _pytest.reports import TestReport

if False: # TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type


Expand Down Expand Up @@ -189,7 +190,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
3 changes: 2 additions & 1 deletion src/_pytest/python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import _pytest._code
from _pytest.compat import overload
from _pytest.compat import STRING_TYPES
from _pytest.compat import TYPE_CHECKING
from _pytest.outcomes import fail

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


Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/recwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
from typing import Union

from _pytest.compat import overload
from _pytest.compat import TYPE_CHECKING
from _pytest.fixtures import yield_fixture
from _pytest.outcomes import fail

if False: # TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type


Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
from .reports import CollectReport
from .reports import TestReport
from _pytest._code.code import ExceptionInfo
from _pytest.compat import TYPE_CHECKING
from _pytest.nodes import Node
from _pytest.outcomes import Exit
from _pytest.outcomes import Skipped
from _pytest.outcomes import TEST_OUTCOME

if False: # TYPE_CHECKING
if TYPE_CHECKING:
from typing import Type

#
Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/warning_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import attr

from _pytest.compat import TYPE_CHECKING

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


Expand Down