-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
file accepts 'rU+' as a mode #46354
Comments
The docs on file's constructor says that the 'U' mode should not work |
Attaching a patch that checks for '+' in the mode string, updates the |
I can confirm that:
$ hg branch
release26-maint
$ ./python -E -tt Lib/test/regrtest.py test_file
test_file
1 test OK.
$ patch -p0 < /tmp/issue2091.diff
patching file Objects/fileobject.c
Hunk #1 succeeded at 209 (offset 54 lines).
Hunk #2 succeeded at 2269 (offset 194 lines).
patching file Misc/NEWS
Hunk #1 FAILED at 12.
1 out of 1 hunk FAILED -- saving rejects to file Misc/NEWS.rej
patching file Lib/test/test_file.py
Hunk #1 succeeded at 176 (offset 55 lines).
$ ./python -E -tt Lib/test/regrtest.py test_file
test_file
test test_file failed -- Traceback (most recent call last):
File "/home/tseaver/projects/hg-repo/py-2.6/Lib/test/test_file.py", line 181, in testModeStrings
f = open(TESTFN, mode)
IOError: [Errno 2] No such file or directory: '@test'
1 test failed:
test_file
$ make
gcc -pthread -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -DPy_BUILD_CORE -o Objects/fileobject.o Objects/fileobject.c
...
$ ./python -E -tt Lib/test/regrtest.py test_file
test_file
1 test OK. |
The patch is now way out of date to the extent that I can't find the code in fileobject.c, perhaps I'm just blind Can someone please provide a new patch, thanks. |
Of course, the implementation is now in the io module: |
In Python 3, the documentation no longer mentions that 'U' should not work with '+' (or 'w' or 'a', for that matter), and the code throws ValueError if 'U' is used with 'w' or 'a', but not '+'. On the other hand, the documentation *does* mention that 'U' is for backwards compatibility and shouldn't be used with new code. In light of this, how do you suggest to proceed with this issue? |
It seems to me that adding the proper check is a good idea. It also may not be obvious to some that 'U' is now more or less an alias for 'r'. I have updated the patch so that it at least applies. I also removed a redundant |
Shouldn't be some deprecation warning somewhere? |
In Python 3.4+ 'U' already emits deprecation warning. |
Updated patch. I'm not going to apply right now - giving it a little time to let folk chime on whether this should be applied all the way back to 3.4, or not. My inclination is to only apply it to 3.6. |
I agree, a change that emits an error where none was emitted before should only go in the next release. With a what's new entry. It is possible there should be a deprecation or -3 warning in 2.7, but I'm not sure it is worth the effort. |
@larry - should this go in 3.5, or would you rather it not? |
I would add a warning in 3.4- (or 3.5-). The 'U' mode should not work |
Yeah, considering how long this bug has been sitting around, I think we can wait for one more release for the fix. 3.6 please. |
New changeset 1a5bbb31f740 by Robert Collins in branch 'default':
|
Perhaps the 'U' mode should just raise an exception in 3.6. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: