diff options
author | Anh71me <iyumelive@gmail.com> | 2022-10-07 18:23:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-07 18:23:06 (GMT) |
commit | d5fea01d9d439b1638cd8e5db19c33909841d86f (patch) | |
tree | 0be1fac1076f8ef77702a808ab4a1fa39a9814b7 /Lib/inspect.py | |
parent | 676d8ef3806758bcd1d3fd84a746c8a9b64480d0 (diff) | |
download | cpython-d5fea01d9d439b1638cd8e5db19c33909841d86f.zip cpython-d5fea01d9d439b1638cd8e5db19c33909841d86f.tar.gz cpython-d5fea01d9d439b1638cd8e5db19c33909841d86f.tar.bz2 |
GH-96073: Fix wild replacement in inspect.formatannotation (#96074)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 8a107a8..585875a 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1433,7 +1433,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): |