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

Created on 2019-06-18 15:48 by vstinner, last changed 2019-07-16 08:59 by vstinner.

Pull Requests
URL Status Linked Edit
PR 14204 closed vstinner, 2019-06-18 16:06
Messages (4)
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/
History
Date User Action Args
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