-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-41352: Raise UnsupportedOperation for FileIO.readall() in "w" mode #21568
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
base: main
Are you sure you want to change the base?
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
check self->readable added tests for FileIO.read and FileIO.readall
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 ran the tests with and without the code change. The read test passed with and without the patch, the readall test failed without and passed with. So this seems correct.
What does readall do currently on a file which was opened with "w"? Does it sometimes work?
You need to add a news entry to this PR. You can created it with this form: https://blurb-it.herokuapp.com/add_blurb Look at some merged PRs to see what they look like. |
Hi @iritkatriel. I worked with @evanWang1409 to submit this patch and can answer your questions. The
|
Lib/test/test_fileio.py
Outdated
w = os.fdopen(w, "w") | ||
w.write("hello") | ||
w.close() |
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.
Please use a with
statement.
Lib/test/test_fileio.py
Outdated
w = os.fdopen(w, "w") | ||
w.write("hello") | ||
w.close() |
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.
Please use a with
statement.
with self.assertRaises(_io.UnsupportedOperation): | ||
f.read() | ||
|
||
def testReadallWithWritingMode(self): |
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.
These new test methods have too much duplicated code.
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 (or @evanWang1409) can pull out the pipe setup into a separate method, if you would like. Otherwise I'm not sure what else is the right direction here. It's not clear what abstraction would make sense given that there are only two callers right now and this is a small test case.
Modules/_io/fileio.c
Outdated
if (!self->readable) | ||
return err_mode("reading"); |
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.
The PEP 7 style guide states that "all new C code requires braces".
Unfortunately can't checkout: My clone was up to date yesterday and local copy, not having issues with other PRs. |
The following commit authors need to sign the Contributor License Agreement: |
Signed CLA. Will come back and see if this fix is still needed. |
check self->readable
added tests for FileIO.read and FileIO.readall
https://bugs.python.org/issue41352