Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/icalendar/compatibility.py: 75%

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

20 statements  

1"""This module contains compatibility code for different Python versions. 

2 

3All compatibility checks and imports should go here. 

4This way, we can centralize the handling of different Python versions. 

5 

6Do NOT import this module directly if you use icalendar. 

7Members will be added and removed without deprecation warnings. 

8""" 

9 

10import functools 

11import sys 

12import warnings 

13from typing import TypeGuard 

14 

15if sys.version_info >= (3, 11): 

16 from typing import Self 

17else: 

18 from typing_extensions import Self 

19 

20if sys.version_info >= (3, 13): 

21 from typing import TypeIs 

22else: 

23 from typing_extensions import TypeIs 

24 

25 

26def deprecate_for_version_8(func): 

27 """Issue a warning for deprecated functions to be removed in version 8.""" 

28 public_name = func.__name__.removeprefix("_") 

29 

30 @functools.wraps(func) 

31 def wrapper(*args, **kwargs): 

32 warnings.warn( 

33 f"{public_name} is deprecated and will be removed in icalendar 8", 

34 DeprecationWarning, 

35 stacklevel=2, 

36 ) 

37 wrapper.__name__ = public_name 

38 return func(*args, **kwargs) 

39 

40 return wrapper 

41 

42 

43__all__ = [ 

44 "Self", 

45 "TypeGuard", 

46 "TypeIs", 

47 "deprecate_for_version_8", 

48]