summaryrefslogtreecommitdiff
path: root/src/_pytest/compat.py
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-09-21 17:45:24 +0300
committerRan Benita <ran@unusedvar.com>2020-09-22 12:40:40 +0300
commita99ca879e7c9db0ac91324e701275e9439cf7b73 (patch)
tree99665f73dd072fea21855684787d3141366426d3 /src/_pytest/compat.py
parentcdfdb3a25d1033f732072d9a4d2fb700feb73a09 (diff)
downloadpytest-a99ca879e7c9db0ac91324e701275e9439cf7b73.tar.gz
Mark some public and to-be-public classes as `@final`
This indicates at least for people using type checkers that these classes are not designed for inheritance and we make no stability guarantees regarding inheritance of them. Currently this doesn't show up in the docs. Sphinx does actually support `@final`, however it only works when imported directly from `typing`, while we import from `_pytest.compat`. In the future there might also be a `@sealed` decorator which would cover some more cases.
Diffstat (limited to 'src/_pytest/compat.py')
-rw-r--r--src/_pytest/compat.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py
index 0c9f47de7..7eab2ea0c 100644
--- a/src/_pytest/compat.py
+++ b/src/_pytest/compat.py
@@ -19,7 +19,6 @@ from typing import Union
import attr
-from _pytest._io.saferepr import saferepr
from _pytest.outcomes import fail
from _pytest.outcomes import TEST_OUTCOME
@@ -297,6 +296,8 @@ def get_real_func(obj):
break
obj = new_obj
else:
+ 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)
@@ -357,6 +358,19 @@ if sys.version_info < (3, 5, 2):
return f
+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): # noqa: F811
+ return f
+
+
if getattr(attr, "__version_info__", ()) >= (19, 2):
ATTRS_EQ_FIELD = "eq"
else: