Issue 32680: smtplib SMTP instances missing a default sock attribute (original) (raw)

Created on 2018-01-26 15:26 by Romuald, last changed 2022-04-11 14:58 by admin. 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) * (Python committer) 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
apple.com
msg327409 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) 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) * (Python committer) 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
2022-04-11 14:58:57 admin set github: 76861
2018-10-09 14:35:41 giampaolo.rodola set status: open -> closedversions: + Python 3.8messages: + resolution: fixedstage: patch review -> resolved
2018-10-09 14:32:01 giampaolo.rodola set nosy: + giampaolo.rodolamessages: +
2018-02-03 13:57:00 amirjn set messages: +
2018-02-03 13:55:55 amirjn set nosy: + amirjnmessages: +
2018-01-26 16:10:58 matrixise set nosy: + matrixisemessages: +
2018-01-26 15:34:10 Romuald set messages: +
2018-01-26 15:31:26 Romuald set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest5192>
2018-01-26 15:26:15 Romuald create