Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
dadf5e2
Added isdst deprecation warning
alanfwilliams Apr 11, 2022
77414f9
📜🤖 Added by blurb_it.
blurb-it[bot] Apr 11, 2022
add07f3
added documentation and used _deprecated
alanfwilliams Apr 12, 2022
854ebf8
Removed trailing whitespace.
alanfwilliams Apr 12, 2022
1b9a60f
added newline, moved whatsnew, reformatted warning
alanfwilliams Apr 13, 2022
6784b42
formatting corrections
alanfwilliams Apr 13, 2022
1bd66a2
Updated documentation and code on isdst
alanfwilliams Apr 28, 2022
d3fd3f2
removed trailing whitespace
alanfwilliams Apr 28, 2022
b30f940
corrected spacing
alanfwilliams Apr 28, 2022
354eff2
use deprecated-removed properly
alanfwilliams Apr 28, 2022
36365fe
further documentation edits
alanfwilliams Apr 29, 2022
44f025c
Added isdst deprecation warning
alanfwilliams Apr 11, 2022
7125e78
📜🤖 Added by blurb_it.
blurb-it[bot] Apr 11, 2022
cdea718
added documentation and used _deprecated
alanfwilliams Apr 12, 2022
6b0ccbb
Removed trailing whitespace.
alanfwilliams Apr 12, 2022
47474c9
added newline, moved whatsnew, reformatted warning
alanfwilliams Apr 13, 2022
0d3c5bf
formatting corrections
alanfwilliams Apr 13, 2022
9f59d33
Updated documentation and code on isdst
alanfwilliams Apr 28, 2022
ae687b0
removed trailing whitespace
alanfwilliams Apr 28, 2022
c214c4f
corrected spacing
alanfwilliams Apr 28, 2022
7cacc5f
use deprecated-removed properly
alanfwilliams Apr 28, 2022
0633911
further documentation edits
alanfwilliams Apr 29, 2022
e483ed6
Merge branch 'fix-gh-72346' of https://github.com/aw1231/cpython into…
alanfwilliams Aug 30, 2022
bf4b0c6
removed duplicated whatsnew/ moved to current ver
alanfwilliams Aug 30, 2022
a63a5e4
took one too many lines off old whatsnew
alanfwilliams Aug 30, 2022
8807fa1
Changed != to is not
alanfwilliams Aug 30, 2022
318ef9e
shifted versions to latest values
alanfwilliams Aug 30, 2022
718888c
Properly format documentation
alanfwilliams Aug 30, 2022
9389791
Revert incorrect change.
ezio-melotti Aug 30, 2022
672b5e5
Merge branch 'fix-gh-72346' of https://github.com/aw1231/cpython into…
alanfwilliams Sep 2, 2022
89eb11a
Merge branch 'main' into fix-gh-72346
alanfwilliams Sep 7, 2022
c2b4c94
Merge branch 'fix-gh-72346' of https://github.com/aw1231/cpython into…
alanfwilliams Sep 7, 2022
31a4c46
Modified existing tests/added test for deprecation
alanfwilliams Sep 8, 2022
54596ef
Merge branch 'main' into fix-gh-72346
alanfwilliams Sep 8, 2022
d0eda9d
Moved whatsnew note
alanfwilliams Sep 8, 2022
ecc3bff
Merge branch 'fix-gh-72346' of https://github.com/aw1231/cpython into…
alanfwilliams Sep 8, 2022
8151b5a
Merge branch 'main' into fix-gh-72346
alanfwilliams Oct 7, 2022
4c3413a
Adjust formatting
alanfwilliams Oct 7, 2022
7ff165e
Merge branch 'main' into fix-gh-72346
alanfwilliams Oct 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Doc/library/email.utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it wasn't documented before and is being removed, we probably don't want to add it now :). The deprecation note can mention that it was previously undocumented.


Return local time as an aware datetime object. If called without
arguments, return current time. Otherwise *dt* argument should be a
Expand All @@ -26,6 +26,8 @@ module:

.. versionadded:: 3.3

.. deprecated:: 3.11
Comment thread
alanfwilliams marked this conversation as resolved.
Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're specifying in the code that it will be removed in 3.13, we can use the deprecated-removed directive here to also document when it will disappear.

Use of the *isdst* argument is deprecated.

.. function:: make_msgid(idstring=None, domain=None)

Expand Down
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:issue:`72346` will direct to https://bugs.python.org/issue72346, which doesn't exist :). This should now be :gh:`72346` , IIUC.



Removed
=======
Expand Down
3 changes: 3 additions & 0 deletions Lib/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import socket
import datetime
import urllib.parse
import warnings
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this should generally not be necessary unless someone is passing in a value for isdst, it can be imported where it's used.


from email._parseaddr import quote
from email._parseaddr import AddressList as _AddressList
Expand Down Expand Up @@ -345,6 +346,8 @@ def localtime(dt=None, isdst=-1):
to divine whether summer time is in effect for the specified time.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring should be updated to remove everything about isdst, and replace it with a simple note that the parameter is ignored. Similar in the documentation.


"""
if isdst != -1:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to change the default value here to detect when someone is passing in -1 explicitly. None is fine as the new default, or you could add _ignored = object() just before this function and use _ignored as the new default.

warnings._deprecated("The isdst parameter to localtime", remove=(3, 13))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the easy route here makes for an ugly message: 'The isdst argument to localtime' is deprecated .... We need to specify our own message to make it prettier:

Suggested change
warnings._deprecated("The isdst parameter to localtime", remove=(3, 13))
warnings._deprecated(
"The 'isdst' parameter to 'localtime'",
message='{name} 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:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the issue, this whole function can be reduced to just a thin wrapper around datetime.astimezone():

if dt is None:
    dt = datetime.datetime.now()
return dt.astimezone()

(Extra code for the deprecated parameter not shown :))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added deprecation warning to isdst parameter of email.utils.localtime.
Comment thread
alanfwilliams marked this conversation as resolved.
Outdated