diff options
author | Ran Benita <ran@unusedvar.com> | 2020-09-21 17:45:24 +0300 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2020-09-22 12:40:40 +0300 |
commit | a99ca879e7c9db0ac91324e701275e9439cf7b73 (patch) | |
tree | 99665f73dd072fea21855684787d3141366426d3 /src/_pytest/compat.py | |
parent | cdfdb3a25d1033f732072d9a4d2fb700feb73a09 (diff) | |
download | pytest-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.py | 16 |
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: |