bpo-46342: make @typing.final introspectable by JelleZijlstra · Pull Request #30530 · python/cpython

@JelleZijlstra

@JelleZijlstra

JelleZijlstra

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

@Fidget-Spinner

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

@JelleZijlstra

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.

Fidget-Spinner

Choose a reason for hiding this comment

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

Some minor nits

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>

Fidget-Spinner

gvanrossum

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.

@JelleZijlstra

Fidget-Spinner

Choose a reason for hiding this comment

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

LGTM. Thanks Jelle.

gvanrossum

AlexWaygood