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

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

6 statements  

1import sys 

2 

3from . import py311 

4 

5# Distribution.origin was added in Python 3.13, so a provider built on 

6# importlib.metadata cannot supply it on every supported Python and must 

7# not be faulted for its absence. 

8exempt = frozenset({'origin'}) if sys.version_info < (3, 13) else frozenset() 

9 

10 

11def required(protocol): 

12 """ 

13 The members a protocol expects of a provider on this Python. 

14 """ 

15 return set(py311.protocol_attrs(protocol)) - exempt 

16 

17 

18def tolerant_conforms(instance, protocol): # pragma: no cover 

19 """ 

20 Determine conformance, overlooking the exempt members. 

21 

22 Consults the type rather than the instance, which also keeps 

23 isinstance() from evaluating property members on Python 3.11 

24 (https://github.com/python/cpython/issues/102433). 

25 """ 

26 return all(hasattr(type(instance), attr) for attr in required(protocol)) 

27 

28 

29conforms = tolerant_conforms if sys.version_info < (3, 13) else isinstance