classification
Title: open(): remove 'U' mode, deprecated since Python 3.3
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, miss-islington, pitrou, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2019-06-18 15:48 by vstinner, last changed 2019-10-29 09:40 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14204 closed vstinner, 2019-06-18 16:06
PR 16959 merged vstinner, 2019-10-27 15:49
PR 16972 merged vstinner, 2019-10-28 22:09
PR 16982 merged miss-islington, 2019-10-29 09:33
Messages (11)
msg345991 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-18 15:48
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 6787a3806ee6a85a6f21ede70c10e15a6df267c4
Author: Serhiy Storchaka <storchaka@gmail.com>
Date:   Sat Nov 23 22:12:06 2013 +0200

    Issue #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.
msg345995 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-18 16:07
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.
msg346219 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-06-21 14:01
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/
msg348007 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-07-16 08:59
docutils is already fixed in the development version. I requested a release:
https://sourceforge.net/p/docutils/bugs/364/
msg355479 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-27 16:17
I cited this change in the PEP 608 "Coordinated Python release".
msg355543 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-28 14:40
New changeset e471e72977c83664f13d041c78549140c86c92de by Victor Stinner in branch 'master':
bpo-37330: open() no longer accept 'U' in file mode (GH-16959)
https://github.com/python/cpython/commit/e471e72977c83664f13d041c78549140c86c92de
msg355544 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-28 14:40
Thanks for the review Serhiy ;-)
msg355573 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2019-10-28 17:28
should we backport a documentation change for this? (the deprecatedremoved says 4.0 currently)
msg355633 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-29 09:32
New changeset 1d2862a323ae1387e306942253b1e487018e2b7f by Victor Stinner in branch '3.8':
bpo-37330: open(): "U" mode is removed in Python 3.9 (GH-16972)
https://github.com/python/cpython/commit/1d2862a323ae1387e306942253b1e487018e2b7f
msg355635 - (view) Author: miss-islington (miss-islington) Date: 2019-10-29 09:38
New changeset 4cb08b6c0ae6989d169dd48c2b24087941f6d0b0 by Miss Skeleton (bot) in branch '3.7':
bpo-37330: open(): "U" mode is removed in Python 3.9 (GH-16972)
https://github.com/python/cpython/commit/4cb08b6c0ae6989d169dd48c2b24087941f6d0b0
msg355636 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-29 09:40
> should we backport a documentation change for this? (the deprecatedremoved says 4.0 currently)

Done. Thanks for the reminder.
History
Date User Action Args
2019-10-29 09:40:22vstinnersetmessages: + msg355636
2019-10-29 09:38:41miss-islingtonsetnosy: + miss-islington
messages: + msg355635
2019-10-29 09:33:08miss-islingtonsetpull_requests: + pull_request16508
2019-10-29 09:32:51vstinnersetmessages: + msg355633
2019-10-28 22:09:45vstinnersetpull_requests: + pull_request16499
2019-10-28 17:28:33Anthony Sottilesetnosy: + Anthony Sottile
messages: + msg355573
2019-10-28 14:40:57vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg355544

stage: patch review -> resolved
2019-10-28 14:40:21vstinnersetmessages: + msg355543
2019-10-27 16:17:16vstinnersetmessages: + msg355479
2019-10-27 15:49:30vstinnersetpull_requests: + pull_request16487
2019-07-16 08:59:25vstinnersetmessages: + msg348007
2019-06-21 14:01:07vstinnersetmessages: + msg346219
2019-06-18 16:07:56vstinnersetmessages: + msg345995
2019-06-18 16:07:08vstinnersetnosy: + pitrou
2019-06-18 16:06:58vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request14042
2019-06-18 15:48:25vstinnercreate