Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/arrow/api.py: 85%

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

26 statements  

1""" 

2Provides the default implementation of :class:`ArrowFactory <arrow.factory.ArrowFactory>` 

3methods for use as a module API. 

4 

5""" 

6 

7from datetime import date, datetime 

8from datetime import tzinfo as dt_tzinfo 

9from time import struct_time 

10from typing import Any, List, Optional, Tuple, Type, Union, overload 

11 

12from arrow.arrow import TZ_EXPR, Arrow 

13from arrow.constants import DEFAULT_LOCALE 

14from arrow.factory import ArrowFactory 

15 

16# internal default factory. 

17_factory = ArrowFactory() 

18 

19# TODO: Use Positional Only Argument (https://www.python.org/dev/peps/pep-0570/) 

20# after Python 3.7 deprecation 

21 

22 

23@overload 

24def get( 

25 *, 

26 locale: str = DEFAULT_LOCALE, 

27 tzinfo: Optional[TZ_EXPR] = None, 

28 normalize_whitespace: bool = False, 

29) -> Arrow: ... # pragma: no cover 

30 

31 

32@overload 

33def get( 

34 *args: int, 

35 locale: str = DEFAULT_LOCALE, 

36 tzinfo: Optional[TZ_EXPR] = None, 

37 normalize_whitespace: bool = False, 

38) -> Arrow: ... # pragma: no cover 

39 

40 

41@overload 

42def get( 

43 __obj: Union[ 

44 Arrow, 

45 datetime, 

46 date, 

47 struct_time, 

48 dt_tzinfo, 

49 int, 

50 float, 

51 str, 

52 Tuple[int, int, int], 

53 ], 

54 *, 

55 locale: str = DEFAULT_LOCALE, 

56 tzinfo: Optional[TZ_EXPR] = None, 

57 normalize_whitespace: bool = False, 

58) -> Arrow: ... # pragma: no cover 

59 

60 

61@overload 

62def get( 

63 __arg1: Union[datetime, date], 

64 __arg2: TZ_EXPR, 

65 *, 

66 locale: str = DEFAULT_LOCALE, 

67 tzinfo: Optional[TZ_EXPR] = None, 

68 normalize_whitespace: bool = False, 

69) -> Arrow: ... # pragma: no cover 

70 

71 

72@overload 

73def get( 

74 __arg1: str, 

75 __arg2: Union[str, List[str]], 

76 *, 

77 locale: str = DEFAULT_LOCALE, 

78 tzinfo: Optional[TZ_EXPR] = None, 

79 normalize_whitespace: bool = False, 

80) -> Arrow: ... # pragma: no cover 

81 

82 

83def get(*args: Any, **kwargs: Any) -> Arrow: 

84 """Calls the default :class:`ArrowFactory <arrow.factory.ArrowFactory>` ``get`` method.""" 

85 

86 return _factory.get(*args, **kwargs) 

87 

88 

89get.__doc__ = _factory.get.__doc__ 

90 

91 

92def utcnow() -> Arrow: 

93 """Calls the default :class:`ArrowFactory <arrow.factory.ArrowFactory>` ``utcnow`` method.""" 

94 

95 return _factory.utcnow() 

96 

97 

98utcnow.__doc__ = _factory.utcnow.__doc__ 

99 

100 

101def now(tz: Optional[TZ_EXPR] = None) -> Arrow: 

102 """Calls the default :class:`ArrowFactory <arrow.factory.ArrowFactory>` ``now`` method.""" 

103 

104 return _factory.now(tz) 

105 

106 

107now.__doc__ = _factory.now.__doc__ 

108 

109 

110def factory(type: Type[Arrow]) -> ArrowFactory: 

111 """Returns an :class:`.ArrowFactory` for the specified :class:`Arrow <arrow.arrow.Arrow>` 

112 or derived type. 

113 

114 :param type: the type, :class:`Arrow <arrow.arrow.Arrow>` or derived. 

115 

116 """ 

117 

118 return ArrowFactory(type) 

119 

120 

121__all__ = ["get", "utcnow", "now", "factory"]