Skip to content

Commit 89e9eb7

Browse files
jaracoclaude
andcommitted
Revert normalize performance changes (gh-143658) in __init__.py
Reverts the importlib_metadata/__init__.py normalize() changes introduced by the merge 8c5d91b (str.translate/replace optimizations from 3e7f3ac and 001db0d), restoring the original re.sub-based implementation. Closes #540 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 555287c commit 89e9eb7

1 file changed

Lines changed: 1 addition & 8 deletions

File tree

importlib_metadata/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -962,15 +962,8 @@ def __init__(self, name: str | None):
962962
def normalize(name):
963963
"""
964964
PEP 503 normalization plus dashes as underscores.
965-
966-
Specifically avoids ``re.sub`` as prescribed for performance
967-
benefits (see python/cpython#143658).
968965
"""
969-
value = name.lower().replace("-", "_").replace(".", "_")
970-
# Condense repeats
971-
while "__" in value:
972-
value = value.replace("__", "_")
973-
return value
966+
return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
974967

975968
@staticmethod
976969
def legacy_normalize(name):

0 commit comments

Comments
 (0)