Skip to content

Commit 91a6e6f

Browse files
committed
Address code review
1 parent 448231f commit 91a6e6f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Lib/tempfile.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ def cleanup(self, windows=(_os.name == 'nt'), unlink=_os.unlink):
433433
try:
434434
if not self.close_called:
435435
self.close_called = True
436-
if self.file is not None:
437-
self.file.close()
436+
self.file.close()
438437
finally:
439438
# Windows provides delete-on-close as a primitive, in which
440439
# case the file was deleted by self.file.close().
@@ -448,8 +447,7 @@ def close(self):
448447
if not self.close_called:
449448
self.close_called = True
450449
try:
451-
if self.file is not None:
452-
self.file.close()
450+
self.file.close()
453451
finally:
454452
if self.delete and self.delete_on_close:
455453
self.cleanup()

Lib/urllib/error.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
an application may want to handle an exception like a regular
1111
response.
1212
"""
13-
13+
import io
1414
import urllib.response
1515

1616
__all__ = ['URLError', 'HTTPError', 'ContentTooShortError']
@@ -42,7 +42,10 @@ def __init__(self, url, code, msg, hdrs, fp):
4242
self.hdrs = hdrs
4343
self.fp = fp
4444
self.filename = url
45-
self.__super_init(fp, hdrs, url, code)
45+
if fp is not None:
46+
self.__super_init(fp, hdrs, url, code)
47+
else:
48+
self.__super_init(io.StringIO(), hdrs, url, code)
4649

4750
def __str__(self):
4851
return 'HTTP Error %s: %s' % (self.code, self.msg)

0 commit comments

Comments
 (0)