Skip to content

Commit 4098b51

Browse files
committed
Perform exact match on Prepared.normalized, and then add a separate check for an empty self.normalized instead of relying on a degenerate result from startswith.
1 parent 7bdbb57 commit 4098b51

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

importlib_metadata/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class Prepared:
474474
"""
475475
A prepared search for metadata on a possibly-named package.
476476
"""
477-
normalized = ''
477+
normalized = None
478478
prefix = ''
479479
suffixes = '.dist-info', '.egg-info'
480480
exact_matches = [''][:0]
@@ -503,8 +503,10 @@ def matches(self, cand, base):
503503
name, sep, rest = pre.partition('-')
504504
return (
505505
low in self.exact_matches
506-
or name.replace('.', '_').startswith(self.normalized)
507-
and ext in self.suffixes
506+
or ext in self.suffixes and (
507+
not self.normalized or
508+
name.replace('.', '_') == self.normalized
509+
)
508510
# legacy case:
509511
or self.is_egg(base) and low == 'egg-info'
510512
)

0 commit comments

Comments
 (0)