Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_defaults.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_dont_trace.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_dont_trace_files.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_exec2.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/__init__.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_afm.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_animation_data.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_blocking_input.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_cm.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_cm_bivar.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_cm_multivar.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_color_data.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_docstring.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_enums.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_fontconfig_pattern.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_internal_utils.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_layoutgrid.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_mathtext.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_mathtext_data.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_pylab_helpers.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_text_helpers.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_tight_bbox.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_tight_layout.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_type1font.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/_version.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/animation.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/artist.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/axis.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/backend_managers.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/backend_tools.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/bezier.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/category.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/cbook.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/cm.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/collections.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/colorbar.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/colorizer.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/contour.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/dates.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/dviread.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/font_manager.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/gridspec.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/hatch.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/text.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/textpath.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/ticker.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/transforms.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/typing.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/__pycache__/units.cpython-310.pyc +0 -0
- lib/python3.10/site-packages/matplotlib/_api/__init__.py +391 -0
lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_defaults.cpython-310.pyc
ADDED
|
Binary file (1.58 kB). View file
|
|
|
lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_dont_trace.cpython-310.pyc
ADDED
|
Binary file (1.84 kB). View file
|
|
|
lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_dont_trace_files.cpython-310.pyc
ADDED
|
Binary file (4.99 kB). View file
|
|
|
lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/__pycache__/pydevd_exec2.cpython-310.pyc
ADDED
|
Binary file (346 Bytes). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (46.9 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_afm.cpython-310.pyc
ADDED
|
Binary file (15.2 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_animation_data.cpython-310.pyc
ADDED
|
Binary file (8.07 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_blocking_input.cpython-310.pyc
ADDED
|
Binary file (1.39 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_cm.cpython-310.pyc
ADDED
|
Binary file (30.1 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_cm_bivar.cpython-310.pyc
ADDED
|
Binary file (68.8 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_cm_multivar.cpython-310.pyc
ADDED
|
Binary file (5.74 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_color_data.cpython-310.pyc
ADDED
|
Binary file (50.6 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_docstring.cpython-310.pyc
ADDED
|
Binary file (5.58 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_enums.cpython-310.pyc
ADDED
|
Binary file (6.74 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_fontconfig_pattern.cpython-310.pyc
ADDED
|
Binary file (3.85 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_internal_utils.cpython-310.pyc
ADDED
|
Binary file (2.34 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_layoutgrid.cpython-310.pyc
ADDED
|
Binary file (15.6 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_mathtext.cpython-310.pyc
ADDED
|
Binary file (84.2 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_mathtext_data.cpython-310.pyc
ADDED
|
Binary file (41.8 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_pylab_helpers.cpython-310.pyc
ADDED
|
Binary file (5.15 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_text_helpers.cpython-310.pyc
ADDED
|
Binary file (2.7 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_tight_bbox.cpython-310.pyc
ADDED
|
Binary file (2.61 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_tight_layout.cpython-310.pyc
ADDED
|
Binary file (8.91 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_type1font.cpython-310.pyc
ADDED
|
Binary file (24.4 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/_version.cpython-310.pyc
ADDED
|
Binary file (219 Bytes). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/animation.cpython-310.pyc
ADDED
|
Binary file (55.4 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/artist.cpython-310.pyc
ADDED
|
Binary file (57.8 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/axis.cpython-310.pyc
ADDED
|
Binary file (82.6 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/backend_managers.cpython-310.pyc
ADDED
|
Binary file (11.3 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/backend_tools.cpython-310.pyc
ADDED
|
Binary file (32.7 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/bezier.cpython-310.pyc
ADDED
|
Binary file (15.4 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/category.cpython-310.pyc
ADDED
|
Binary file (7.8 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/cbook.cpython-310.pyc
ADDED
|
Binary file (69.4 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/cm.cpython-310.pyc
ADDED
|
Binary file (9.35 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/collections.cpython-310.pyc
ADDED
|
Binary file (86.7 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/colorbar.cpython-310.pyc
ADDED
|
Binary file (44.1 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/colorizer.cpython-310.pyc
ADDED
|
Binary file (21.3 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/contour.cpython-310.pyc
ADDED
|
Binary file (52.9 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/dates.cpython-310.pyc
ADDED
|
Binary file (57.4 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/dviread.cpython-310.pyc
ADDED
|
Binary file (36 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/font_manager.cpython-310.pyc
ADDED
|
Binary file (47.4 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/gridspec.cpython-310.pyc
ADDED
|
Binary file (27.1 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/hatch.cpython-310.pyc
ADDED
|
Binary file (7.33 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/text.cpython-310.pyc
ADDED
|
Binary file (57.8 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/textpath.cpython-310.pyc
ADDED
|
Binary file (11.1 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/ticker.cpython-310.pyc
ADDED
|
Binary file (90.7 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/transforms.cpython-310.pyc
ADDED
|
Binary file (96.3 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/typing.cpython-310.pyc
ADDED
|
Binary file (2.19 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/__pycache__/units.cpython-310.pyc
ADDED
|
Binary file (6.33 kB). View file
|
|
|
lib/python3.10/site-packages/matplotlib/_api/__init__.py
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Helper functions for managing the Matplotlib API.
|
| 3 |
+
|
| 4 |
+
This documentation is only relevant for Matplotlib developers, not for users.
|
| 5 |
+
|
| 6 |
+
.. warning::
|
| 7 |
+
|
| 8 |
+
This module and its submodules are for internal use only. Do not use them
|
| 9 |
+
in your own code. We may change the API at any time with no warning.
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import functools
|
| 14 |
+
import itertools
|
| 15 |
+
import pathlib
|
| 16 |
+
import re
|
| 17 |
+
import sys
|
| 18 |
+
import warnings
|
| 19 |
+
|
| 20 |
+
from .deprecation import ( # noqa: F401
|
| 21 |
+
deprecated, warn_deprecated,
|
| 22 |
+
rename_parameter, delete_parameter, make_keyword_only,
|
| 23 |
+
deprecate_method_override, deprecate_privatize_attribute,
|
| 24 |
+
suppress_matplotlib_deprecation_warning,
|
| 25 |
+
MatplotlibDeprecationWarning)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class classproperty:
|
| 29 |
+
"""
|
| 30 |
+
Like `property`, but also triggers on access via the class, and it is the
|
| 31 |
+
*class* that's passed as argument.
|
| 32 |
+
|
| 33 |
+
Examples
|
| 34 |
+
--------
|
| 35 |
+
::
|
| 36 |
+
|
| 37 |
+
class C:
|
| 38 |
+
@classproperty
|
| 39 |
+
def foo(cls):
|
| 40 |
+
return cls.__name__
|
| 41 |
+
|
| 42 |
+
assert C.foo == "C"
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
def __init__(self, fget, fset=None, fdel=None, doc=None):
|
| 46 |
+
self._fget = fget
|
| 47 |
+
if fset is not None or fdel is not None:
|
| 48 |
+
raise ValueError('classproperty only implements fget.')
|
| 49 |
+
self.fset = fset
|
| 50 |
+
self.fdel = fdel
|
| 51 |
+
# docs are ignored for now
|
| 52 |
+
self._doc = doc
|
| 53 |
+
|
| 54 |
+
def __get__(self, instance, owner):
|
| 55 |
+
return self._fget(owner)
|
| 56 |
+
|
| 57 |
+
@property
|
| 58 |
+
def fget(self):
|
| 59 |
+
return self._fget
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
# In the following check_foo() functions, the first parameter is positional-only to make
|
| 63 |
+
# e.g. `_api.check_isinstance([...], types=foo)` work.
|
| 64 |
+
|
| 65 |
+
def check_isinstance(types, /, **kwargs):
|
| 66 |
+
"""
|
| 67 |
+
For each *key, value* pair in *kwargs*, check that *value* is an instance
|
| 68 |
+
of one of *types*; if not, raise an appropriate TypeError.
|
| 69 |
+
|
| 70 |
+
As a special case, a ``None`` entry in *types* is treated as NoneType.
|
| 71 |
+
|
| 72 |
+
Examples
|
| 73 |
+
--------
|
| 74 |
+
>>> _api.check_isinstance((SomeClass, None), arg=arg)
|
| 75 |
+
"""
|
| 76 |
+
none_type = type(None)
|
| 77 |
+
types = ((types,) if isinstance(types, type) else
|
| 78 |
+
(none_type,) if types is None else
|
| 79 |
+
tuple(none_type if tp is None else tp for tp in types))
|
| 80 |
+
|
| 81 |
+
def type_name(tp):
|
| 82 |
+
return ("None" if tp is none_type
|
| 83 |
+
else tp.__qualname__ if tp.__module__ == "builtins"
|
| 84 |
+
else f"{tp.__module__}.{tp.__qualname__}")
|
| 85 |
+
|
| 86 |
+
for k, v in kwargs.items():
|
| 87 |
+
if not isinstance(v, types):
|
| 88 |
+
names = [*map(type_name, types)]
|
| 89 |
+
if "None" in names: # Move it to the end for better wording.
|
| 90 |
+
names.remove("None")
|
| 91 |
+
names.append("None")
|
| 92 |
+
raise TypeError(
|
| 93 |
+
"{!r} must be an instance of {}, not a {}".format(
|
| 94 |
+
k,
|
| 95 |
+
", ".join(names[:-1]) + " or " + names[-1]
|
| 96 |
+
if len(names) > 1 else names[0],
|
| 97 |
+
type_name(type(v))))
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def check_in_list(values, /, *, _print_supported_values=True, **kwargs):
|
| 101 |
+
"""
|
| 102 |
+
For each *key, value* pair in *kwargs*, check that *value* is in *values*;
|
| 103 |
+
if not, raise an appropriate ValueError.
|
| 104 |
+
|
| 105 |
+
Parameters
|
| 106 |
+
----------
|
| 107 |
+
values : iterable
|
| 108 |
+
Sequence of values to check on.
|
| 109 |
+
_print_supported_values : bool, default: True
|
| 110 |
+
Whether to print *values* when raising ValueError.
|
| 111 |
+
**kwargs : dict
|
| 112 |
+
*key, value* pairs as keyword arguments to find in *values*.
|
| 113 |
+
|
| 114 |
+
Raises
|
| 115 |
+
------
|
| 116 |
+
ValueError
|
| 117 |
+
If any *value* in *kwargs* is not found in *values*.
|
| 118 |
+
|
| 119 |
+
Examples
|
| 120 |
+
--------
|
| 121 |
+
>>> _api.check_in_list(["foo", "bar"], arg=arg, other_arg=other_arg)
|
| 122 |
+
"""
|
| 123 |
+
if not kwargs:
|
| 124 |
+
raise TypeError("No argument to check!")
|
| 125 |
+
for key, val in kwargs.items():
|
| 126 |
+
if val not in values:
|
| 127 |
+
msg = f"{val!r} is not a valid value for {key}"
|
| 128 |
+
if _print_supported_values:
|
| 129 |
+
msg += f"; supported values are {', '.join(map(repr, values))}"
|
| 130 |
+
raise ValueError(msg)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def check_shape(shape, /, **kwargs):
|
| 134 |
+
"""
|
| 135 |
+
For each *key, value* pair in *kwargs*, check that *value* has the shape *shape*;
|
| 136 |
+
if not, raise an appropriate ValueError.
|
| 137 |
+
|
| 138 |
+
*None* in the shape is treated as a "free" size that can have any length.
|
| 139 |
+
e.g. (None, 2) -> (N, 2)
|
| 140 |
+
|
| 141 |
+
The values checked must be numpy arrays.
|
| 142 |
+
|
| 143 |
+
Examples
|
| 144 |
+
--------
|
| 145 |
+
To check for (N, 2) shaped arrays
|
| 146 |
+
|
| 147 |
+
>>> _api.check_shape((None, 2), arg=arg, other_arg=other_arg)
|
| 148 |
+
"""
|
| 149 |
+
for k, v in kwargs.items():
|
| 150 |
+
data_shape = v.shape
|
| 151 |
+
|
| 152 |
+
if (len(data_shape) != len(shape)
|
| 153 |
+
or any(s != t and t is not None for s, t in zip(data_shape, shape))):
|
| 154 |
+
dim_labels = iter(itertools.chain(
|
| 155 |
+
'NMLKJIH',
|
| 156 |
+
(f"D{i}" for i in itertools.count())))
|
| 157 |
+
text_shape = ", ".join([str(n) if n is not None else next(dim_labels)
|
| 158 |
+
for n in shape[::-1]][::-1])
|
| 159 |
+
if len(shape) == 1:
|
| 160 |
+
text_shape += ","
|
| 161 |
+
|
| 162 |
+
raise ValueError(
|
| 163 |
+
f"{k!r} must be {len(shape)}D with shape ({text_shape}), "
|
| 164 |
+
f"but your input has shape {v.shape}"
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def check_getitem(mapping, /, **kwargs):
|
| 169 |
+
"""
|
| 170 |
+
*kwargs* must consist of a single *key, value* pair. If *key* is in
|
| 171 |
+
*mapping*, return ``mapping[value]``; else, raise an appropriate
|
| 172 |
+
ValueError.
|
| 173 |
+
|
| 174 |
+
Examples
|
| 175 |
+
--------
|
| 176 |
+
>>> _api.check_getitem({"foo": "bar"}, arg=arg)
|
| 177 |
+
"""
|
| 178 |
+
if len(kwargs) != 1:
|
| 179 |
+
raise ValueError("check_getitem takes a single keyword argument")
|
| 180 |
+
(k, v), = kwargs.items()
|
| 181 |
+
try:
|
| 182 |
+
return mapping[v]
|
| 183 |
+
except KeyError:
|
| 184 |
+
raise ValueError(
|
| 185 |
+
f"{v!r} is not a valid value for {k}; supported values are "
|
| 186 |
+
f"{', '.join(map(repr, mapping))}") from None
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def caching_module_getattr(cls):
|
| 190 |
+
"""
|
| 191 |
+
Helper decorator for implementing module-level ``__getattr__`` as a class.
|
| 192 |
+
|
| 193 |
+
This decorator must be used at the module toplevel as follows::
|
| 194 |
+
|
| 195 |
+
@caching_module_getattr
|
| 196 |
+
class __getattr__: # The class *must* be named ``__getattr__``.
|
| 197 |
+
@property # Only properties are taken into account.
|
| 198 |
+
def name(self): ...
|
| 199 |
+
|
| 200 |
+
The ``__getattr__`` class will be replaced by a ``__getattr__``
|
| 201 |
+
function such that trying to access ``name`` on the module will
|
| 202 |
+
resolve the corresponding property (which may be decorated e.g. with
|
| 203 |
+
``_api.deprecated`` for deprecating module globals). The properties are
|
| 204 |
+
all implicitly cached. Moreover, a suitable AttributeError is generated
|
| 205 |
+
and raised if no property with the given name exists.
|
| 206 |
+
"""
|
| 207 |
+
|
| 208 |
+
assert cls.__name__ == "__getattr__"
|
| 209 |
+
# Don't accidentally export cls dunders.
|
| 210 |
+
props = {name: prop for name, prop in vars(cls).items()
|
| 211 |
+
if isinstance(prop, property)}
|
| 212 |
+
instance = cls()
|
| 213 |
+
|
| 214 |
+
@functools.cache
|
| 215 |
+
def __getattr__(name):
|
| 216 |
+
if name in props:
|
| 217 |
+
return props[name].__get__(instance)
|
| 218 |
+
raise AttributeError(
|
| 219 |
+
f"module {cls.__module__!r} has no attribute {name!r}")
|
| 220 |
+
|
| 221 |
+
return __getattr__
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def define_aliases(alias_d, cls=None):
|
| 225 |
+
"""
|
| 226 |
+
Class decorator for defining property aliases.
|
| 227 |
+
|
| 228 |
+
Use as ::
|
| 229 |
+
|
| 230 |
+
@_api.define_aliases({"property": ["alias", ...], ...})
|
| 231 |
+
class C: ...
|
| 232 |
+
|
| 233 |
+
For each property, if the corresponding ``get_property`` is defined in the
|
| 234 |
+
class so far, an alias named ``get_alias`` will be defined; the same will
|
| 235 |
+
be done for setters. If neither the getter nor the setter exists, an
|
| 236 |
+
exception will be raised.
|
| 237 |
+
|
| 238 |
+
The alias map is stored as the ``_alias_map`` attribute on the class and
|
| 239 |
+
can be used by `.normalize_kwargs` (which assumes that higher priority
|
| 240 |
+
aliases come last).
|
| 241 |
+
"""
|
| 242 |
+
if cls is None: # Return the actual class decorator.
|
| 243 |
+
return functools.partial(define_aliases, alias_d)
|
| 244 |
+
|
| 245 |
+
def make_alias(name): # Enforce a closure over *name*.
|
| 246 |
+
@functools.wraps(getattr(cls, name))
|
| 247 |
+
def method(self, *args, **kwargs):
|
| 248 |
+
return getattr(self, name)(*args, **kwargs)
|
| 249 |
+
return method
|
| 250 |
+
|
| 251 |
+
for prop, aliases in alias_d.items():
|
| 252 |
+
exists = False
|
| 253 |
+
for prefix in ["get_", "set_"]:
|
| 254 |
+
if prefix + prop in vars(cls):
|
| 255 |
+
exists = True
|
| 256 |
+
for alias in aliases:
|
| 257 |
+
method = make_alias(prefix + prop)
|
| 258 |
+
method.__name__ = prefix + alias
|
| 259 |
+
method.__doc__ = f"Alias for `{prefix + prop}`."
|
| 260 |
+
setattr(cls, prefix + alias, method)
|
| 261 |
+
if not exists:
|
| 262 |
+
raise ValueError(
|
| 263 |
+
f"Neither getter nor setter exists for {prop!r}")
|
| 264 |
+
|
| 265 |
+
def get_aliased_and_aliases(d):
|
| 266 |
+
return {*d, *(alias for aliases in d.values() for alias in aliases)}
|
| 267 |
+
|
| 268 |
+
preexisting_aliases = getattr(cls, "_alias_map", {})
|
| 269 |
+
conflicting = (get_aliased_and_aliases(preexisting_aliases)
|
| 270 |
+
& get_aliased_and_aliases(alias_d))
|
| 271 |
+
if conflicting:
|
| 272 |
+
# Need to decide on conflict resolution policy.
|
| 273 |
+
raise NotImplementedError(
|
| 274 |
+
f"Parent class already defines conflicting aliases: {conflicting}")
|
| 275 |
+
cls._alias_map = {**preexisting_aliases, **alias_d}
|
| 276 |
+
return cls
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
def select_matching_signature(funcs, *args, **kwargs):
|
| 280 |
+
"""
|
| 281 |
+
Select and call the function that accepts ``*args, **kwargs``.
|
| 282 |
+
|
| 283 |
+
*funcs* is a list of functions which should not raise any exception (other
|
| 284 |
+
than `TypeError` if the arguments passed do not match their signature).
|
| 285 |
+
|
| 286 |
+
`select_matching_signature` tries to call each of the functions in *funcs*
|
| 287 |
+
with ``*args, **kwargs`` (in the order in which they are given). Calls
|
| 288 |
+
that fail with a `TypeError` are silently skipped. As soon as a call
|
| 289 |
+
succeeds, `select_matching_signature` returns its return value. If no
|
| 290 |
+
function accepts ``*args, **kwargs``, then the `TypeError` raised by the
|
| 291 |
+
last failing call is re-raised.
|
| 292 |
+
|
| 293 |
+
Callers should normally make sure that any ``*args, **kwargs`` can only
|
| 294 |
+
bind a single *func* (to avoid any ambiguity), although this is not checked
|
| 295 |
+
by `select_matching_signature`.
|
| 296 |
+
|
| 297 |
+
Notes
|
| 298 |
+
-----
|
| 299 |
+
`select_matching_signature` is intended to help implementing
|
| 300 |
+
signature-overloaded functions. In general, such functions should be
|
| 301 |
+
avoided, except for back-compatibility concerns. A typical use pattern is
|
| 302 |
+
::
|
| 303 |
+
|
| 304 |
+
def my_func(*args, **kwargs):
|
| 305 |
+
params = select_matching_signature(
|
| 306 |
+
[lambda old1, old2: locals(), lambda new: locals()],
|
| 307 |
+
*args, **kwargs)
|
| 308 |
+
if "old1" in params:
|
| 309 |
+
warn_deprecated(...)
|
| 310 |
+
old1, old2 = params.values() # note that locals() is ordered.
|
| 311 |
+
else:
|
| 312 |
+
new, = params.values()
|
| 313 |
+
# do things with params
|
| 314 |
+
|
| 315 |
+
which allows *my_func* to be called either with two parameters (*old1* and
|
| 316 |
+
*old2*) or a single one (*new*). Note that the new signature is given
|
| 317 |
+
last, so that callers get a `TypeError` corresponding to the new signature
|
| 318 |
+
if the arguments they passed in do not match any signature.
|
| 319 |
+
"""
|
| 320 |
+
# Rather than relying on locals() ordering, one could have just used func's
|
| 321 |
+
# signature (``bound = inspect.signature(func).bind(*args, **kwargs);
|
| 322 |
+
# bound.apply_defaults(); return bound``) but that is significantly slower.
|
| 323 |
+
for i, func in enumerate(funcs):
|
| 324 |
+
try:
|
| 325 |
+
return func(*args, **kwargs)
|
| 326 |
+
except TypeError:
|
| 327 |
+
if i == len(funcs) - 1:
|
| 328 |
+
raise
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def nargs_error(name, takes, given):
|
| 332 |
+
"""Generate a TypeError to be raised by function calls with wrong arity."""
|
| 333 |
+
return TypeError(f"{name}() takes {takes} positional arguments but "
|
| 334 |
+
f"{given} were given")
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
def kwarg_error(name, kw):
|
| 338 |
+
"""
|
| 339 |
+
Generate a TypeError to be raised by function calls with wrong kwarg.
|
| 340 |
+
|
| 341 |
+
Parameters
|
| 342 |
+
----------
|
| 343 |
+
name : str
|
| 344 |
+
The name of the calling function.
|
| 345 |
+
kw : str or Iterable[str]
|
| 346 |
+
Either the invalid keyword argument name, or an iterable yielding
|
| 347 |
+
invalid keyword arguments (e.g., a ``kwargs`` dict).
|
| 348 |
+
"""
|
| 349 |
+
if not isinstance(kw, str):
|
| 350 |
+
kw = next(iter(kw))
|
| 351 |
+
return TypeError(f"{name}() got an unexpected keyword argument '{kw}'")
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def recursive_subclasses(cls):
|
| 355 |
+
"""Yield *cls* and direct and indirect subclasses of *cls*."""
|
| 356 |
+
yield cls
|
| 357 |
+
for subcls in cls.__subclasses__():
|
| 358 |
+
yield from recursive_subclasses(subcls)
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
def warn_external(message, category=None):
|
| 362 |
+
"""
|
| 363 |
+
`warnings.warn` wrapper that sets *stacklevel* to "outside Matplotlib".
|
| 364 |
+
|
| 365 |
+
The original emitter of the warning can be obtained by patching this
|
| 366 |
+
function back to `warnings.warn`, i.e. ``_api.warn_external =
|
| 367 |
+
warnings.warn`` (or ``functools.partial(warnings.warn, stacklevel=2)``,
|
| 368 |
+
etc.).
|
| 369 |
+
"""
|
| 370 |
+
kwargs = {}
|
| 371 |
+
if sys.version_info[:2] >= (3, 12):
|
| 372 |
+
# Go to Python's `site-packages` or `lib` from an editable install.
|
| 373 |
+
basedir = pathlib.Path(__file__).parents[2]
|
| 374 |
+
kwargs['skip_file_prefixes'] = (str(basedir / 'matplotlib'),
|
| 375 |
+
str(basedir / 'mpl_toolkits'))
|
| 376 |
+
else:
|
| 377 |
+
frame = sys._getframe()
|
| 378 |
+
for stacklevel in itertools.count(1):
|
| 379 |
+
if frame is None:
|
| 380 |
+
# when called in embedded context may hit frame is None
|
| 381 |
+
kwargs['stacklevel'] = stacklevel
|
| 382 |
+
break
|
| 383 |
+
if not re.match(r"\A(matplotlib|mpl_toolkits)(\Z|\.(?!tests\.))",
|
| 384 |
+
# Work around sphinx-gallery not setting __name__.
|
| 385 |
+
frame.f_globals.get("__name__", "")):
|
| 386 |
+
kwargs['stacklevel'] = stacklevel
|
| 387 |
+
break
|
| 388 |
+
frame = frame.f_back
|
| 389 |
+
# preemptively break reference cycle between locals and the frame
|
| 390 |
+
del frame
|
| 391 |
+
warnings.warn(message, category, **kwargs)
|