diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-11-23 20:12:06 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-11-23 20:12:06 (GMT) |
commit | 6787a3806ee6a85a6f21ede70c10e15a6df267c4 (patch) | |
tree | d72149a2f3a4eab3e8f288fa2a25bb1957620d91 /Lib/_pyio.py | |
parent | d41c343f28bd7631cfa866f8276673ccafb71d57 (diff) | |
download | cpython-6787a3806ee6a85a6f21ede70c10e15a6df267c4.zip cpython-6787a3806ee6a85a6f21ede70c10e15a6df267c4.tar.gz cpython-6787a3806ee6a85a6f21ede70c10e15a6df267c4.tar.bz2 |
Issue #15204: Deprecated the 'U' mode in file-like objects.
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r-- | Lib/_pyio.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 78c6dfb..d6eee79 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -62,8 +62,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, 'b' binary mode 't' text mode (default) '+' open a disk file for updating (reading and writing) - 'U' universal newline mode (for backwards compatibility; unneeded - for new code) + 'U' universal newline mode (deprecated) ========= =============================================================== The default mode is 'rt' (open for reading text). For binary random @@ -79,6 +78,10 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given. + 'U' mode is deprecated and will raise an exception in future versions + of Python. It has no effect in Python 3. Use newline to control + universal newlines mode. + buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate @@ -174,6 +177,9 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None, if "U" in modes: if creating or writing or appending: raise ValueError("can't use U and writing mode at once") + import warnings + warnings.warn("'U' mode is deprecated", + DeprecationWarning, 2) reading = True if text and binary: raise ValueError("can't have text and binary mode at once") |