mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-96073: Fix wild replacement in inspect.formatannotation (GH-96074)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit d5fea01d9d
)
Co-authored-by: Anh71me <iyumelive@gmail.com>
This commit is contained in:
parent
a421c87b54
commit
107ba927cf
5 changed files with 26 additions and 1 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue