Issue32680
Created on 2018-01-26 15:26 by Romuald, last changed 2018-10-09 14:35 by giampaolo.rodola. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 5345 | merged | Romuald, 2018-01-26 15:31 | |
| Messages (7) | |||
|---|---|---|---|
| msg310764 - (view) | Author: Romuald Brunet (Romuald) * | Date: 2018-01-26 15:26 | |
SMTP instances from the smtplib module are not creating their sock attribute consistently after __init__ When host is sent as parameter a sock object is created (and hopefully, connected) When the host is not sent, the sock attribute doesn't exist at all |
|||
| msg310766 - (view) | Author: Romuald Brunet (Romuald) * | Date: 2018-01-26 15:34 | |
My use case:
try:
s = SMTP('myhost')
s.do_some_sending()
finaly:
if s is not None and s.sock is not None:
s.quit()
But I realize just now that in that case, if s was initialized correctly, its sock was inevitably set
|
|||
| msg310774 - (view) | Author: Stéphane Wirtel (matrixise) * | Date: 2018-01-26 16:10 | |
You are right, but...
if there is an exception in the connect method before the init of
self.sock, the sock attribute will not exist and in this case, and only
in this case, there will be an exception in the close method.
your code will work fine if you use a try/finally but not in the case
where we use the with statement, for example.
with SMTP('myhost') as smtp:
smtp.do_something()
If there is an exception in the __init__ of SMTP and self.sock is not
initialized -> traceback.
|
|||
| msg311553 - (view) | Author: (amirjn) | Date: 2018-02-03 13:55 | |
same problem at apple.com |
|||
| msg311554 - (view) | Author: (amirjn) | Date: 2018-02-03 13:57 | |
<a href="apple.com">apple.com</a> |
|||
| msg327409 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * | Date: 2018-10-09 14:32 | |
New changeset 7b313971805ca9b53f181f7b97e5376d0b89dc06 by Giampaolo Rodola (Romuald Brunet) in branch 'master': bpo-32680 add default "sock" on SMTP objects (#5345) https://github.com/python/cpython/commit/7b313971805ca9b53f181f7b97e5376d0b89dc06 |
|||
| msg327410 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * | Date: 2018-10-09 14:35 | |
PR merged for 3.8 branch. I don't think such a simple change deserves a backport for previous Python versions. Closing this out as resolved. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2018-10-09 14:35:41 | giampaolo.rodola | set | status: open -> closed versions: + Python 3.8 messages: + msg327410 resolution: fixed |
| 2018-10-09 14:32:01 | giampaolo.rodola | set | nosy:
+ giampaolo.rodola messages: + msg327409 |
| 2018-02-03 13:57:00 | amirjn | set | messages: + msg311554 |
| 2018-02-03 13:55:55 | amirjn | set | nosy:
+ amirjn messages: + msg311553 |
| 2018-01-26 16:10:58 | matrixise | set | nosy:
+ matrixise messages: + msg310774 |
| 2018-01-26 15:34:10 | Romuald | set | messages: + msg310766 |
| 2018-01-26 15:31:26 | Romuald | set | keywords:
+ patch stage: patch review pull_requests: + pull_request5192 |
| 2018-01-26 15:26:15 | Romuald | create | |