Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/importlib_metadata/compat/py311.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

8 statements  

1import operator 

2import os 

3import pathlib 

4import sys 

5import types 

6import typing 

7 

8 

9def wrap(path): # pragma: no cover 

10 """ 

11 Workaround for https://github.com/python/cpython/issues/84538 

12 to add backward compatibility for walk_up=True. 

13 An example affected package is dask-labextension, which uses 

14 jupyter-packaging to install JupyterLab javascript files outside 

15 of site-packages. 

16 """ 

17 

18 def relative_to(root, *, walk_up=False): 

19 return pathlib.Path(os.path.relpath(path, root)) 

20 

21 return types.SimpleNamespace(relative_to=relative_to) 

22 

23 

24relative_fix = wrap if sys.version_info < (3, 12) else lambda x: x 

25 

26 

27# __protocol_attrs__ is only present on Python 3.12 and later. 

28protocol_attrs = ( 

29 typing._get_protocol_attrs # type: ignore[attr-defined] # private, 3.11 only 

30 if sys.version_info < (3, 12) 

31 else operator.attrgetter('__protocol_attrs__') 

32)