Repository navigation
file accepts 'rU+' as a mode #46354
Copy link
Copy link
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
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:
assignee = None
closed_at = <Date 2015-07-25.18:45:53.834>
created_at = <Date 2008-02-12.22:55:09.244>
labels = ['interpreter-core', 'type-bug', 'expert-IO']
title = "file accepts 'rU+' as a mode"
updated_at = <Date 2019-04-27.20:39:08.758>
user = 'https://github.com/brettcannon'bugs.python.org fields:
activity = <Date 2019-04-27.20:39:08.758>
actor = 'berker.peksag'
assignee = 'none'
closed = True
closed_date = <Date 2015-07-25.18:45:53.834>
closer = 'rbcollins'
components = ['Interpreter Core', 'IO']
creation = <Date 2008-02-12.22:55:09.244>
creator = 'brett.cannon'
dependencies = []
files = ['9697', '22217', '39980']
hgrepos = []
issue_num = 2091
keywords = ['patch', 'needs review']
message_count = 19.0
messages = ['62343', '63741', '104582', '116954', '116955', '136425', '137409', '223368', '223810', '247133', '247193', '247212', '247215', '247334', '247365', '247366', '247370', '341010', '341013']
nosy_count = 14.0
nosy_names = ['brett.cannon', 'amaury.forgeotdarc', 'pitrou', 'vstinner', 'larry', 'rbcollins', 'benjamin.peterson', 'jeff.balogh', 'r.david.murray', 'python-dev', 'jcon', 'francismb', 'berker.peksag', 'serhiy.storchaka']
pr_nums = ['12987', '12988']
priority = 'high'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue2091'
versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
brettcannon commentedon Feb 12, 2008
The docs on file's constructor says that the 'U' mode should not work
with '+', and yet 'rU+' does not throw an error.
jeffbalogh commentedon Mar 17, 2008
Attaching a patch that checks for '+' in the mode string, updates the
docs, and tests bad mode strings.
tseaver commentedon Apr 29, 2010
I can confirm that:
exception of the Misc/NEWS portion::
$ ./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.BreamoreBoy commentedon Sep 20, 2010
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.
amauryfa commentedon Sep 20, 2010
Of course, the implementation is now in the io module:
Modules/_io/_iomodule.c *and* Lib/_pyio.py
elibendersky commentedon May 21, 2011
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?
jcon commentedon Jun 1, 2011
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
reading = 1francismb commentedon Jul 17, 2014
Shouldn't be some deprecation warning somewhere?
serhiy-storchaka commentedon Jul 24, 2014
In Python 3.4+ 'U' already emits deprecation warning.
rbtcollins commentedon Jul 22, 2015
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.
bitdancer commentedon Jul 23, 2015
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.
rbtcollins commentedon Jul 23, 2015
@larry - should this go in 3.5, or would you rather it not?
serhiy-storchaka commentedon Jul 23, 2015
I would add a warning in 3.4- (or 3.5-). The 'U' mode should not work
with '+', and it can't work with '+' correctly. This is a bug that we can decide not fix by raising an exception.
larryhastings commentedon Jul 25, 2015
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.
python-dev commentedon Jul 25, 2015
New changeset 1a5bbb31f740 by Robert Collins in branch 'default':
https://hg.python.org/cpython/rev/1a5bbb31f740
rbtcollins commentedon Jul 25, 2015
@larry thanks - that was my inclination too. Applied to 3.6
@serhiy I've not done a warning in 3.4/3.5 because - the behaviour is already broken, this patch just catches it a lot earlier (on open rather than subsequent operations).
serhiy-storchaka commentedon Jul 25, 2015
Perhaps the 'U' mode should just raise an exception in 3.6.
berkerpeksag commentedon Apr 27, 2019
New changeset 21a9ba1 by Berker Peksag in branch 'master':
bpo-2091: Fix typo in exception message (GH-12987)
21a9ba1
berkerpeksag commentedon Apr 27, 2019
New changeset f5972cc by Berker Peksag (Miss Islington (bot)) in branch '3.7':
bpo-2091: Fix typo in exception message (GH-12987)
f5972cc