summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-10-07 19:56:16 (GMT)
committerGitHub <noreply@github.com>2022-10-07 19:56:16 (GMT)
commit107ba927cf60d26c1f6302a8c953de5ed136dd35 (patch)
treef5a4f41c41738db0b31684b6e966331572c73a99 /Lib/inspect.py
parenta421c87b54facbbc223c7539172a5871e1a75edb (diff)
downloadcpython-107ba927cf60d26c1f6302a8c953de5ed136dd35.zip
cpython-107ba927cf60d26c1f6302a8c953de5ed136dd35.tar.gz
cpython-107ba927cf60d26c1f6302a8c953de5ed136dd35.tar.bz2
GH-96073: Fix wild replacement in inspect.formatannotation (GH-96074)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit d5fea01d9d439b1638cd8e5db19c33909841d86f) Co-authored-by: Anh71me <iyumelive@gmail.com>
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index cbc0632..5f7574c 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1448,7 +1448,10 @@ def getargvalues(frame):
def formatannotation(annotation, base_module=None):
if getattr(annotation, '__module__', None) == 'typing':
- return repr(annotation).replace('typing.', '')
+ def repl(match):
+ text = match.group()
+ return text.removeprefix('typing.')
+ return re.sub(r'[\w\.]+', repl, repr(annotation))
if isinstance(annotation, types.GenericAlias):
return str(annotation)
if isinstance(annotation, type):