-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
bpo-34246: Use no mutable default args in smtplib #8554
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There is nothing wrong with using mutable default arguments if they are not mutated inside function and are not exposed outside of it. For |
49247c0
to
2975697
Compare
Some methods of the SMTP class use mutable default arguments. Specially `send_message` is affected in which it mutates one of the args by appending items to it, whic has side effects on further calls.
2975697
to
67f70fd
Compare
Hello, @serhiy-storchaka. Thanks so much for reviewing my changes. It's now cleaner with tuples 👍 I'm not sure whether I should ping you or if the new commit (67f70fd) triggers that automatically. |
Please don't squash commits, this makes reviewing new changes more difficult. I have not received a notification because you edited your commit instead of adding a new commit. |
@@ -0,0 +1,2 @@ | |||
Use an empty tuple as the default argument for mail_options and avoid it from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The argument for what function? Using an empty tuple is an implementation detail, please describe the user visible behavior change. For example ":meth:`smtplib.SMTP.send_message` no longer modifies the content of the *mail_options* argument.
" or something like.
Add also "Patch by Pablo S. Blum de Aguiar."
@@ -958,7 +958,7 @@ def send_message(self, msg, from_addr=None, to_addrs=None, | |||
if international: | |||
g = email.generator.BytesGenerator( | |||
bytesmsg, policy=msg.policy.clone(utf8=True)) | |||
mail_options += ['SMTPUTF8', 'BODY=8BITMIME'] | |||
mail_options = (*mail_options, 'SMTPUTF8', 'BODY=8BITMIME') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this change. +=
seems more common/readable, and it's valid for immutable objects
like tuple and str. (You need to change []
to ()
in this case)
I'm sorry, I was wrong. When caller passed list, list += tuple will raise TypeError.
Just to ensure `smtplib.SMTP.send_message` no longer modifies the content of the *mail_options* argument
Hey, I hope the 2 new commits I added 10 days ago triggered a notification. I also hope this message isn't just additional noise – apologies if it is, I'm still new to contrubuting to CPython. |
Thank you for your reminder @scorphus. It is not a noise. This PR LGTM, but we need to get an approval from @bitdancer or @warsaw, the email module experts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update also the signature in Doc/library/smtplib.rst
.
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 phrase |
I have made the requested changes; please review again. Regarding #5334 (and issue32657) it proposes a change that was already discussed here and droped in favour of the current status of this very PR (#8554). |
Thanks for making the requested changes! @serhiy-storchaka: please review the changes made to this pull request. |
If rcpt_options expected to be a sequence, not mapping, it is better to make a default value for options in |
Yeah, I thought so – and actually did exactly that in my initial change – but decided not to, as |
Done, @serhiy-storchaka How about |
It won't hurt :-) Making the default value for |
Cool! Thanks, @serhiy-storchaka. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you for your contribution Pablo!
YAY! Thanks for reviewing! I'm very happy to contribute! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thanks @scorphus for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
Some methods of the SMTP class use mutable default arguments. Specially `send_message` is affected as it mutates one of the args by appending items to it, which has side effects on further calls. (cherry picked from commit d5fbe9b) Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
GH-9111 is a backport of this pull request to the 3.7 branch. |
Sorry, @scorphus and @pablogsal, I could not cleanly backport this to |
Some methods of the SMTP class use mutable default arguments. Specially `send_message` is affected as it mutates one of the args by appending items to it, which has side effects on further calls. (cherry picked from commit d5fbe9b) Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
GH-9112 is a backport of this pull request to the 3.6 branch. |
Some methods of the SMTP class use mutable default arguments. Specially `send_message` is affected as it mutates one of the args by appending items to it, which has side effects on further calls.. (cherry picked from commit d5fbe9b) Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
) Some methods of the SMTP class use mutable default arguments. Specially `send_message` is affected as it mutates one of the args by appending items to it, which has side effects on further calls.. (cherry picked from commit d5fbe9b) Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
Some methods of the SMTP class use mutable default arguments. Specially
send_message
is affected in which it mutates one of the args by appending items to it, whic has side effects on further calls.https://bugs.python.org/issue34246