Open JelleZijlstra opened 3 years ago
This is impossible because the @final
decorator is a no-op at runtime: https://github.com/python/cpython/blob/main/Lib/typing.py#L2030. I'm thinking of proposing a change to CPython for 3.11 to make the decorator add .__final__ = True
to decorated functions or classes. Then we can backport that change to typing-extensions.
Classes annotated with
@final
should not allow subclasses, and methods decorated with@final
should not allow overrides.