Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-130167: Improve speed ofinspect.formatannotation by replacingre#130242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
donBarbos wants to merge8 commits intopython:main
base:main
Choose a base branch
Loading
fromdonBarbos:improve-inspect-speed
Open
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Improve speed of inspect.formatannotation by replacing re
  • Loading branch information
@donBarbos
donBarbos committedFeb 17, 2025
commitef19ae67fc2b65bebd0095dfb7b800782254a89d
9 changes: 4 additions & 5 deletionsLib/inspect.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -153,7 +153,6 @@
import itertools
import linecache
import os
import re
import sys
import tokenize
import token
Expand DownExpand Up@@ -1331,10 +1330,10 @@ def formatannotation(annotation, base_module=None, *, quote_annotation_strings=T
if not quote_annotation_strings and isinstance(annotation, str):
return annotation
if getattr(annotation, '__module__', None) == 'typing':
def repl(match):
text = match.group()
return text.removeprefix('typing.')
return re.sub(r'[\w\.]+', repl, repr(annotation))
return (repr(annotation)
.replace(".typing.", "@TYPING@")
.replace("typing.", "")
.replace("@TYPING@", ".typing."))
if isinstance(annotation, types.GenericAlias):
return str(annotation)
if isinstance(annotation, type):
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp