aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest/py3/_pytest/compat.py
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2025-05-05 12:31:52 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2025-05-05 12:41:33 +0300
commit6ff49ec58061f642c3a2f83c61eba12820787dfc (patch)
treec733ec9bdb15ed280080d31dea8725bfec717acd /contrib/python/pytest/py3/_pytest/compat.py
parenteefca8305c6a545cc6b16dca3eb0d91dcef2adcd (diff)
downloadydb-6ff49ec58061f642c3a2f83c61eba12820787dfc.tar.gz
Intermediate changes
commit_hash:8b3bb826b17db8329ed1221f545c0645f12c552d
Diffstat (limited to 'contrib/python/pytest/py3/_pytest/compat.py')
-rw-r--r--contrib/python/pytest/py3/_pytest/compat.py81
1 files changed, 7 insertions, 74 deletions
diff --git a/contrib/python/pytest/py3/_pytest/compat.py b/contrib/python/pytest/py3/_pytest/compat.py
index 6fdb5a1d8eb..83c598c816f 100644
--- a/contrib/python/pytest/py3/_pytest/compat.py
+++ b/contrib/python/pytest/py3/_pytest/compat.py
@@ -1,37 +1,24 @@
"""Python version compatibility code."""
+
from __future__ import annotations
import dataclasses
import enum
import functools
import inspect
-import os
-import sys
from inspect import Parameter
from inspect import signature
+import os
from pathlib import Path
+import sys
from typing import Any
from typing import Callable
-from typing import Generic
+from typing import Final
from typing import NoReturn
-from typing import TYPE_CHECKING
from typing import TypeVar
import _pytest._py.path as py_path
-# fmt: off
-# Workaround for https://github.com/sphinx-doc/sphinx/issues/10351.
-# If `overload` is imported from `compat` instead of from `typing`,
-# Sphinx doesn't recognize it as `overload` and the API docs for
-# overloaded functions look good again. But type checkers handle
-# it fine.
-# fmt: on
-if True:
- from typing import overload as overload
-
-if TYPE_CHECKING:
- from typing_extensions import Final
-
_T = TypeVar("_T")
_S = TypeVar("_S")
@@ -58,17 +45,6 @@ class NotSetType(enum.Enum):
NOTSET: Final = NotSetType.token # noqa: E305
# fmt: on
-if sys.version_info >= (3, 8):
- import importlib.metadata
-
- importlib_metadata = importlib.metadata
-else:
- import importlib_metadata as importlib_metadata # noqa: F401
-
-
-def _format_args(func: Callable[..., Any]) -> str:
- return str(signature(func))
-
def is_generator(func: object) -> bool:
genfunc = inspect.isgeneratorfunction(func)
@@ -93,7 +69,7 @@ def is_async_function(func: object) -> bool:
return iscoroutinefunction(func) or inspect.isasyncgenfunction(func)
-def getlocation(function, curdir: str | None = None) -> str:
+def getlocation(function, curdir: str | os.PathLike[str] | None = None) -> str:
function = get_real_func(function)
fn = Path(inspect.getfile(function))
lineno = function.__code__.co_firstlineno
@@ -127,7 +103,7 @@ def num_mock_patch_args(function) -> int:
def getfuncargnames(
- function: Callable[..., Any],
+ function: Callable[..., object],
*,
name: str = "",
is_method: bool = False,
@@ -283,9 +259,7 @@ def get_real_func(obj):
from _pytest._io.saferepr import saferepr
raise ValueError(
- ("could not find real function of {start}\nstopped at {current}").format(
- start=saferepr(start_obj), current=saferepr(obj)
- )
+ f"could not find real function of {saferepr(start_obj)}\nstopped at {saferepr(obj)}"
)
if isinstance(obj, functools.partial):
obj = obj.func
@@ -338,47 +312,6 @@ def safe_isclass(obj: object) -> bool:
return False
-if TYPE_CHECKING:
- if sys.version_info >= (3, 8):
- from typing import final as final
- else:
- from typing_extensions import final as final
-elif sys.version_info >= (3, 8):
- from typing import final as final
-else:
-
- def final(f):
- return f
-
-
-if sys.version_info >= (3, 8):
- from functools import cached_property as cached_property
-else:
-
- class cached_property(Generic[_S, _T]):
- __slots__ = ("func", "__doc__")
-
- def __init__(self, func: Callable[[_S], _T]) -> None:
- self.func = func
- self.__doc__ = func.__doc__
-
- @overload
- def __get__(
- self, instance: None, owner: type[_S] | None = ...
- ) -> cached_property[_S, _T]:
- ...
-
- @overload
- def __get__(self, instance: _S, owner: type[_S] | None = ...) -> _T:
- ...
-
- def __get__(self, instance, owner=None):
- if instance is None:
- return self
- value = instance.__dict__[self.func.__name__] = self.func(instance)
- return value
-
-
def get_user_id() -> int | None:
"""Return the current process's real user id or None if it could not be
determined.