-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-37560: Add exception handler in FieldStorage cleanup #14815
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
bpo-37560: Add exception handler in FieldStorage cleanup #14815
Conversation
Lib/test/test_cgi.py
Outdated
@@ -363,6 +363,14 @@ def test_fieldstorage_as_context_manager(self): | |||
with self.assertRaisesRegex(ValueError, 'I/O operation on closed file'): | |||
fs.file.read() | |||
|
|||
def test_fieldstorage_exit_context(self): | |||
fs = cgi.FieldStorage() | |||
try: |
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 think there's a need to use try
/ except
here in the unit test.
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.
should I remove it? I was assuming it should assert the test.
ac98d55
to
c0d3bbd
Compare
self.file.close() | ||
try: | ||
self.file.close() | ||
except AttributeError: |
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 know this comes from __del__
, but can we instead check whether self.file
is None
before calling close
on it?
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 thought it was better to follow EAFP coding style rather than LBYL, do you have any consent why it should check whether self.file
is None
?
Closing as cgi module is deprecated as per PEP 594 and further no improvements or bug fixes will be made to the module. |
Add exception handler on
FieldStorage
at__exit__
methodhttps://bugs.python.org/issue37560