Skip to content

open(): remove 'U' mode, deprecated since Python 3.3 #81511

Closed

Description

@vstinner
BPO 37330
Nosy @pitrou, @vstinner, @merwok, @ambv, @serhiy-storchaka, @asottile, @miss-islington, @abartlet
PRs
  • bpo-37330: open() no longer accept 'U' in file mode #14204
  • bpo-37330: open() no longer accept 'U' in file mode #16959
  • [3.8] bpo-37330: open(): "U" mode is removed in Python 3.9 #16972
  • [3.7] bpo-37330: open(): "U" mode is removed in Python 3.9 (GH-16972) #16982
  • bpo-39674: Revert "bpo-37330: open() no longer accept 'U' in file mode (GH-16959)" #18767
  • bpo-37330: open() no longer accept 'U' in file mode #28118
  • 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 2021-09-02.11:16:54.115>
    created_at = <Date 2019-06-18.15:48:25.669>
    labels = ['library', '3.11']
    title = "open(): remove 'U' mode, deprecated since Python 3.3"
    updated_at = <Date 2022-01-05.17:46:12.863>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2022-01-05.17:46:12.863>
    actor = 'eric.araujo'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-09-02.11:16:54.115>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2019-06-18.15:48:25.669>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37330
    keywords = ['patch']
    message_count = 25.0
    messages = ['345991', '345995', '346219', '348007', '355479', '355543', '355544', '355573', '355633', '355635', '355636', '362362', '363194', '363211', '363247', '363320', '363321', '363344', '363366', '400884', '400888', '400889', '400914', '400917', '409791']
    nosy_count = 8.0
    nosy_names = ['pitrou', 'vstinner', 'eric.araujo', 'lukasz.langa', 'serhiy.storchaka', 'Anthony Sottile', 'miss-islington', 'abartlet']
    pr_nums = ['14204', '16959', '16972', '16982', '18767', '28118']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue37330'
    versions = ['Python 3.11']

    Activity

    1. vstinner commented on Jun 18, 2019

      @vstinner
      MemberAuthor

      The builtin open() function accepts 'U' in the file mode, but it emits a DeprecationWarning since Python 3.4, change made in bpo-15204:

      commit 6787a38
      Author: Serhiy Storchaka <storchaka@gmail.com>
      Date: Sat Nov 23 22:12:06 2013 +0200

      Issue bpo-15204: Deprecated the 'U' mode in file-like objects.
      
      $ cat x.py 
      f = open(__file__, 'U')
      line = f.readline()
      print(type(line))
      f.close()
      
      $ python3.7 x.py 
      x.py:1: DeprecationWarning: 'U' mode is deprecated
        f = open(__file__, 'U')
      <class 'str'>

      The 'U' mode is documented as deprecated since Python 3.3

      The flag is basically only there for backward compatibility with Python 2. Python 3.9.0 final release is currently scheduled at 2020-06-08: 6 months after Python 2 end-of-life (2020-01-01).

      Currently, the 'U' mode is documented as it will be removed from Python 4.0. But I dislike having a bunch of backward incompatible changes in Python 4.0. I would prefer Python 4.0 to be simply the version after Python 3.X.

      Deprecation warnings are now displayed in the __main__ module by default, thanks to the PEP-565 -- Show DeprecationWarning in __main__.
      https://www.python.org/dev/peps/pep-0565/

      More and more projects run their test suite using -Werror and so have to fix deprecation warnings.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Jun 18, 2019
    3. vstinner commented on Jun 18, 2019

      @vstinner
      MemberAuthor

      I prefer to push backward incompatible changes at the beginning of a dev cycle (Python 3.9), so we have room to revert it later if it causes too much trouble.

    4. vstinner commented on Jun 21, 2019

      @vstinner
      MemberAuthor

      I reported the issue to docutils. In fact, docutils FileInput class was already fixed to prevent the deprecation warning, but there was no release yet:
      https://sourceforge.net/p/docutils/bugs/363/

    5. vstinner commented on Jul 16, 2019

      @vstinner
      MemberAuthor

      docutils is already fixed in the development version. I requested a release:
      https://sourceforge.net/p/docutils/bugs/364/

    6. vstinner commented on Oct 27, 2019

      @vstinner
      MemberAuthor

      I cited this change in the PEP-608 "Coordinated Python release".

    7. vstinner commented on Oct 28, 2019

      @vstinner
      MemberAuthor

      New changeset e471e72 by Victor Stinner in branch 'master':
      bpo-37330: open() no longer accept 'U' in file mode (GH-16959)
      e471e72

    8. vstinner commented on Oct 28, 2019

      @vstinner
      MemberAuthor

      Thanks for the review Serhiy ;-)

    9. asottile commented on Oct 28, 2019

      asottilemannequin
      Mannequin

      should we backport a documentation change for this? (the deprecatedremoved says 4.0 currently)

    10. vstinner commented on Oct 29, 2019

      @vstinner
      MemberAuthor

      New changeset 1d2862a by Victor Stinner in branch '3.8':
      bpo-37330: open(): "U" mode is removed in Python 3.9 (GH-16972)
      1d2862a

    11. miss-islington commented on Oct 29, 2019

      @miss-islington
      Contributor

      New changeset 4cb08b6 by Miss Skeleton (bot) in branch '3.7':
      bpo-37330: open(): "U" mode is removed in Python 3.9 (GH-16972)
      4cb08b6

    12. vstinner commented on Oct 29, 2019

      @vstinner
      MemberAuthor

      should we backport a documentation change for this? (the deprecatedremoved says 4.0 currently)

      Done. Thanks for the reminder.

    13. abartlet commented on Feb 20, 2020

      abartletmannequin
      Mannequin

      This breaks Samba's build:

      https://bugzilla.samba.org/show_bug.cgi?id=14266

      While we are of course able to patch new versions of Samba, this will make it harder to bisect back though Samba history. It would be really great if this kind of change could be reverted or at least deferred so Samba can rely on a stable language platform for it's build system.

    14. 6 remaining items

    15. vstinner commented on Mar 4, 2020

      @vstinner
      MemberAuthor

      New changeset 942f7a2 by Victor Stinner in branch 'master':
      bpo-39674: Revert "bpo-37330: open() no longer accept 'U' in file mode (GH-16959)" (GH-18767)
      942f7a2

    16. vstinner commented on Sep 1, 2021

      @vstinner
      MemberAuthor

      I reopen the issue. I created PR 28118 to try again to remove the "U" mode in Python 3.11.

    17. added
      3.11only security fixes
      and removed on Sep 1, 2021
    18. vstinner commented on Sep 2, 2021

      @vstinner
      MemberAuthor

      This breaks Samba's build:
      https://bugzilla.samba.org/show_bug.cgi?id=14266

      Samba has been updated in the meanwhile, buildtools/wafsamba/samba_utils.py:

      •            function_code = node.read('rU', None)
        

      + function_code = node.read('r', None)

      https://github.com/samba-team/samba/blob/1209c89dcf6371bbfa4f3929a47a573ef2916c1a/buildtools/wafsamba/samba_utils.py#L692

    19. vstinner commented on Sep 2, 2021

      @vstinner
      MemberAuthor

      docutils is already fixed in the development version. I requested a release: https://sourceforge.net/p/docutils/bugs/364/

      At 2019-07-22, Günter Milde wrote: "Docutils 0.15 is released" (with the fix). The latest docutils version is 0.17.1.

    20. ambv commented on Sep 2, 2021

      @ambv
      Contributor

      New changeset 19ba212 by Victor Stinner in branch 'main':
      bpo-37330: open() no longer accept 'U' in file mode (GH-28118)
      19ba212

    21. vstinner commented on Sep 2, 2021

      @vstinner
      MemberAuthor

      Let's see how it goes. In the worst case, we have time before Python 3.11 final to revert it one more time.

    22. merwok commented on Jan 5, 2022

      @merwok
      Member

      it is useful to build old versions, sometimes 7 year old versions, to confirm if/when the behaviour regressed.

      I think the sticking point is this: it is not expected that old versions should work as-is with the newest Python. Can you do your build and test with the Python version that was current 7 years ago?

    23. transferred this issue fromon Apr 10, 2022
    24. added a commit that references this issue on May 21, 2024
    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

      3.11only security fixesstdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions