Currently, @typing.final is implemented as an identity function, which makes it impossible for type checkers that look at runtime objects to support it.
I propose that we implement it as something like:
deffinal(f):
try:
f.__final__=TrueexceptAttributeError:
pass# in case it is used on an object that doesn't support setting attributesreturnf
Activity
JelleZijlstra commented on Jan 11, 2022
Currently, @typing.final is implemented as an identity function, which makes it impossible for type checkers that look at runtime objects to support it.
I propose that we implement it as something like:
I will submit a PR implementing this idea.
gvanrossum commented on Jan 12, 2022
New changeset 0bbf30e by Jelle Zijlstra in branch 'main':
bpo-46342: make @typing.final introspectable (GH-30530)
0bbf30e