Overloading an abstract attribute with a Final one
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
In the following code it would be useful to mark toto as final to make sure no code modifies it by error. However this triggers Cannot override writable attribute "toto" with a final one
from typing import Final
class Base:
toto: str = NotImplemented
def access_toto(self) -> str:
return self.toto
class CmdA(Base):
toto: Final[str] = "toto"
In fact I tend to agree with that error, in that what I'd really like to do is to annotate toto as "abstract final", which is not possible either as the use of toto: Final[str] triggers Final name must be initialized with a value, and toto: Final[str] = NotImplemented still gets the
Cannot override final attribute "toto" (previously declared in base class "Base") the previous attempt also showed.
- Mypy version used: 1.1.1, 0.812
- Python version used: 3.9.2
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
Start by reproducing the supplied example with mypy 1.1.1 and 0.812, then compare the diagnostics for Final attributes and inheritance. No files or tests are named in the report; done requires an agreed interpretation of abstract-final attributes and corresponding behavior or diagnostics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100