summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2022-01-12 19:38:25 (GMT)
committerGitHub <noreply@github.com>2022-01-12 19:38:25 (GMT)
commit0bbf30e2b910bc9c5899134ae9d73a8df968da35 (patch)
treec1b8846dd8be0686cea098ea10ce2cf4c4abb2fd /Lib/typing.py
parente34c9367f8e0068ca4bcad9fb5c2c1024d02a77d (diff)
downloadcpython-0bbf30e2b910bc9c5899134ae9d73a8df968da35.zip
cpython-0bbf30e2b910bc9c5899134ae9d73a8df968da35.tar.gz
cpython-0bbf30e2b910bc9c5899134ae9d73a8df968da35.tar.bz2
bpo-46342: make @typing.final introspectable (GH-30530)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index d520f6b..972b8ba 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -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