From b71304c03bdecc5304cdbdd06beee5642e2dfded Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 25 May 2018 02:21:22 -0700 Subject: [PATCH] Don't recurse in to_filehandle for PathLikes. --- lib/matplotlib/cbook/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index cd2177e75f6b..c722819765c5 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -452,9 +452,7 @@ def to_filehandle(fname, flag='rU', return_opened=False, encoding=None): read/write flag for :func:`file` """ if isinstance(fname, getattr(os, "PathLike", ())): - return to_filehandle( - os.fspath(fname), - flag=flag, return_opened=return_opened, encoding=encoding) + fname = os.fspath(fname) if isinstance(fname, str): if fname.endswith('.gz'): # get rid of 'U' in flag for gzipped files.