You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some languages (e.g. java) it's possible to declare a class as final so that it can't be subclassed; similarly, it's possible to declare functions as final so that they can't be overridden by sublclasses. It would be great if mypy could support this - so that classes could be annotated as final or their functions as final.
The text was updated successfully, but these errors were encountered:
I recall this being proposed as a feature of ABC/ABCMeta as well. I guess the syntax would be pretty obvious: a @final decorator on a method or class.
But the way these things go it would have to be added to PEP 484 first, and that means a discussion in the https://github.com/python/typing/ tracker, and waiting until the release of Python 3.5.3.
We currently don't have a way to define mypy-only features that require new "syntax" like this, although it has occasionally been proposed and isn't technically difficult.
The quickest route to success however would be just to implement your own class decorator specific to your app that somehow sabotages subclassing. It would probably have to add a custom metaclass (or ride piggy-back on one you're already using) so that it can take over control of the class creation machinery. (If you need help with this I can try to construct a prototype and send it to you off-list.)
In some languages (e.g. java) it's possible to declare a class as
final
so that it can't be subclassed; similarly, it's possible to declare functions asfinal
so that they can't be overridden by sublclasses. It would be great if mypy could support this - so that classes could be annotated as final or their functions as final.The text was updated successfully, but these errors were encountered: