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.
This commit is contained in:
Ran Benita
2020-09-21 17:45:24 +03:00
parent cdfdb3a25d
commit a99ca879e7
23 changed files with 81 additions and 1 deletions
+3
View File
@@ -26,6 +26,7 @@ from _pytest._code.code import ReprLocals
from _pytest._code.code import ReprTraceback
from _pytest._code.code import TerminalRepr
from _pytest._io import TerminalWriter
from _pytest.compat import final
from _pytest.compat import TYPE_CHECKING
from _pytest.config import Config
from _pytest.nodes import Collector
@@ -225,6 +226,7 @@ def _report_unserialization_failure(
raise RuntimeError(stream.getvalue())
@final
class TestReport(BaseReport):
"""Basic test report object (also used for setup and teardown calls if
they fail)."""
@@ -333,6 +335,7 @@ class TestReport(BaseReport):
)
@final
class CollectReport(BaseReport):
"""Collection report object."""