Skip to content

Commit eb621bd

Browse files
committed
Add compatibility layer for Python 3.8 stdlib lack of _normalized_name
1 parent 9c2e16e commit eb621bd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

importlib_metadata/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,9 +1015,18 @@ def version(distribution_name):
10151015
return distribution(distribution_name).version
10161016

10171017

1018+
def _compat_normalized_name(dist: Distribution) -> Optional[str]:
1019+
"""
1020+
Compatibility layer that honor name normalization for distributions
1021+
that don't provide ``_normalized_name``
1022+
(as in ``importlib.metadata`` for Python 3.8/3.9).
1023+
"""
1024+
return getattr(dist, '_normalized_name', None) or Prepared.normalize(dist.name)
1025+
1026+
10181027
_unique = functools.partial(
10191028
unique_everseen,
1020-
key=operator.attrgetter('_normalized_name'),
1029+
key=_compat_normalized_name,
10211030
)
10221031
"""
10231032
Wrapper for ``distributions`` to return unique distributions by name.

0 commit comments

Comments
 (0)