8000 Remove 3.3 deprecations in cbook. · matplotlib/matplotlib@7286e9b · GitHub
[go: up one dir, main page]

Skip to content

Commit 7286e9b

Browse files
committed
Remove 3.3 deprecations in cbook.
1 parent 876415d commit 7286e9b

File tree

4 files changed

+19
-135
lines changed

4 files changed

+19
-135
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Removal of ``cbook`` deprecations
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
* ``local_over_kwdict`` has been removed; use `.cbook.normalize_kwargs`
5+
instead.
6+
* *required*, *forbidden* and *allowed* parameters of `.cbook.normalize_kwargs`
7+
have been removed.
8+
* Flags containing "U" passed to `.cbook.to_filehandle` and
9+
`.cbook.open_file_cm` are no longer accepted. This is consistent with their
10+
removal from `open` in Python 3.9.

lib/matplotlib/cbook/__init__.py

Lines changed: 7 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -315,54 +315,6 @@ def __repr__(self):
315315
return "<an empty list>"
316316

317317

318-
@_api.deprecated("3.3")
319-
class IgnoredKeywordWarning(UserWarning):
320-
"""
321-
A class for issuing warnings about keyword arguments that will be ignored
322-
by Matplotlib.
323-
"""
324-
pass
325-
326-
327-
@_api.deprecated("3.3", alternative="normalize_kwargs")
328-
def local_over_kwdict(local_var, kwargs, *keys):
329-
"""
330-
Enforces the priority of a local variable over potentially conflicting
331-
argument(s) from a kwargs dict. The following possible output values are
332-
considered in order of priority::
333-
334-
local_var > kwargs[keys[0]] > ... > kwargs[keys[-1]]
335-
336-
The first of these whose value is not None will be returned. If all are
337-
None then None will be returned. Each key in keys will be removed from the
338-
kwargs dict in place.
339-
340-
Parameters
341-
----------
342-
local_var : any object
343-
The local variable (highest priority).
344-
345-
kwargs : dict
346-
Dictionary of keyword arguments; modified in place.
347-
348-
*keys : str(s)
349-
Name(s) of keyword arguments to process, in descending order of
350-
priority.
351-
352-
Returns
353-
-------
354-
any object
355-
Either local_var or one of kwargs[key] for key in keys.
356-
357-
Raises
358-
------
359-
IgnoredKeywordWarning
360-
For each key in keys that is removed from kwargs but not used as
361-
the output value.
362-
"""
363-
return _local_over_kwdict(local_var, kwargs, *keys, IgnoredKeywordWarning)
364-
365-
366318
def _local_over_kwdict(
367319
local_var, kwargs, *keys, warning_cls=MatplotlibDeprecationWarning):
368320
out = local_var
@@ -449,11 +401,6 @@ def to_filehandle(fname, flag='r', return_opened=False, encoding=None):
449401
"""
450402
if isinstance(fname, os.PathLike):
451403
fname = os.fspath(fname)
452-
if "U" in flag:
453-
_api.warn_deprecated(
454-
"3.3", message="Passing a flag containing 'U' to to_filehandle() "
455-
"is deprecated since %(since)s and will be removed %(removal)s.")
456-
flag = flag.replace("U", "")
457404
if isinstance(fname, str):
458405
if fname.endswith('.gz'):
459406
fh = gzip.open(fname, flag)
@@ -555,15 +502,6 @@ def flatten(seq, scalarp=is_scalar_or_string):
555502
yield from flatten(item, scalarp)
556503

557504

558-
@_api.deprecated("3.3", alternative="os.path.realpath and os.stat")
559-
@functools.lru_cache()
560-
def get_realpath_and_stat(path):
561-
realpath = os.path.realpath(path)
562-
st 1E0A at = os.stat(realpath)
563-
stat_key = (stat.st_ino, stat.st_dev)
564-
return realpath, stat_key
565-
566-
567505
class maxdict(dict):
568506
"""
569507
A dictionary with a maximum size.
@@ -1711,24 +1649,10 @@ def sanitize_sequence(data):
17111649
else data)
17121650

17131651

1714-
@_api.delete_parameter("3.3", "required")
1715-
@_api.delete_parameter("3.3", "forbidden")
1716-
@_api.delete_parameter("3.3", "allowed")
1717-
def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
1718-
allowed=None):
1652+
def normalize_kwargs(kw, alias_mapping=None):
17191653
"""
17201654
Helper function to normalize kwarg inputs.
17211655
1722-
The order they are resolved are:
1723-
1724-
1. aliasing
1725-
2. required
1726-
3. forbidden
1727-
4. allowed
1728-
1729-
This order means that only the canonical names need appear in
1730-
*allowed*, *forbidden*, *required*.
1731-
17321656
Parameters
17331657
----------
17341658
kw : dict or None
@@ -1737,32 +1661,20 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
17371661
the form ``props=None``.
17381662
17391663
alias_mapping : dict or Artist subclass or Artist instance, optional
1740-
A mapping between a canonical name to a list of
1741-
aliases, in order of precedence from lowest to highest.
1664+
A mapping between a canonical name to a list of aliases, in order of
1665+
precedence from lowest to highest.
17421666
1743-
If the canonical value is not in the list it is assumed to have
1744-
the highest priority.
1667+
If the canonical value is not in the list it is assumed to have the
1668+
highest priority.
17451669
17461670
If an Artist subclass or instance is passed, use its properties alias
17471671
mapping.
17481672
1749-
required : list of str, optional
1750-
A list of keys that must be in *kws*. This parameter is deprecated.
1751-
1752-
forbidden : list of str, optional
1753-
A list of keys which may not be in *kw*. This parameter is deprecated.
1754-
1755-
allowed : list of str, optional
1756-
A list of allowed fields. If this not None, then raise if
1757-
*kw* contains any keys not in the union of *required*
1758-
and *allowed*. To allow only the required fields pass in
1759-
an empty tuple ``allowed=()``. This parameter is deprecated.
1760-
17611673
Raises
17621674
------
17631675
TypeError
1764-
To match what python raises if invalid args/kwargs are passed to
1765-
a callable.
1676+
To match what Python raises if invalid arguments/keyword arguments are
1677+
passed to a callable.
17661678
"""
17671679
from matplotlib.artist import Artist
17681680

@@ -1790,25 +1702,6 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
17901702
canonical_to_seen[canonical] = k
17911703
ret[canonical] = v
17921704

1793-
fail_keys = [k for k in required if k not in ret]
1794-
if fail_keys:
1795-
raise TypeError("The required keys {keys!r} "
1796-
"are not in kwargs".format(keys=fail_keys))
1797-
1798-
fail_keys = [k for k in forbidden if k in ret]
1799-
if fail_keys:
1800-
raise TypeError("The forbidden keys {keys!r} "
1801-
"are in kwargs".format(keys=fail_keys))
1802-
1803-
if allowed is not None:
1804-
allowed_set = {*required, *allowed}
1805-
fail_keys = [k for k in ret if k not in allowed_set]
1806-
if fail_keys:
1807-
raise TypeError(
1808-
"kwargs c 10000 ontains {keys!r} which are not in the required "
1809-
"{req!r} or allowed {allow!r} keys".format(
1810-
keys=fail_keys, req=required, allow=allowed))
1811-
18121705
return ret
18131706

18141707

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4086,8 +4086,8 @@ def test_eventplot_colors(colors):
40864086
def test_eventplot_problem_kwargs(recwarn):
40874087
"""
40884088
test that 'singular' versions of LineCollection props raise an
4089-
IgnoredKeywordWarning rather than overriding the 'plural' versions (e.g.
4090-
to prevent 'color' from overriding 'colors', see issue #4297)
4089+
MatplotlibDeprecationWarning rather than overriding the 'plural' versions
4090+
(e.g., to prevent 'color' from overriding 'colors', see issue #4297)
40914091
"""
40924092
np.random.seed(0)
40934093

@@ -4106,7 +4106,6 @@ def test_eventplot_problem_kwargs(recwarn):
41064106
linestyles=['solid', 'dashed'],
41074107
linestyle=['dashdot', 'dotted'])
41084108

4109-
# check that three IgnoredKeywordWarnings were raised
41104109
assert len(recwarn) == 3
41114110
assert all(issubclass(wi.category, MatplotlibDeprecationWarning)
41124111
for wi in recwarn)

lib/matplotlib/tests/test_cbook.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -374,32 +374,14 @@ def test_sanitize_sequence():
374374

375375

376376
fail_mapping = (
377-
({'a': 1}, {'forbidden': ('a')}),
378-
({'a': 1}, {'required': ('b')}),
379-
({'a': 1, 'b': 2}, {'required': ('a'), 'allowed': ()}),
380377
({'a': 1, 'b': 2}, {'alias_mapping': {'a': ['b']}}),
381-
({'a': 1, 'b': 2}, {'alias_mapping': {'a': ['b']}, 'allowed': ('a',)}),
382378
({'a': 1, 'b': 2}, {'alias_mapping': {'a': ['a', 'b']}}),
383-
({'a': 1, 'b': 2, 'c': 3},
384-
{'alias_mapping': {'a': ['b']}, 'required': ('a', )}),
385379
)
386380

387381
pass_mapping = (
388382
(None, {}, {}),
389383
({'a': 1, 'b': 2}, {'a': 1, 'b': 2}, {}),
390384
({'b': 2}, {'a': 2}, {'alias_mapping': {'a': ['a', 'b']}}),
391-
({'b': 2}, {'a': 2},
392-
{'alias_mapping': {'a': ['b']}, 'forbidden': ('b', )}),
393-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3},
394-
{'required': ('a', ), 'allowed': ('c', )}),
395-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3},
396-
{'required': ('a', 'c'), 'allowed': ('c', )}),
397-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3},
398-
{'required': ('a', 'c'), 'allowed': ('a', 'c')}),
399-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3},
400-
{'required': ('a', 'c'), 'allowed': ()}),
401-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3}, {'required': ('a', 'c')}),
402-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3}, {'allowed': ('a', 'c')}),
403385
)
404386

405387

0 commit comments

Comments
 (0)
0