use `if not TYPE_CHECKING` on `pytest.__getattr__` to prevent type checkers from using it

This commit is contained in:
DetachHead 2023-08-21 18:00:28 +10:00 committed by GitHub
parent 37bb186175
commit fc653d0d12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 7 deletions

View File

@ -1,5 +1,7 @@
# PYTHON_ARGCOMPLETE_OK
"""pytest: unit and functional testing with Python."""
from typing import TYPE_CHECKING
from _pytest import __version__
from _pytest import version_tuple
from _pytest._code import ExceptionInfo
@ -165,11 +167,12 @@ __all__ = [
"yield_fixture",
]
if not TYPE_CHECKING:
def __getattr__(name: str) -> object:
if name == "Instance":
# The import emits a deprecation warning.
from _pytest.python import Instance
return Instance
raise AttributeError(f"module {__name__} has no attribute {name}")
def __getattr__(name: str) -> object:
if name == "Instance":
# The import emits a deprecation warning.
from _pytest.python import Instance
return Instance
raise AttributeError(f"module {__name__} has no attribute {name}")