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

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

30 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: 

30 ... # pragma: no cover 

31 

32 

33@overload 

34def get( 

35 *args: int, 

36 locale: str = DEFAULT_LOCALE, 

37 tzinfo: Optional[TZ_EXPR] = None, 

38 normalize_whitespace: bool = False, 

39) -> Arrow: 

40 ... # pragma: no cover 

41 

42 

43@overload 

44def get( 

45 __obj: Union[ 

46 Arrow, 

47 datetime, 

48 date, 

49 struct_time, 

50 dt_tzinfo, 

51 int, 

52 float, 

53 str, 

54 Tuple[int, int, int], 

55 ], 

56 *, 

57 locale: str = DEFAULT_LOCALE, 

58 tzinfo: Optional[TZ_EXPR] = None, 

59 normalize_whitespace: bool = False, 

60) -> Arrow: 

61 ... # pragma: no cover 

62 

63 

64@overload 

65def get( 

66 __arg1: Union[datetime, date], 

67 __arg2: TZ_EXPR, 

68 *, 

69 locale: str = DEFAULT_LOCALE, 

70 tzinfo: Optional[TZ_EXPR] = None, 

71 normalize_whitespace: bool = False, 

72) -> Arrow: 

73 ... # pragma: no cover 

74 

75 

76@overload 

77def get( 

78 __arg1: str, 

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

80 *, 

81 locale: str = DEFAULT_LOCALE, 

82 tzinfo: Optional[TZ_EXPR] = None, 

83 normalize_whitespace: bool = False, 

84) -> Arrow: 

85 ... # pragma: no cover 

86 

87 

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

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

90 

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

92 

93 

94get.__doc__ = _factory.get.__doc__ 

95 

96 

97def utcnow() -> Arrow: 

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

99 

100 return _factory.utcnow() 

101 

102 

103utcnow.__doc__ = _factory.utcnow.__doc__ 

104 

105 

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

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

108 

109 return _factory.now(tz) 

110 

111 

112now.__doc__ = _factory.now.__doc__ 

113 

114 

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

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

117 or derived type. 

118 

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

120 

121 """ 

122 

123 return ArrowFactory(type) 

124 

125 

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