Documentation tools like sphinx
use docstrings attached to type hinted attributes. Sometimes it is desirable to repeat/extend the documentation of certain inherited attributes (but not document all inherited members).
I propose to allow respecifying Final
-attributes for documentation purposes if the type hint matches exactly the previously defined type hint on the parent class, since in this case we are not overriding, but simply repeating the statement.
from typing import Final
class Base:
input_size: Final[int]
hidden_size: Final[int]
def __init__(self, input_size: int, hidden_size: int) -> None:
self.input_size = input_size
self.hidden_size = hidden_size
class Custom(Base):
input_size: Final[int] # ❌ Cannot override final attribute
"""Documentation"""
hidden_size: Final[int] # ❌ Cannot override final attribute
"""Documentation"""
def __init__(self, input_size: int, hidden_size: int) -> None:
super().__init__(input_size, hidden_size)