Skip to content

Commit ca62e2e

Browse files
committed
Deprecate "U" mode passed to cbook.to_filehandle().
It has had no effect ever since transition to Py3, and the corresponding feature in open() is being removed in cpython 3.9.
1 parent 1e9c794 commit ca62e2e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ with locator classes defined in :mod:`matplotlib.ticker`.
3535
``backend_pgf.LatexManager.latex`` is now created with ``encoding="utf-8"``, so
3636
its ``stdin`` attribute is already utf8-encoded; the ``latex_stdin_utf8``
3737
attribute is thus deprecated.
38+
39+
Flags containing "U" passed to `.cbook.to_filehandle` and `.cbook.open_file_cm`
40+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41+
Please remove "U" from flags passed to `.cbook.to_filehandle` and
42+
`.cbook.open_file_cm`. This is consistent with their removal from `open` in
43+
Python 3.9.

lib/matplotlib/cbook/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,18 @@ def to_filehandle(fname, flag='r', return_opened=False, encoding=None):
427427
"""
428428
if isinstance(fname, os.PathLike):
429429
fname = os.fspath(fname)
430+
if "U" in flag:
431+
warn_deprecated("3.3", message="Passing a flag containing 'U' to "
432+
"to_filehandle() is deprecated since %(since)s and "
433+
"will be removed %(removal)s.")
434+
flag = flag.replace("U", "")
430435
if isinstance(fname, str):
431436
if fname.endswith('.gz'):
432-
# get rid of 'U' in flag for gzipped files.
433-
flag = flag.replace('U', '')
434437
fh = gzip.open(fname, flag)
435438
elif fname.endswith('.bz2'):
436439
# python may not be complied with bz2 support,
437440
# bury import until we need it
438441
import bz2
439-
# get rid of 'U' in flag for bz2 files
440-
flag = flag.replace('U', '')
441442
fh = bz2.BZ2File(fname, flag)
442443
else:
443444
fh = open(fname, flag, encoding=encoding)

0 commit comments

Comments
 (0)