bpo-46342: make @typing.final introspectable (GH-30530)

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
This commit is contained in:
Jelle Zijlstra 2022-01-12 11:38:25 -08:00 committed by GitHub
parent e34c9367f8
commit 0bbf30e2b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 93 additions and 1 deletions

View file

@ -2042,8 +2042,17 @@ def final(f):
class Other(Leaf): # Error reported by type checker
...
There is no runtime checking of these properties.
There is no runtime checking of these properties. The decorator
sets the ``__final__`` attribute to ``True`` on the decorated object
to allow runtime introspection.
"""
try:
f.__final__ = True
except (AttributeError, TypeError):
# Skip the attribute silently if it is not writable.
# AttributeError happens if the object has __slots__ or a
# read-only property, TypeError if it's a builtin class.
pass
return f