Skip to content
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

bpo-46342: make @typing.final introspectable #30530

Merged
merged 4 commits into from Jan 12, 2022

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Jan 11, 2022

"""
try:
f.__final__ = True
except (AttributeError, TypeError):
Copy link
Member Author

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.

@Fidget-Spinner
Copy link
Member

LGTM.
Side question: I'm curious as to which runtime type checkers use this information/What inspired you to make this change?

@JelleZijlstra
Copy link
Member Author

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.

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor nits

Doc/library/typing.rst Outdated Show resolved Hide resolved
JelleZijlstra and others added 2 commits January 11, 2022 06:06
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Copy link
Member

@gvanrossum gvanrossum left a comment

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.

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks Jelle.

@gvanrossum gvanrossum merged commit 0bbf30e into python:main Jan 12, 2022
@JelleZijlstra JelleZijlstra deleted the issue46342 branch January 12, 2022 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants