mirror of
https://github.com/python/cpython.git
synced 2025-10-13 10:23:28 +00:00
GH-96073: Fix wild replacement in inspect.formatannotation (#96074)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
676d8ef380
commit
d5fea01d9d
5 changed files with 26 additions and 1 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue