8000 Deprecate the 'warn' parameter to matplotlib.use(). · matplotlib/matplotlib@3249152 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3249152

Browse files
committed
Deprecate the 'warn' parameter to matplotlib.use().
Right now, the only case where the 'warn' parameter to use() has an observable effect is if the user calls `use(some_backend, warn=True, force=False)` (the default is `warn=False, force=True`) and `some_backend` cannot be switched to. If they really want a warning in that case and not an exception (why?), they can just do ``` try: use(some_backend) except ImportError: warnings.warn(...) ``` instead. Given the non-obvious interaction between `warn` and `force`, just deprecate `warn`. We could even deprecate `force` and tell user to catch ImportErrors if they know a switch can fail and that they want to silently ignore the switch failure, but I guess someone will complain that `use(some_backend, force=False)` is so much shorter to write than ``` try: use(some_backend) except ImportError: pass ``` ...
1 parent 40583b0 commit 3249152

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Deprecations
2+
````````````
3+
4+
The ``warn`` parameter to `matplotlib.use()` is deprecated (catch the
5+
`ImportError` emitted on backend switch failure and reemit a warning yourself
6+
if so desired).

lib/matplotlib/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,7 @@ def __exit__(self, exc_type, exc_value, exc_tb):
12271227

12281228

12291229
@cbook._rename_parameter("3.1", "arg", "backend")
1230+
@cbook._delete_parameter("3.1", "warn")
12301231
def use(backend, warn=False, force=True):
12311232
"""
12321233
Select the backend used for rendering and GUI integration.
@@ -1249,7 +1250,7 @@ def use(backend, warn=False, force=True):
12491250
12501251
warn : bool, optional, default: False
12511252
If True and not *force*, emit a warning if a failure-to-switch
1252-
`ImportError` has been suppressed.
1253+
`ImportError` has been suppressed. This parameter is deprecated.
12531254
12541255
force : bool, optional, default: True
12551256
If True (the default), raise an `ImportError` if the backend cannot be

lib/matplotlib/testing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def setup():
5050
"Could not set locale to English/United States. "
5151
"Some date-related tests may fail.")
5252

53-
mpl.use('Agg', force=True, warn=False) # use Agg backend for these tests
53+
mpl.use('Agg')
5454

5555
with cbook._suppress_matplotlib_deprecation_warning():
5656
mpl.rcdefaults() # Start with all defaults

0 commit comments

Comments
 (0)
0