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
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
1"""
2Provides the default implementation of :class:`ArrowFactory <arrow.factory.ArrowFactory>`
3methods for use as a module API.
5"""
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
12from arrow.arrow import TZ_EXPR, Arrow
13from arrow.constants import DEFAULT_LOCALE
14from arrow.factory import ArrowFactory
16# internal default factory.
17_factory = ArrowFactory()
19# TODO: Use Positional Only Argument (https://www.python.org/dev/peps/pep-0570/)
20# after Python 3.7 deprecation
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
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
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
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
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
83def get(*args: Any, **kwargs: Any) -> Arrow:
84 """Calls the default :class:`ArrowFactory <arrow.factory.ArrowFactory>` ``get`` method."""
86 return _factory.get(*args, **kwargs)
89get.__doc__ = _factory.get.__doc__
92def utcnow() -> Arrow:
93 """Calls the default :class:`ArrowFactory <arrow.factory.ArrowFactory>` ``utcnow`` method."""
95 return _factory.utcnow()
98utcnow.__doc__ = _factory.utcnow.__doc__
101def now(tz: Optional[TZ_EXPR] = None) -> Arrow:
102 """Calls the default :class:`ArrowFactory <arrow.factory.ArrowFactory>` ``now`` method."""
104 return _factory.now(tz)
107now.__doc__ = _factory.now.__doc__
110def factory(type: Type[Arrow]) -> ArrowFactory:
111 """Returns an :class:`.ArrowFactory` for the specified :class:`Arrow <arrow.arrow.Arrow>`
112 or derived type.
114 :param type: the type, :class:`Arrow <arrow.arrow.Arrow>` or derived.
116 """
118 return ArrowFactory(type)
121__all__ = ["get", "utcnow", "now", "factory"]