Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-72346: Added isdst deprecation warning to email.utils.localtime#91450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
zware merged 39 commits intopython:mainfromalanfwilliams:fix-gh-72346
Mar 20, 2023

Conversation

alanfwilliams
Copy link
Contributor

@alanfwilliamsalanfwilliams commentedApr 11, 2022
edited by bedevere-bot
Loading

This adds a deprecation warning to the isdst parameter in email.utils.localtime. This is my first contribution so any feedback is welcome.

@ghost

This comment was marked as outdated.

@alanfwilliams
Copy link
ContributorAuthor

I'm not sure why it says I haven't signed the CLA. I did just link it with my github account so it may take a moment to refresh I assume.

@zware
Copy link
Member

Closing and re-opening to re-trigger the CLA check.

@zwarezware closed thisApr 11, 2022
@zwarezware reopened thisApr 11, 2022
@zwarezware linked an issueApr 12, 2022 that may beclosed by this pull request
Copy link
Member

@hugovkhugovk left a comment

Choose a reason for hiding this comment

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

A good start, thanks!

It would need some documentation updating too.

Put a.. deprecated:: 3.11 under the function inemail.utils.rst. For example, have a look at:

And also list it on "What’s New In Python 3.11":

@alanfwilliams
Copy link
ContributorAuthor

@hugovk I've added the edits you've requested. Thanks for the quick review.

Copy link
Member

@hugovkhugovk left a comment

Choose a reason for hiding this comment

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

Thanks for the update!

@alanfwilliams
Copy link
ContributorAuthor

@hugovk I've completed the changes you requested.

Copy link
Member

@hugovkhugovk left a comment

Choose a reason for hiding this comment

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

Thanks! Just a couple of minor style things!

@@ -26,6 +26,8 @@ module:

.. versionadded:: 3.3

.. deprecated:: 3.11
Use of the ``isdst`` argument is deprecated.
Copy link
Member

Choose a reason for hiding this comment

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

I just noticed the style for parameters is italics (for example see the docstring):

Suggested change
Use of the``isdst`` argument is deprecated.
Use of the*isdst* argument is deprecated.

@@ -853,6 +853,9 @@ Deprecated

(Contributed by Brett Cannon in :issue:`47061`.)

* Deprecated the ``isdst`` parameter in :func:`email.utils.localtime`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Deprecated the``isdst`` parameter in:func:`email.utils.localtime`.
* Deprecated the*isdst* parameter in:func:`email.utils.localtime`.

@@ -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._deprecated("The isdst parameter to localtime", remove=(3,13))
Copy link
Member

Choose a reason for hiding this comment

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

A little nit :)

Suggested change
warnings._deprecated("The isdst parameter to localtime",remove=(3,13))
warnings._deprecated("The isdst parameter to localtime",remove=(3,13))

Copy link
Member

@hugovkhugovk left a comment
edited
Loading

Choose a reason for hiding this comment

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

Thanks, looks good! Hopefully a core dev can take a look soon and trigger the CI.

cc@abalkin,@bitdancer,@Mariatta

@hugovkhugovk added topic-email stdlibPython modules in the Lib dir 3.11only security fixes labelsApr 13, 2022
@alanfwilliams
Copy link
ContributorAuthor

Hi, just wanted to check if there was anything I could do to move this along.

Copy link
Member

@zwarezware left a comment

Choose a reason for hiding this comment

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

This is a great start! A few things to fix up, though.

There will also need to be test changes for this, both to test that the deprecation warning is emitted as expected, and to prevent it from escaping where we don't want it.

Also, note that I'm not a maintainer of theemail package, so these are just general suggestions to hopefully make this quicker and easier for one of them to accept :)

@@ -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:
Copy link
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.

@@ -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._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:
Copy link
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 arounddatetime.astimezone():

ifdtisNone:dt=datetime.datetime.now()returndt.astimezone()

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

@@ -29,6 +29,7 @@
import socket
import datetime
import urllib.parse
import warnings
Copy link
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 forisdst, it can be imported where it's used.

@@ -26,6 +26,8 @@ module:

.. versionadded:: 3.3

.. deprecated:: 3.11
Copy link
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 thedeprecated-removed directive here to also document when it will disappear.

@@ -345,6 +346,8 @@ def localtime(dt=None, isdst=-1):
to divine whether summer time is in effect for the specified time.
Copy link
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 aboutisdst, and replace it with a simple note that the parameter is ignored. Similar in the documentation.

@@ -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._deprecated("The isdst parameter to localtime", remove=(3, 13))
Copy link
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}isdeprecatedandslatedforremovalinPython {remove},
remove=(3,13),
)

@@ -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
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.

@@ -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
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 tohttps://bugs.python.org/issue72346, which doesn't exist :). This should now be:gh:`72346`, IIUC.

ezio-melotti reacted with thumbs up emoji
@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@alanfwilliams
Copy link
ContributorAuthor

Although it seems that the Azure test isn't working properly (says it passed in the output, but is marked as failed), I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@zware: please review the changes made to this pull request.

@alanfwilliams
Copy link
ContributorAuthor

Hey@zware, any chance you can take a look at this?

@zware
Copy link
Member

5 months later, yes! LGTM, sorry for the delay.

@zwarezware merged commit5e6661b intopython:mainMar 20, 2023
@zwarezware added 3.12only security fixes and removed 3.11only security fixes labelsMar 20, 2023
Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this pull requestMar 27, 2023
warsaw pushed a commit to warsaw/cpython that referenced this pull requestApr 11, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@hugovkhugovkhugovk approved these changes

@ezio-melottiezio-melottiezio-melotti left review comments

@zwarezwarezware approved these changes

Assignees
No one assigned
Labels
3.12only security fixesstdlibPython modules in the Lib dirtopic-email
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Deprecate isdst argument in email.utils.localtime
5 participants
@alanfwilliams@zware@bedevere-bot@hugovk@ezio-melotti

[8]ページ先頭

©2009-2025 Movatter.jp