pytest-dev / pytest-dev/pytest
Add a runtime check for exported classes which should not be subclassed
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
From @bluetech: we expose some classes in our API which are not meant for subclassing. We indicate this with @final annotations but these are only effective when type-checking. The following is a suggestion how to add a runtime check.
it's quite clean to add a runtime deprecation warning, so might be worth doing in this PR:
def __init_subclass__(cls, **kwargs):
warnings.warn(f"subclassing {cls} is deprecated", PytestDeprecationWarning)
def runtime_final(cls: T) -> T:
cls.__init_subclass__ = __init_subclass__ # type: ignore
return cls
...
@final
@runtime_final
class Ham:
pass
Originally posted by @graingert in https://github.com/pytest-dev/pytest/pull/8017#discussion_r520805087
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no implementation file or test; begin by reviewing the exported @final classes and the referenced pytest-dev/pytest#8017 discussion. Done means a runtime check is defined for subclassing classes intended not to be subclassed, with tests covering the resulting behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100