Skip to content
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

Closed
brettcannon opened this issue Feb 12, 2008 · 19 comments
Closed

file accepts 'rU+' as a mode #46354

brettcannon opened this issue Feb 12, 2008 · 19 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-IO type-bug An unexpected behavior, bug, or error

Comments

@brettcannon
Copy link
Member

BPO 2091
Nosy @brettcannon, @amauryfa, @pitrou, @vstinner, @larryhastings, @rbtcollins, @benjaminp, @bitdancer, @berkerpeksag, @serhiy-storchaka
PRs
  • bpo-2091: Fix typo in exception message #12987
  • [3.7] bpo-2091: Fix typo in exception message (GH-12987) #12988
  • Files
  • issue2091.diff
  • issue2091-2.patch: Updated patch for new io
  • issue2091-3.patch
  • 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']

    @brettcannon
    Copy link
    Member Author

    The docs on file's constructor says that the 'U' mode should not work
    with '+', and yet 'rU+' does not throw an error.

    @brettcannon brettcannon added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Feb 12, 2008
    @jeffbalogh
    Copy link
    Mannequin

    jeffbalogh mannequin commented Mar 17, 2008

    Attaching a patch that checks for '+' in the mode string, updates the
    docs, and tests bad mode strings.

    @devdanzin devdanzin mannequin added the topic-IO label Apr 28, 2009
    @tseaver
    Copy link

    tseaver commented Apr 29, 2010

    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).
      $ ./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
    Copy link
    Mannequin

    BreamoreBoy mannequin commented 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
    Copy link
    Member

    Of course, the implementation is now in the io module:
    Modules/_io/_iomodule.c *and* Lib/_pyio.py

    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented 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
    Copy link
    Mannequin

    jcon mannequin commented 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 = 1

    @francismb
    Copy link
    Mannequin

    francismb mannequin commented Jul 17, 2014

    On the other hand, the documentation *does* mention that
    'U' is for backwards compatibility and shouldn't be used
    with new code.

    Shouldn't be some deprecation warning somewhere?

    @serhiy-storchaka
    Copy link
    Member

    In Python 3.4+ 'U' already emits deprecation warning.

    @rbtcollins
    Copy link
    Member

    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
    Copy link
    Member

    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
    Copy link
    Member

    @larry - should this go in 3.5, or would you rather it not?

    @serhiy-storchaka
    Copy link
    Member

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

    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
    Copy link
    Mannequin

    python-dev mannequin commented Jul 25, 2015

    New changeset 1a5bbb31f740 by Robert Collins in branch 'default':

    @rbtcollins
    Copy link
    Member

    @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
    Copy link
    Member

    Perhaps the 'U' mode should just raise an exception in 3.6.

    @berkerpeksag
    Copy link
    Member

    New changeset 21a9ba1 by Berker Peksag in branch 'master':
    bpo-2091: Fix typo in exception message (GH-12987)
    21a9ba1

    @berkerpeksag
    Copy link
    Member

    New changeset f5972cc by Berker Peksag (Miss Islington (bot)) in branch '3.7':
    bpo-2091: Fix typo in exception message (GH-12987)
    f5972cc

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-IO type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    8 participants