Python · maintainability
duplicated-override-docstring
python:duplicated-override-docstring Remove an override docstring copied verbatim from its local base method.
- Code
- SARJ084
- Default
- error
- Fix
- none
- Languages
- python
Why
Inherited documentation is already discoverable, while a duplicate adds a second copy that can drift.
Fix
Delete the copied docstring, or rewrite it only when the override has behavior-specific information to add.
Before / after
Executed by this rule’s unit tests.
Before
Override repeats its base method documentation
class Store:
def get(self, key: str) -> str:
"""Get a value by key."""
return key
class MemoryStore(Store):
def get(self, key: str) -> str:
"""Get a value by key."""
return key
After
Override documents its distinct behavior
class Store:
def get(self, key: str) -> str:
"""Get a value by key."""
return key
class ReplicaStore(Store):
def get(self, key: str) -> str:
"""Get a value from the read replica."""
return key
Limits
- Only methods whose base class is defined under an undotted name in the same file are compared.
- Overloads, generated files, undocumented bases, and methods whose docstring is their entire body are excluded.