bpo-46342: make @typing.final introspectable by JelleZijlstra · Pull Request #30530 · python/cpython
| """ | ||
| try: | ||
| f.__final__ = True | ||
| except (AttributeError, TypeError): |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be open to just doing just except Exception here, in case some type throws a different exception if you try to set an attribute. For precedent, note that @no_type_check catches only TypeError.
LGTM.
Side question: I'm curious as to which runtime type checkers use this information/What inspired you to make this change?
quora/pyanalyze#161. My type checker, pyanalyze, imports modules it typechecks and uses the runtime objects for checking. With this change, I can make it show an error if you inherit from something @final.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor nits
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea. I trust the current participants to come up with the right thing. Let me know when you all agree and you want me to merge it.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks Jelle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters