Skip to content

[feature request] final classes and member functions #2032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dgoldstein0 opened this issue Aug 17, 2016 · 3 comments
Closed

[feature request] final classes and member functions #2032

dgoldstein0 opened this issue Aug 17, 2016 · 3 comments

Comments

@dgoldstein0
Copy link

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.

@gvanrossum
Copy link
Member

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.)

@gvanrossum gvanrossum added this to the Undetermined priority milestone Aug 18, 2016
@gvanrossum
Copy link
Member

Closing, since this really needs to be brought up in the typing tracker. Sorry!

@dgoldstein0
Copy link
Author

python/typing#286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants