From 73efee29782708e3297ac25097021336899d968a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 14 Jul 2026 18:58:20 -0400 Subject: [PATCH] Revert normalize performance changes (gh-143658) in __init__.py Reverts the importlib_metadata/__init__.py normalize() changes introduced by the merge 8c5d91b58a (str.translate/replace optimizations from 3e7f3ac and 001db0db09), restoring the original re.sub-based implementation. Closes #540 Co-Authored-By: Claude Opus 4.8 --- importlib_metadata/__init__.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 4d5592f6..335c3b63 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -962,15 +962,8 @@ def __init__(self, name: str | None): def normalize(name): """ PEP 503 normalization plus dashes as underscores. - - Specifically avoids ``re.sub`` as prescribed for performance - benefits (see python/cpython#143658). """ - value = name.lower().replace("-", "_").replace(".", "_") - # Condense repeats - while "__" in value: - value = value.replace("__", "_") - return value + return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_') @staticmethod def legacy_normalize(name):