Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/importlib_metadata/_py39compat.py: 29%

14 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-01 06:54 +0000

1""" 

2Compatibility layer with Python 3.8/3.9 

3""" 

4from typing import TYPE_CHECKING, Any, Optional 

5 

6if TYPE_CHECKING: # pragma: no cover 

7 # Prevent circular imports on runtime. 

8 from . import Distribution, EntryPoint 

9else: 

10 Distribution = EntryPoint = Any 

11 

12 

13def normalized_name(dist: Distribution) -> Optional[str]: 

14 """ 

15 Honor name normalization for distributions that don't provide ``_normalized_name``. 

16 """ 

17 try: 

18 return dist._normalized_name 

19 except AttributeError: 

20 from . import Prepared # -> delay to prevent circular imports. 

21 

22 return Prepared.normalize(getattr(dist, "name", None) or dist.metadata['Name']) 

23 

24 

25def ep_matches(ep: EntryPoint, **params) -> bool: 

26 """ 

27 Workaround for ``EntryPoint`` objects without the ``matches`` method. 

28 """ 

29 try: 

30 return ep.matches(**params) 

31 except AttributeError: 

32 from . import EntryPoint # -> delay to prevent circular imports. 

33 

34 # Reconstruct the EntryPoint object to make sure it is compatible. 

35 return EntryPoint(ep.name, ep.value, ep.group).matches(**params)