Skip to content

Commit fc653d0

Browse files
authored
use if not TYPE_CHECKING on pytest.__getattr__ to prevent type checkers from using it
1 parent 37bb186 commit fc653d0

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/pytest/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# PYTHON_ARGCOMPLETE_OK
22
"""pytest: unit and functional testing with Python."""
3+
from typing import TYPE_CHECKING
4+
35
from _pytest import __version__
46
from _pytest import version_tuple
57
from _pytest._code import ExceptionInfo
@@ -165,11 +167,12 @@
165167
"yield_fixture",
166168
]
167169

170+
if not TYPE_CHECKING:
168171

169-
def __getattr__(name: str) -> object:
170-
if name == "Instance":
171-
# The import emits a deprecation warning.
172-
from _pytest.python import Instance
173-
174-
return Instance
175-
raise AttributeError(f"module {__name__} has no attribute {name}")
172+
def __getattr__(name: str) -> object:
173+
if name == "Instance":
174+
# The import emits a deprecation warning.
175+
from _pytest.python import Instance
176+
177+
return Instance
178+
raise AttributeError(f"module {__name__} has no attribute {name}")

0 commit comments

Comments
 (0)