From dadf5e2ae0c41dbc72f24b8142138a23aea5dc1b Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Mon, 11 Apr 2022 13:27:28 -0500 Subject: [PATCH 01/31] Added isdst deprecation warning --- Lib/email/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index cfdfeb3f1a86e4..c1298d90ba0910 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -29,6 +29,7 @@ import socket import datetime import urllib.parse +import warnings from email._parseaddr import quote from email._parseaddr import AddressList as _AddressList @@ -345,6 +346,8 @@ def localtime(dt=None, isdst=-1): to divine whether summer time is in effect for the specified time. """ + if isdst != -1: + warnings.warn("The isdst parameter to localtime is deprecated.", DeprecationWarning, stacklevel=2) if dt is None: return datetime.datetime.now(datetime.timezone.utc).astimezone() if dt.tzinfo is not None: From 77414f9ce64da206df029b729580caa79422dcc3 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 18:34:34 +0000 Subject: [PATCH 02/31] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst diff --git a/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst b/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst new file mode 100644 index 00000000000000..ef220c270a940c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst @@ -0,0 +1 @@ +Added deprecation warning to isdst parameter of email.utils.localtime. From add07f36c614f2fd31820eeae8292cb8394c9e52 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Tue, 12 Apr 2022 12:30:16 -0500 Subject: [PATCH 03/31] added documentation and used _deprecated --- Doc/library/email.utils.rst | 5 +++-- Doc/whatsnew/3.11.rst | 3 +++ Lib/email/utils.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 0e266b6a45782a..11614472371e4a 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -11,7 +11,7 @@ There are a couple of useful utilities provided in the :mod:`email.utils` module: -.. function:: localtime(dt=None) +.. function:: localtime(dt=None, isdst=-1) Return local time as an aware datetime object. If called without arguments, return current time. Otherwise *dt* argument should be a @@ -25,7 +25,8 @@ module: is in effect for the specified time. .. versionadded:: 3.3 - + .. deprecated:: 3.11 + Use of the ``isdst`` argument is deprecated. .. function:: make_msgid(idstring=None, domain=None) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index df0b0a7fbebec9..516825c870167a 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1389,6 +1389,9 @@ Deprecated * Deprecate the ``ob_shash`` member of the :c:type:`PyBytesObject`. Use :c:func:`PyObject_Hash` instead. (Contributed by Inada Naoki in :issue:`46864`.) +* Deprecate the ``isdst`` parameter in :func:`email.utils.localtime`. + (Contributed by Alan Williams in :issue:`72346`.) + Removed ------- diff --git a/Lib/email/utils.py b/Lib/email/utils.py index c1298d90ba0910..28e5ee197cde76 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -347,7 +347,7 @@ def localtime(dt=None, isdst=-1): """ if isdst != -1: - warnings.warn("The isdst parameter to localtime is deprecated.", DeprecationWarning, stacklevel=2) + warnings._deprecated("The isdst parameter to localtime is deprecated.", remove=(3,13)) if dt is None: return datetime.datetime.now(datetime.timezone.utc).astimezone() if dt.tzinfo is not None: From 854ebf834c1c10381146f691f1250c4ab4ec287a Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Tue, 12 Apr 2022 13:03:49 -0500 Subject: [PATCH 04/31] Removed trailing whitespace. --- Doc/library/email.utils.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 11614472371e4a..93fe603e4592ca 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -26,7 +26,7 @@ module: .. versionadded:: 3.3 .. deprecated:: 3.11 - Use of the ``isdst`` argument is deprecated. + Use of the ``isdst`` argument is deprecated. .. function:: make_msgid(idstring=None, domain=None) From 1b9a60f117262e46c35c0c40c06094660db8e04b Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Wed, 13 Apr 2022 09:33:43 -0500 Subject: [PATCH 05/31] added newline, moved whatsnew, reformatted warning --- Doc/library/email.utils.rst | 1 + Doc/whatsnew/3.11.rst | 5 +++-- Lib/email/utils.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 93fe603e4592ca..186463fcafb93a 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -25,6 +25,7 @@ module: is in effect for the specified time. .. versionadded:: 3.3 + .. deprecated:: 3.11 Use of the ``isdst`` argument is deprecated. diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 516825c870167a..7271830baea352 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -853,6 +853,9 @@ Deprecated (Contributed by Brett Cannon in :issue:`47061`.) +* Deprecated the ``isdst`` parameter in :func:`email.utils.localtime`. + (Contributed by Alan Williams in :issue:`72346`.) + Removed ======= @@ -1389,8 +1392,6 @@ Deprecated * Deprecate the ``ob_shash`` member of the :c:type:`PyBytesObject`. Use :c:func:`PyObject_Hash` instead. (Contributed by Inada Naoki in :issue:`46864`.) -* Deprecate the ``isdst`` parameter in :func:`email.utils.localtime`. - (Contributed by Alan Williams in :issue:`72346`.) Removed ------- diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 28e5ee197cde76..e1f6760bc39543 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -347,7 +347,7 @@ def localtime(dt=None, isdst=-1): """ if isdst != -1: - warnings._deprecated("The isdst parameter to localtime is deprecated.", remove=(3,13)) + warnings._deprecated("The isdst parameter to localtime", remove=(3,13)) if dt is None: return datetime.datetime.now(datetime.timezone.utc).astimezone() if dt.tzinfo is not None: From 6784b42337c129085644cc974784ad0388284bc4 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Wed, 13 Apr 2022 15:04:35 -0500 Subject: [PATCH 06/31] formatting corrections --- Doc/library/email.utils.rst | 2 +- Doc/whatsnew/3.11.rst | 3 +-- Lib/email/utils.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 186463fcafb93a..c1bb5ed70dcd55 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -27,7 +27,7 @@ module: .. versionadded:: 3.3 .. deprecated:: 3.11 - Use of the ``isdst`` argument is deprecated. + Use of the *isdst* argument is deprecated. .. function:: make_msgid(idstring=None, domain=None) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 7271830baea352..b5824af4feaa92 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -853,7 +853,7 @@ Deprecated (Contributed by Brett Cannon in :issue:`47061`.) -* Deprecated the ``isdst`` parameter in :func:`email.utils.localtime`. +* Deprecated the *isdst* parameter in :func:`email.utils.localtime`. (Contributed by Alan Williams in :issue:`72346`.) @@ -1392,7 +1392,6 @@ Deprecated * Deprecate the ``ob_shash`` member of the :c:type:`PyBytesObject`. Use :c:func:`PyObject_Hash` instead. (Contributed by Inada Naoki in :issue:`46864`.) - Removed ------- diff --git a/Lib/email/utils.py b/Lib/email/utils.py index e1f6760bc39543..6a98c75b60d109 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -347,7 +347,7 @@ def localtime(dt=None, isdst=-1): """ if isdst != -1: - warnings._deprecated("The isdst parameter to localtime", remove=(3,13)) + warnings._deprecated("The isdst parameter to localtime", remove=(3, 13)) if dt is None: return datetime.datetime.now(datetime.timezone.utc).astimezone() if dt.tzinfo is not None: From 1bd66a2233e12cd250b4787919a6c1c3b2f8bdce Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Thu, 28 Apr 2022 15:01:58 -0500 Subject: [PATCH 07/31] Updated documentation and code on isdst --- Doc/library/email.utils.rst | 14 +++++------- Doc/whatsnew/3.11.rst | 2 +- Lib/email/utils.py | 44 ++++++++++--------------------------- 3 files changed, 18 insertions(+), 42 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index c1bb5ed70dcd55..1d63352b4e4f14 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -11,23 +11,19 @@ There are a couple of useful utilities provided in the :mod:`email.utils` module: -.. function:: localtime(dt=None, isdst=-1) +.. function:: localtime(dt=None) Return local time as an aware datetime object. If called without arguments, return current time. Otherwise *dt* argument should be a :class:`~datetime.datetime` instance, and it is converted to the local time zone according to the system time zone database. If *dt* is naive (that - is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. In this - case, a positive or zero value for *isdst* causes ``localtime`` to presume - initially that summer time (for example, Daylight Saving Time) is or is not - (respectively) in effect for the specified time. A negative value for - *isdst* causes the ``localtime`` to attempt to divine whether summer time - is in effect for the specified time. + is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The + isdst parameter is ignored. .. versionadded:: 3.3 - .. deprecated:: 3.11 - Use of the *isdst* argument is deprecated. + .. deprecated-removed:: 3.11 + Use of the *isdst* argument (which was undocumented) is deprecated. .. function:: make_msgid(idstring=None, domain=None) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index b5824af4feaa92..0072955961f1b3 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -854,7 +854,7 @@ Deprecated (Contributed by Brett Cannon in :issue:`47061`.) * Deprecated the *isdst* parameter in :func:`email.utils.localtime`. - (Contributed by Alan Williams in :issue:`72346`.) + (Contributed by Alan Williams in :gh:`72346`.) Removed diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 6a98c75b60d109..7d5df45abeae87 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -29,7 +29,6 @@ import socket import datetime import urllib.parse -import warnings from email._parseaddr import quote from email._parseaddr import AddressList as _AddressList @@ -332,43 +331,24 @@ def collapse_rfc2231_value(value, errors='replace', # better than not having it. # -def localtime(dt=None, isdst=-1): +def localtime(dt=None, isdst=None): """Return local time as an aware datetime object. If called without arguments, return current time. Otherwise *dt* argument should be a datetime instance, and it is converted to the local time zone according to the system time zone database. If *dt* is naive (that is, dt.tzinfo is None), it is assumed to be in local time. - In this case, a positive or zero value for *isdst* causes localtime to - presume initially that summer time (for example, Daylight Saving Time) - is or is not (respectively) in effect for the specified time. A - negative value for *isdst* causes the localtime() function to attempt - to divine whether summer time is in effect for the specified time. + The isdst parameter is ignored. """ - if isdst != -1: - warnings._deprecated("The isdst parameter to localtime", remove=(3, 13)) + if isdst != None: + import warnings + warnings._deprecated( + "The 'isdst' parameter to 'localtime'", + message='{name} (which was previously undocumented) is deprecated \ + and slated for removal in Python {remove}', + remove=(3, 13), + ) if dt is None: - return datetime.datetime.now(datetime.timezone.utc).astimezone() - if dt.tzinfo is not None: - return dt.astimezone() - # We have a naive datetime. Convert to a (localtime) timetuple and pass to - # system mktime together with the isdst hint. System mktime will return - # seconds since epoch. - tm = dt.timetuple()[:-1] + (isdst,) - seconds = time.mktime(tm) - localtm = time.localtime(seconds) - try: - delta = datetime.timedelta(seconds=localtm.tm_gmtoff) - tz = datetime.timezone(delta, localtm.tm_zone) - except AttributeError: - # Compute UTC offset and compare with the value implied by tm_isdst. - # If the values match, use the zone name implied by tm_isdst. - delta = dt - datetime.datetime(*time.gmtime(seconds)[:6]) - dst = time.daylight and localtm.tm_isdst > 0 - gmtoff = -(time.altzone if dst else time.timezone) - if delta == datetime.timedelta(seconds=gmtoff): - tz = datetime.timezone(delta, time.tzname[dst]) - else: - tz = datetime.timezone(delta) - return dt.replace(tzinfo=tz) + dt = datetime.datetime.now() + return dt.astimezone() From d3fd3f209cb502137b0c656760ce9e5125856802 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Thu, 28 Apr 2022 15:10:23 -0500 Subject: [PATCH 08/31] removed trailing whitespace --- Doc/library/email.utils.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 1d63352b4e4f14..be318d31c89d4f 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -17,7 +17,7 @@ module: arguments, return current time. Otherwise *dt* argument should be a :class:`~datetime.datetime` instance, and it is converted to the local time zone according to the system time zone database. If *dt* is naive (that - is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The + is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The isdst parameter is ignored. .. versionadded:: 3.3 From b30f940c4ca0c4f75b6d7600c697fc2a9cf9ec2e Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Thu, 28 Apr 2022 15:20:23 -0500 Subject: [PATCH 09/31] corrected spacing --- Doc/library/email.utils.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index be318d31c89d4f..83aaf6feb02407 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -13,17 +13,17 @@ module: .. function:: localtime(dt=None) - Return local time as an aware datetime object. If called without - arguments, return current time. Otherwise *dt* argument should be a - :class:`~datetime.datetime` instance, and it is converted to the local time - zone according to the system time zone database. If *dt* is naive (that - is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The - isdst parameter is ignored. + Return local time as an aware datetime object. If called without + arguments, return current time. Otherwise *dt* argument should be a + :class:`~datetime.datetime` instance, and it is converted to the local time + zone according to the system time zone database. If *dt* is naive (that + is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The + isdst parameter is ignored. - .. versionadded:: 3.3 + .. versionadded:: 3.3 - .. deprecated-removed:: 3.11 - Use of the *isdst* argument (which was undocumented) is deprecated. + .. deprecated-removed:: 3.11 + Use of the *isdst* argument (which was undocumented) is deprecated. .. function:: make_msgid(idstring=None, domain=None) From 354eff2e3578aa3af3677b927238bb5a6d0893c1 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Thu, 28 Apr 2022 15:25:30 -0500 Subject: [PATCH 10/31] use deprecated-removed properly --- Doc/library/email.utils.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 83aaf6feb02407..13de7baacda309 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -22,7 +22,7 @@ module: .. versionadded:: 3.3 - .. deprecated-removed:: 3.11 + .. deprecated-removed:: 3.11 3.13 Use of the *isdst* argument (which was undocumented) is deprecated. .. function:: make_msgid(idstring=None, domain=None) From 36365fe930c63f2f51b54697437c17e5b051df81 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Fri, 29 Apr 2022 15:20:58 -0500 Subject: [PATCH 11/31] further documentation edits --- Doc/library/email.utils.rst | 4 ++-- Lib/email/utils.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 13de7baacda309..49dc4336db027b 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -18,12 +18,12 @@ module: :class:`~datetime.datetime` instance, and it is converted to the local time zone according to the system time zone database. If *dt* is naive (that is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The - isdst parameter is ignored. + *isdst* parameter is ignored. .. versionadded:: 3.3 .. deprecated-removed:: 3.11 3.13 - Use of the *isdst* argument (which was undocumented) is deprecated. + The *isdst* parameter. .. function:: make_msgid(idstring=None, domain=None) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 7d5df45abeae87..0380a7f446be16 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -345,8 +345,7 @@ def localtime(dt=None, isdst=None): import warnings warnings._deprecated( "The 'isdst' parameter to 'localtime'", - message='{name} (which was previously undocumented) is deprecated \ - and slated for removal in Python {remove}', + message='{name} is deprecated and slated for removal in Python {remove}', remove=(3, 13), ) if dt is None: From 44f025c64388e6d2a6997994029e1df9538a0984 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Mon, 11 Apr 2022 13:27:28 -0500 Subject: [PATCH 12/31] Added isdst deprecation warning --- Lib/email/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index cfdfeb3f1a86e4..c1298d90ba0910 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -29,6 +29,7 @@ import socket import datetime import urllib.parse +import warnings from email._parseaddr import quote from email._parseaddr import AddressList as _AddressList @@ -345,6 +346,8 @@ def localtime(dt=None, isdst=-1): to divine whether summer time is in effect for the specified time. """ + if isdst != -1: + warnings.warn("The isdst parameter to localtime is deprecated.", DeprecationWarning, stacklevel=2) if dt is None: return datetime.datetime.now(datetime.timezone.utc).astimezone() if dt.tzinfo is not None: From 7125e78f6954ebc22b4c10979437a1f185079166 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 18:34:34 +0000 Subject: [PATCH 13/31] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst diff --git a/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst b/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst new file mode 100644 index 00000000000000..ef220c270a940c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst @@ -0,0 +1 @@ +Added deprecation warning to isdst parameter of email.utils.localtime. From cdea718b22d02dad6a9beeb376d9e542d27305f6 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Tue, 12 Apr 2022 12:30:16 -0500 Subject: [PATCH 14/31] added documentation and used _deprecated --- Doc/library/email.utils.rst | 5 +++-- Doc/whatsnew/3.11.rst | 3 +++ Lib/email/utils.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 0e266b6a45782a..11614472371e4a 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -11,7 +11,7 @@ There are a couple of useful utilities provided in the :mod:`email.utils` module: -.. function:: localtime(dt=None) +.. function:: localtime(dt=None, isdst=-1) Return local time as an aware datetime object. If called without arguments, return current time. Otherwise *dt* argument should be a @@ -25,7 +25,8 @@ module: is in effect for the specified time. .. versionadded:: 3.3 - + .. deprecated:: 3.11 + Use of the ``isdst`` argument is deprecated. .. function:: make_msgid(idstring=None, domain=None) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 7c72ef4d2076df..6f31161ed2ce7f 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -2080,6 +2080,9 @@ Deprecated * Deprecate the ``ob_shash`` member of the :c:type:`PyBytesObject`. Use :c:func:`PyObject_Hash` instead. (Contributed by Inada Naoki in :issue:`46864`.) +* Deprecate the ``isdst`` parameter in :func:`email.utils.localtime`. + (Contributed by Alan Williams in :issue:`72346`.) + Removed ------- diff --git a/Lib/email/utils.py b/Lib/email/utils.py index c1298d90ba0910..28e5ee197cde76 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -347,7 +347,7 @@ def localtime(dt=None, isdst=-1): """ if isdst != -1: - warnings.warn("The isdst parameter to localtime is deprecated.", DeprecationWarning, stacklevel=2) + warnings._deprecated("The isdst parameter to localtime is deprecated.", remove=(3,13)) if dt is None: return datetime.datetime.now(datetime.timezone.utc).astimezone() if dt.tzinfo is not None: From 6b0ccbb204c99661a7f1ecb653fb0eae569499b5 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Tue, 12 Apr 2022 13:03:49 -0500 Subject: [PATCH 15/31] Removed trailing whitespace. --- Doc/library/email.utils.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 11614472371e4a..93fe603e4592ca 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -26,7 +26,7 @@ module: .. versionadded:: 3.3 .. deprecated:: 3.11 - Use of the ``isdst`` argument is deprecated. + Use of the ``isdst`` argument is deprecated. .. function:: make_msgid(idstring=None, domain=None) From 47474c973461a5860be3702c4b959c474939a072 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Wed, 13 Apr 2022 09:33:43 -0500 Subject: [PATCH 16/31] added newline, moved whatsnew, reformatted warning --- Doc/library/email.utils.rst | 1 + Doc/whatsnew/3.11.rst | 5 +++-- Lib/email/utils.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 93fe603e4592ca..186463fcafb93a 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -25,6 +25,7 @@ module: is in effect for the specified time. .. versionadded:: 3.3 + .. deprecated:: 3.11 Use of the ``isdst`` argument is deprecated. diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 6f31161ed2ce7f..f691f38361241c 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1471,6 +1471,9 @@ C API: * :c:type:`PyUnicodeObject` * :c:func:`PyUnicode_InternImmortal()` +* Deprecated the ``isdst`` parameter in :func:`email.utils.localtime`. + (Contributed by Alan Williams in :issue:`72346`.) + Removed ======= @@ -2080,8 +2083,6 @@ Deprecated * Deprecate the ``ob_shash`` member of the :c:type:`PyBytesObject`. Use :c:func:`PyObject_Hash` instead. (Contributed by Inada Naoki in :issue:`46864`.) -* Deprecate the ``isdst`` parameter in :func:`email.utils.localtime`. - (Contributed by Alan Williams in :issue:`72346`.) Removed ------- diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 28e5ee197cde76..e1f6760bc39543 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -347,7 +347,7 @@ def localtime(dt=None, isdst=-1): """ if isdst != -1: - warnings._deprecated("The isdst parameter to localtime is deprecated.", remove=(3,13)) + warnings._deprecated("The isdst parameter to localtime", remove=(3,13)) if dt is None: return datetime.datetime.now(datetime.timezone.utc).astimezone() if dt.tzinfo is not None: From 0d3c5bf11aa3244cf591d8b5db148d84263d239e Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Wed, 13 Apr 2022 15:04:35 -0500 Subject: [PATCH 17/31] formatting corrections --- Doc/library/email.utils.rst | 2 +- Doc/whatsnew/3.11.rst | 3 +-- Lib/email/utils.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 186463fcafb93a..c1bb5ed70dcd55 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -27,7 +27,7 @@ module: .. versionadded:: 3.3 .. deprecated:: 3.11 - Use of the ``isdst`` argument is deprecated. + Use of the *isdst* argument is deprecated. .. function:: make_msgid(idstring=None, domain=None) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index f691f38361241c..77bf745e29be0d 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1471,7 +1471,7 @@ C API: * :c:type:`PyUnicodeObject` * :c:func:`PyUnicode_InternImmortal()` -* Deprecated the ``isdst`` parameter in :func:`email.utils.localtime`. +* Deprecated the *isdst* parameter in :func:`email.utils.localtime`. (Contributed by Alan Williams in :issue:`72346`.) @@ -2083,7 +2083,6 @@ Deprecated * Deprecate the ``ob_shash`` member of the :c:type:`PyBytesObject`. Use :c:func:`PyObject_Hash` instead. (Contributed by Inada Naoki in :issue:`46864`.) - Removed ------- diff --git a/Lib/email/utils.py b/Lib/email/utils.py index e1f6760bc39543..6a98c75b60d109 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -347,7 +347,7 @@ def localtime(dt=None, isdst=-1): """ if isdst != -1: - warnings._deprecated("The isdst parameter to localtime", remove=(3,13)) + warnings._deprecated("The isdst parameter to localtime", remove=(3, 13)) if dt is None: return datetime.datetime.now(datetime.timezone.utc).astimezone() if dt.tzinfo is not None: From 9f59d33a2fa84e513bd28b662b407e3a6f971868 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Thu, 28 Apr 2022 15:01:58 -0500 Subject: [PATCH 18/31] Updated documentation and code on isdst --- Doc/library/email.utils.rst | 14 +++++------- Doc/whatsnew/3.11.rst | 2 +- Lib/email/utils.py | 44 ++++++++++--------------------------- 3 files changed, 18 insertions(+), 42 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index c1bb5ed70dcd55..1d63352b4e4f14 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -11,23 +11,19 @@ There are a couple of useful utilities provided in the :mod:`email.utils` module: -.. function:: localtime(dt=None, isdst=-1) +.. function:: localtime(dt=None) Return local time as an aware datetime object. If called without arguments, return current time. Otherwise *dt* argument should be a :class:`~datetime.datetime` instance, and it is converted to the local time zone according to the system time zone database. If *dt* is naive (that - is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. In this - case, a positive or zero value for *isdst* causes ``localtime`` to presume - initially that summer time (for example, Daylight Saving Time) is or is not - (respectively) in effect for the specified time. A negative value for - *isdst* causes the ``localtime`` to attempt to divine whether summer time - is in effect for the specified time. + is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The + isdst parameter is ignored. .. versionadded:: 3.3 - .. deprecated:: 3.11 - Use of the *isdst* argument is deprecated. + .. deprecated-removed:: 3.11 + Use of the *isdst* argument (which was undocumented) is deprecated. .. function:: make_msgid(idstring=None, domain=None) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 77bf745e29be0d..f11efa745ef306 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1472,7 +1472,7 @@ C API: * :c:func:`PyUnicode_InternImmortal()` * Deprecated the *isdst* parameter in :func:`email.utils.localtime`. - (Contributed by Alan Williams in :issue:`72346`.) + (Contributed by Alan Williams in :gh:`72346`.) Removed diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 6a98c75b60d109..7d5df45abeae87 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -29,7 +29,6 @@ import socket import datetime import urllib.parse -import warnings from email._parseaddr import quote from email._parseaddr import AddressList as _AddressList @@ -332,43 +331,24 @@ def collapse_rfc2231_value(value, errors='replace', # better than not having it. # -def localtime(dt=None, isdst=-1): +def localtime(dt=None, isdst=None): """Return local time as an aware datetime object. If called without arguments, return current time. Otherwise *dt* argument should be a datetime instance, and it is converted to the local time zone according to the system time zone database. If *dt* is naive (that is, dt.tzinfo is None), it is assumed to be in local time. - In this case, a positive or zero value for *isdst* causes localtime to - presume initially that summer time (for example, Daylight Saving Time) - is or is not (respectively) in effect for the specified time. A - negative value for *isdst* causes the localtime() function to attempt - to divine whether summer time is in effect for the specified time. + The isdst parameter is ignored. """ - if isdst != -1: - warnings._deprecated("The isdst parameter to localtime", remove=(3, 13)) + if isdst != None: + import warnings + warnings._deprecated( + "The 'isdst' parameter to 'localtime'", + message='{name} (which was previously undocumented) is deprecated \ + and slated for removal in Python {remove}', + remove=(3, 13), + ) if dt is None: - return datetime.datetime.now(datetime.timezone.utc).astimezone() - if dt.tzinfo is not None: - return dt.astimezone() - # We have a naive datetime. Convert to a (localtime) timetuple and pass to - # system mktime together with the isdst hint. System mktime will return - # seconds since epoch. - tm = dt.timetuple()[:-1] + (isdst,) - seconds = time.mktime(tm) - localtm = time.localtime(seconds) - try: - delta = datetime.timedelta(seconds=localtm.tm_gmtoff) - tz = datetime.timezone(delta, localtm.tm_zone) - except AttributeError: - # Compute UTC offset and compare with the value implied by tm_isdst. - # If the values match, use the zone name implied by tm_isdst. - delta = dt - datetime.datetime(*time.gmtime(seconds)[:6]) - dst = time.daylight and localtm.tm_isdst > 0 - gmtoff = -(time.altzone if dst else time.timezone) - if delta == datetime.timedelta(seconds=gmtoff): - tz = datetime.timezone(delta, time.tzname[dst]) - else: - tz = datetime.timezone(delta) - return dt.replace(tzinfo=tz) + dt = datetime.datetime.now() + return dt.astimezone() From ae687b078c832df6df8d33ef48fea5f76f854619 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Thu, 28 Apr 2022 15:10:23 -0500 Subject: [PATCH 19/31] removed trailing whitespace --- Doc/library/email.utils.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 1d63352b4e4f14..be318d31c89d4f 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -17,7 +17,7 @@ module: arguments, return current time. Otherwise *dt* argument should be a :class:`~datetime.datetime` instance, and it is converted to the local time zone according to the system time zone database. If *dt* is naive (that - is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The + is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The isdst parameter is ignored. .. versionadded:: 3.3 From c214c4f32a10e7f75441fe8689c255e228808989 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Thu, 28 Apr 2022 15:20:23 -0500 Subject: [PATCH 20/31] corrected spacing --- Doc/library/email.utils.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index be318d31c89d4f..83aaf6feb02407 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -13,17 +13,17 @@ module: .. function:: localtime(dt=None) - Return local time as an aware datetime object. If called without - arguments, return current time. Otherwise *dt* argument should be a - :class:`~datetime.datetime` instance, and it is converted to the local time - zone according to the system time zone database. If *dt* is naive (that - is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The - isdst parameter is ignored. + Return local time as an aware datetime object. If called without + arguments, return current time. Otherwise *dt* argument should be a + :class:`~datetime.datetime` instance, and it is converted to the local time + zone according to the system time zone database. If *dt* is naive (that + is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The + isdst parameter is ignored. - .. versionadded:: 3.3 + .. versionadded:: 3.3 - .. deprecated-removed:: 3.11 - Use of the *isdst* argument (which was undocumented) is deprecated. + .. deprecated-removed:: 3.11 + Use of the *isdst* argument (which was undocumented) is deprecated. .. function:: make_msgid(idstring=None, domain=None) From 7cacc5fe8ac61a41d47ae6fe94ab7914f289a498 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Thu, 28 Apr 2022 15:25:30 -0500 Subject: [PATCH 21/31] use deprecated-removed properly --- Doc/library/email.utils.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 83aaf6feb02407..13de7baacda309 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -22,7 +22,7 @@ module: .. versionadded:: 3.3 - .. deprecated-removed:: 3.11 + .. deprecated-removed:: 3.11 3.13 Use of the *isdst* argument (which was undocumented) is deprecated. .. function:: make_msgid(idstring=None, domain=None) From 0633911f22e5d2d61411cfcea39f9627e6fd4100 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Fri, 29 Apr 2022 15:20:58 -0500 Subject: [PATCH 22/31] further documentation edits --- Doc/library/email.utils.rst | 4 ++-- Lib/email/utils.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 13de7baacda309..49dc4336db027b 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -18,12 +18,12 @@ module: :class:`~datetime.datetime` instance, and it is converted to the local time zone according to the system time zone database. If *dt* is naive (that is, ``dt.tzinfo`` is ``None``), it is assumed to be in local time. The - isdst parameter is ignored. + *isdst* parameter is ignored. .. versionadded:: 3.3 .. deprecated-removed:: 3.11 3.13 - Use of the *isdst* argument (which was undocumented) is deprecated. + The *isdst* parameter. .. function:: make_msgid(idstring=None, domain=None) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 7d5df45abeae87..0380a7f446be16 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -345,8 +345,7 @@ def localtime(dt=None, isdst=None): import warnings warnings._deprecated( "The 'isdst' parameter to 'localtime'", - message='{name} (which was previously undocumented) is deprecated \ - and slated for removal in Python {remove}', + message='{name} is deprecated and slated for removal in Python {remove}', remove=(3, 13), ) if dt is None: From bf4b0c6f2583e5147adfd5327a0f1c084afa5e74 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Tue, 30 Aug 2022 13:44:35 -0500 Subject: [PATCH 23/31] removed duplicated whatsnew/ moved to current ver --- Doc/whatsnew/3.11.rst | 7 ------- Doc/whatsnew/3.12.rst | 3 +++ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 40070baaa0066b..66d33d245404ff 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1471,13 +1471,6 @@ C API: * :c:type:`PyUnicodeObject` * :c:func:`PyUnicode_InternImmortal()` -* Deprecated the *isdst* parameter in :func:`email.utils.localtime`. - (Contributed by Alan Williams in :gh:`72346`.) - -* Deprecated the *isdst* parameter in :func:`email.utils.localtime`. - (Contributed by Alan Williams in :gh:`72346`.) - - Removed ======= diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index f9fa8ac3123198..6df7178a0ba71b 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -198,6 +198,9 @@ APIs: * :func:`unittest.getTestCaseNames` (:gh:`50096`) * :class:`webbrowser.MacOSX` (:gh:`86421`) +* Deprecated the *isdst* parameter in :func:`email.utils.localtime`. + (Contributed by Alan Williams in :gh:`72346`.) + Pending Removal in Python 3.14 ============================== From a63a5e4554293640f2447a1f5c37763ecd929766 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Tue, 30 Aug 2022 13:46:52 -0500 Subject: [PATCH 24/31] took one too many lines off old whatsnew --- Doc/whatsnew/3.11.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 66d33d245404ff..7c72ef4d2076df 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1471,6 +1471,7 @@ C API: * :c:type:`PyUnicodeObject` * :c:func:`PyUnicode_InternImmortal()` + Removed ======= From 8807fa19a600935a9fad741f7e8273427522056d Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Tue, 30 Aug 2022 13:47:59 -0500 Subject: [PATCH 25/31] Changed != to is not Co-authored-by: Zachary Ware --- Lib/email/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 0380a7f446be16..8b022462c877e7 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -341,7 +341,7 @@ def localtime(dt=None, isdst=None): The isdst parameter is ignored. """ - if isdst != None: + if isdst is not None: import warnings warnings._deprecated( "The 'isdst' parameter to 'localtime'", From 318ef9ec46046f1ccf1e829c742dae9556450b3a Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Tue, 30 Aug 2022 13:52:28 -0500 Subject: [PATCH 26/31] shifted versions to latest values --- Doc/library/email.utils.rst | 2 +- Lib/email/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/email.utils.rst b/Doc/library/email.utils.rst index 49dc4336db027b..345b64001c1ace 100644 --- a/Doc/library/email.utils.rst +++ b/Doc/library/email.utils.rst @@ -22,7 +22,7 @@ module: .. versionadded:: 3.3 - .. deprecated-removed:: 3.11 3.13 + .. deprecated-removed:: 3.12 3.14 The *isdst* parameter. .. function:: make_msgid(idstring=None, domain=None) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 8b022462c877e7..4d014bacd6182e 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -346,7 +346,7 @@ def localtime(dt=None, isdst=None): warnings._deprecated( "The 'isdst' parameter to 'localtime'", message='{name} is deprecated and slated for removal in Python {remove}', - remove=(3, 13), + remove=(3, 14), ) if dt is None: dt = datetime.datetime.now() From 718888cc901c4f234203b19373acc8265df4c05d Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Tue, 30 Aug 2022 14:08:17 -0500 Subject: [PATCH 27/31] Properly format documentation Co-authored-by: Ezio Melotti --- Lib/email/utils.py | 2 +- .../next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index 8b022462c877e7..b7e807535e16a1 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -345,7 +345,7 @@ def localtime(dt=None, isdst=None): import warnings warnings._deprecated( "The 'isdst' parameter to 'localtime'", - message='{name} is deprecated and slated for removal in Python {remove}', + message=f'{name} is deprecated and slated for removal in Python {remove}', remove=(3, 13), ) if dt is None: diff --git a/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst b/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst index ef220c270a940c..149ddd706c358f 100644 --- a/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst +++ b/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-72346.pC7gnM.rst @@ -1 +1 @@ -Added deprecation warning to isdst parameter of email.utils.localtime. +Added deprecation warning to *isdst* parameter of :func:`email.utils.localtime`. From 9389791203d6aef429bc86d9b83e65bde1fbb989 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Tue, 30 Aug 2022 23:23:55 +0200 Subject: [PATCH 28/31] Revert incorrect change. --- Lib/email/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index b7e807535e16a1..8b022462c877e7 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -345,7 +345,7 @@ def localtime(dt=None, isdst=None): import warnings warnings._deprecated( "The 'isdst' parameter to 'localtime'", - message=f'{name} is deprecated and slated for removal in Python {remove}', + message='{name} is deprecated and slated for removal in Python {remove}', remove=(3, 13), ) if dt is None: From 31a4c46280d8883b6f77af90647fdda751e42165 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Thu, 8 Sep 2022 09:43:57 -0500 Subject: [PATCH 29/31] Modified existing tests/added test for deprecation --- Lib/test/test_email/test_utils.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_email/test_utils.py b/Lib/test/test_email/test_utils.py index 78afb358035e81..25fa48c5ee217b 100644 --- a/Lib/test/test_email/test_utils.py +++ b/Lib/test/test_email/test_utils.py @@ -83,14 +83,14 @@ def test_localtime_is_tz_aware_daylight_false(self): def test_localtime_daylight_true_dst_false(self): test.support.patch(self, time, 'daylight', True) t0 = datetime.datetime(2012, 3, 12, 1, 1) - t1 = utils.localtime(t0, isdst=-1) + t1 = utils.localtime(t0) t2 = utils.localtime(t1) self.assertEqual(t1, t2) def test_localtime_daylight_false_dst_false(self): test.support.patch(self, time, 'daylight', False) t0 = datetime.datetime(2012, 3, 12, 1, 1) - t1 = utils.localtime(t0, isdst=-1) + t1 = utils.localtime(t0) t2 = utils.localtime(t1) self.assertEqual(t1, t2) @@ -98,7 +98,7 @@ def test_localtime_daylight_false_dst_false(self): def test_localtime_daylight_true_dst_true(self): test.support.patch(self, time, 'daylight', True) t0 = datetime.datetime(2012, 3, 12, 1, 1) - t1 = utils.localtime(t0, isdst=1) + t1 = utils.localtime(t0) t2 = utils.localtime(t1) self.assertEqual(t1, t2) @@ -106,7 +106,7 @@ def test_localtime_daylight_true_dst_true(self): def test_localtime_daylight_false_dst_true(self): test.support.patch(self, time, 'daylight', False) t0 = datetime.datetime(2012, 3, 12, 1, 1) - t1 = utils.localtime(t0, isdst=1) + t1 = utils.localtime(t0) t2 = utils.localtime(t1) self.assertEqual(t1, t2) @@ -157,6 +157,11 @@ def test_variable_tzname(self): t1 = utils.localtime(t0) self.assertEqual(t1.tzname(), 'EET') + def test_isdst_deprecation(self): + with self.assertWarns(DeprecationWarning): + t0 = datetime.datetime(1990, 1, 1) + t1 = utils.localtime(t0, isdst=True) + # Issue #24836: The timezone files are out of date (pre 2011k) # on Mac OS X Snow Leopard. @test.support.requires_mac_ver(10, 7) From d0eda9d025e8bc6a69ba9736bef2c7e9ee278b01 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Thu, 8 Sep 2022 10:26:42 -0500 Subject: [PATCH 30/31] Moved whatsnew note --- Doc/whatsnew/3.12.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 8f8363047a3312..0ef89634258bf0 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -209,9 +209,6 @@ APIs: * :func:`unittest.getTestCaseNames` (:gh:`50096`) * :class:`webbrowser.MacOSX` (:gh:`86421`) -* Deprecated the *isdst* parameter in :func:`email.utils.localtime`. - (Contributed by Alan Williams in :gh:`72346`.) - Pending Removal in Python 3.14 ============================== @@ -233,6 +230,8 @@ Pending Removal in Python 3.14 * Creating :c:data:`immutable types ` with mutable bases using the C API. +* Deprecated the *isdst* parameter in :func:`email.utils.localtime`. + (Contributed by Alan Williams in :gh:`72346`.) Pending Removal in Future Versions ---------------------------------- From 4c3413ab0831b08d6c195a99cabfb9c0dcf690c5 Mon Sep 17 00:00:00 2001 From: Alan Williams Date: Fri, 7 Oct 2022 13:40:47 -0500 Subject: [PATCH 31/31] Adjust formatting --- Doc/whatsnew/3.12.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 60bc33698f86ed..0ca12d3bbe85f3 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -286,6 +286,7 @@ Pending Removal in Python 3.14 * ``__package__`` and ``__cached__`` will cease to be set or taken into consideration by the import system (:gh:`97879`). + Pending Removal in Future Versions ----------------------------------