Skip to content

Commit

Permalink
pythonGH-96073: Fix wild replacement in formatannotation
Browse files Browse the repository at this point in the history
  • Loading branch information
iyume committed Aug 18, 2022
1 parent 157aef7 commit f14fcb4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,12 @@ 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()
if text.startswith('typing.'):
return text[len('typing.'):]
return text
return re.sub(r'[\w\.]+', repl, repr(annotation))
if isinstance(annotation, types.GenericAlias):
return str(annotation)
if isinstance(annotation, type):
Expand Down

0 comments on commit f14fcb4

Please sign in to comment.