From 5780fe7d7525dfb9caa40db4b8e31319ed110619 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 4 Mar 2018 01:31:03 -0800 Subject: [PATCH] Deprecation fixes. 1) don't import matplotlib.compat.subprocess in `__init__` (as that triggers a deprecation warning). 2) using stacklevel=2 for warn_deprecated as default is not necessarily always sufficient, but will definitely be better than stacklevel=1 as default... (see https://docs.python.org/3/library/warnings.html#warnings.warn). --- lib/matplotlib/__init__.py | 1 - lib/matplotlib/backends/backend_agg.py | 3 +-- lib/matplotlib/cbook/deprecation.py | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 99a6dcc4b15a..22d5d6e078e1 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -142,7 +142,6 @@ from . import cbook from matplotlib.cbook import ( mplDeprecation, dedent, get_label, sanitize_sequence) -from matplotlib.compat import subprocess from matplotlib.rcsetup import defaultParams, validate_backend, cycler import numpy diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.py index 82b724cc8b53..5988abbf74e5 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -589,8 +589,7 @@ def print_tif(self, filename_or_obj, *args, **kwargs): return image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1) dpi = (self.figure.dpi, self.figure.dpi) - return image.save(filename_or_obj, format='tiff', - dpi=dpi) + return image.save(filename_or_obj, format='tiff', dpi=dpi) print_tiff = print_tif diff --git a/lib/matplotlib/cbook/deprecation.py b/lib/matplotlib/cbook/deprecation.py index ca7ae333f272..35c7de50d0f9 100644 --- a/lib/matplotlib/cbook/deprecation.py +++ b/lib/matplotlib/cbook/deprecation.py @@ -103,8 +103,7 @@ def warn_deprecated( """ message = _generate_deprecation_message( since, message, name, alternative, pending, obj_type) - - warnings.warn(message, mplDeprecation, stacklevel=1) + warnings.warn(message, mplDeprecation, stacklevel=2) def deprecated(since, message='', name='', alternative='', pending=False,