classification
Title: file accepts 'rU+' as a mode
Type: behavior Stage: commit review
Components: Interpreter Core, IO Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, amaury.forgeotdarc, benjamin.peterson, brett.cannon, haypo, jcon, jeff.balogh, pitrou
Priority: high Keywords: needs review, patch

Created on 2008-02-12 22:55 by brett.cannon, last changed 2011-07-24 03:21 by eli.bendersky.

Files
File name Uploaded Description Edit
issue2091.diff jeff.balogh, 2008-03-17 19:52 review
issue2091-2.patch jcon, 2011-06-01 00:59 Updated patch for new io review
Messages (7)
msg62343 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-02-12 22:55
The docs on file's constructor says that the 'U' mode should not work
with '+', and yet 'rU+' does not throw an error.
msg63741 - (view) Author: Jeff Balogh (jeff.balogh) * Date: 2008-03-17 19:52
Attaching a patch that checks for '+' in the mode string, updates the 
docs, and tests bad mode strings.
msg104582 - (view) Author: Tres Seaver (tseaver) Date: 2010-04-29 20:27
I can confirm that:

- the patch applies cleanly to the release26-maint branch, with the
  exception of the Misc/NEWS portion::

  $ 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).

- the added test fails before rebuilding Objects/fileobject.c::

  $ ./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

- the added test passes after rebuilding Objects/fielobject.c::

  $ 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.
msg116954 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-09-20 16:37
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.
msg116955 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-09-20 17:33
Of course, the implementation is now in the io module:
Modules/_io/_iomodule.c *and* Lib/_pyio.py
msg136425 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-05-21 09:29
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?
msg137409 - (view) Author: John O'Connor (jcon) Date: 2011-06-01 00:59
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 = 1`
History
Date User Action Args
2011-07-24 03:21:26eli.benderskysetnosy: - eli.bendersky
2011-06-01 01:00:00jconsetfiles: + issue2091-2.patch
nosy: + jcon
messages: + msg137409

2011-05-21 16:25:17tseaversetnosy: - tseaver
2011-05-21 09:29:42eli.benderskysetmessages: + msg136425
2011-05-21 08:09:23eli.benderskysetnosy: + eli.bendersky
2010-09-20 17:33:02amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg116955
2010-09-20 16:37:33BreamoreBoysetnosy: + BreamoreBoy

messages: + msg116954
versions: + Python 3.1, Python 3.2, - Python 2.6
2010-05-05 00:45:40hayposetnosy: + haypo
2010-05-02 17:17:41brett.cannonsetkeywords: + needs review
stage: patch review -> commit review
2010-04-29 20:32:51pitrousetversions: + Python 2.7, - Python 3.1
2010-04-29 20:27:41tseaversetnosy: + tseaver
messages: + msg104582
2009-04-28 00:06:45ajaksu2setnosy: + pitrou, benjamin.peterson
2009-04-28 00:06:10ajaksu2setnosy: brett.cannon, jeff.balogh
versions: + Python 3.1, - Python 2.5
components: + IO
stage: patch review
2008-03-17 19:52:40jeff.baloghsetfiles: + issue2091.diff
nosy: + jeff.balogh
messages: + msg63741
keywords: + patch
2008-02-14 20:20:49christian.heimessetpriority: high
2008-02-12 22:55:09brett.cannoncreate