quora / pyanalyze

A Python type checker
Apache License 2.0
334 stars 35 forks source link

Support @final (PEP 591) #161

Open JelleZijlstra opened 3 years ago

JelleZijlstra commented 3 years ago

Classes annotated with @final should not allow subclasses, and methods decorated with @final should not allow overrides.

JelleZijlstra commented 2 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.