Skip to content

file accepts 'rU+' as a mode #46354

Closed
Closed

Description

@brettcannon
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']

    Activity

    1. brettcannon commented on Feb 12, 2008

      @brettcannon
      MemberAuthor

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

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-bugAn unexpected behavior, bug, or error
      on Feb 12, 2008
    3. jeffbalogh commented on Mar 17, 2008

      jeffbaloghmannequin
      Mannequin

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

    4. tseaver commented on Apr 29, 2010

      @tseaver

      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.
    5. BreamoreBoy commented on Sep 20, 2010

      BreamoreBoymannequin
      Mannequin

      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.

    6. amauryfa commented on Sep 20, 2010

      @amauryfa
      Contributor

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

    7. elibendersky commented on May 21, 2011

      elibenderskymannequin
      Mannequin

      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?

    8. jcon commented on Jun 1, 2011

      jconmannequin
      Mannequin

      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

    9. francismb commented on Jul 17, 2014

      francismbmannequin
      Mannequin

      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?

    10. serhiy-storchaka commented on Jul 24, 2014

      @serhiy-storchaka
      Member

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

    11. rbtcollins commented on Jul 22, 2015

      @rbtcollins
      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.

    12. bitdancer commented on Jul 23, 2015

      @bitdancer
      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.

    13. rbtcollins commented on Jul 23, 2015

      @rbtcollins
      Member

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

    14. serhiy-storchaka commented on Jul 23, 2015

      @serhiy-storchaka
      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.

    15. larryhastings commented on Jul 25, 2015

      @larryhastings
      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.

    16. python-dev commented on Jul 25, 2015

      python-devmannequin
      Mannequin

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

    17. rbtcollins commented on Jul 25, 2015

      @rbtcollins
      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).

    18. serhiy-storchaka commented on Jul 25, 2015

      @serhiy-storchaka
      Member

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

    19. berkerpeksag commented on Apr 27, 2019

      @berkerpeksag
      Member

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

    20. berkerpeksag commented on Apr 27, 2019

      @berkerpeksag
      Member

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

    21. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-IOtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions