Stéphane Wirtel <steph...@wirtel.be> added the comment: 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. ---------- nosy: +matrixise _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32680> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com