Skip to content

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

Conversation

nsiregar
Copy link
Contributor

@nsiregar nsiregar commented Jul 17, 2019

Add exception handler on FieldStorage at __exit__ method

https://bugs.python.org/issue37560

@@ -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:
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@nsiregar nsiregar force-pushed the bpo-37560-exception-handler-exit-field-storage branch from ac98d55 to c0d3bbd Compare July 17, 2019 16:13
self.file.close()
try:
self.file.close()
except AttributeError:
Copy link
Contributor

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?

Copy link
Contributor Author

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?

@kumaraditya303
Copy link
Contributor

Closing as cgi module is deprecated as per PEP 594 and further no improvements or bug fixes will be made to the module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants