3232
3333# stdlib
3434import datetime
35+ import sys
36+ import typing
3537from collections import OrderedDict
3638from typing import Optional , Union
3739
@@ -110,8 +112,6 @@ def get_timezone(tz: str, date: Optional[datetime.datetime] = None) -> Optional[
110112def current_tzinfo () -> Optional [datetime .tzinfo ]:
111113 """
112114 Returns a tzinfo object for the current timezone.
113-
114- :rtype: :class:`python:datetime.tzinfo`
115115 """
116116
117117 return datetime .datetime .now ().astimezone ().tzinfo # pragma: no cover (hard to test)
@@ -126,7 +126,7 @@ def current_tzinfo() -> Optional[datetime.tzinfo]:
126126# :type datetime: :class:`datetime.datetime`
127127# :param current_tzinfo: A tzinfo object representing the current timezone.
128128# If None it will be inferred.
129- # :type current_tzinfo: :class:`~python: datetime.tzinfo`
129+ # :type current_tzinfo: :class:`datetime.tzinfo`
130130#
131131# :return: Timestamp in UTC timezone
132132# :rtype: float
@@ -140,12 +140,10 @@ def set_timezone(obj: datetime.datetime, tzinfo: datetime.tzinfo) -> datetime.da
140140 """
141141 Sets the timezone / tzinfo of the given :class:`datetime.datetime` object.
142142 This will not convert the time (i.e. the hours will stay the same).
143- Use :meth:`python: datetime.datetime.astimezone` to accomplish that.
143+ Use :meth:`datetime.datetime.astimezone` to accomplish that.
144144
145145 :param obj:
146146 :param tzinfo:
147-
148- :return:
149147 """
150148
151149 return obj .replace (tzinfo = tzinfo )
@@ -161,7 +159,7 @@ def utc_timestamp_to_datetime(
161159 If ``output_tz`` is None the timestamp is converted to the platform’s local date and time,
162160 and the local timezone is inferred and set for the object.
163161
164- If ``output_tz`` is not None, it must be an instance of a :class:`~python: datetime.tzinfo` subclass,
162+ If ``output_tz`` is not None, it must be an instance of a :class:`datetime.tzinfo` subclass,
165163 and the timestamp is converted to ``output_tz``’s time zone.
166164
167165
@@ -171,7 +169,7 @@ def utc_timestamp_to_datetime(
171169
172170 :return: The timestamp as a datetime object.
173171
174- :raises: :class:`~python: OverflowError` if the timestamp is out of the range
172+ :raises OverflowError: if the timestamp is out of the range
175173 of values supported by the platform C localtime() or gmtime() functions,
176174 and OSError on localtime() or gmtime() failure. It’s common for this to
177175 be restricted to years in 1970 through 2038.
@@ -181,8 +179,13 @@ def utc_timestamp_to_datetime(
181179 return new_datetime .astimezone (output_tz )
182180
183181
184- # Mapping of months to their 3-character shortcodes.
185- months = OrderedDict (
182+ if sys .version_info <= (3 , 7 ):
183+ MonthsType = OrderedDict
184+ else :
185+ MonthsType = typing .OrderedDict [str , str ]
186+
187+ #: Mapping of 3-character shortcodes to full month names.
188+ months : MonthsType = OrderedDict (
186189 Jan = "January" ,
187190 Feb = "February" ,
188191 Mar = "March" ,
0 commit comments