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-143658: Usestr.lower andreplace to further improve performance ofimportlib.metadata.Prepared.normalized#144083

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
hugovk wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromhugovk:3.15-importlib.metadata-normalized
Open
Show file tree
Hide file tree
Changes fromall commits
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
13 changes: 2 additions & 11 deletionsLib/importlib/metadata/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -890,14 +890,6 @@ def search(self, prepared: Prepared):
return itertools.chain(infos, eggs)


# Translation table for Prepared.normalize: lowercase and
# replace "-" (hyphen) and "." (dot) with "_" (underscore).
_normalize_table = str.maketrans(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ-.",
"abcdefghijklmnopqrstuvwxyz__",
)


class Prepared:
"""
A prepared search query for metadata on a possibly-named package.
Expand DownExpand Up@@ -933,9 +925,8 @@ def normalize(name):
"""
PEP 503 normalization plus dashes as underscores.
"""
# Emulates ``re.sub(r"[-_.]+", "-", name).lower()`` from PEP 503
# About 3x faster, safe since packages only support alphanumeric characters
value = name.translate(_normalize_table)
# Much faster than re.sub, and even faster than str.translate
value = name.lower().replace("-", "_").replace(".", "_")
# Condense repeats (faster than regex)
while "__" in value:
value = value.replace("__", "_")
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
:mod:`importlib.metadata`: Use :meth:`str.lower` and :meth:`str.replace` to
further improve performance of
:meth:`!importlib.metadata.Prepared.normalize`. Patch by Hugo van Kemenade
and Henry Schreiner.
Loading

[8]ページ先頭

©2009-2026 Movatter.jp