Get the legal arguments for the setter associated with *attr*. This is done by querying the docstring of the setter for a line that begins with "ACCEPTS:" or ".. ACCEPTS:", and then by looking for a numpydoc-style documentation for the setter's first argument.
(self, attr)
| 1542 | ) |
| 1543 | |
| 1544 | def get_valid_values(self, attr): |
| 1545 | """ |
| 1546 | Get the legal arguments for the setter associated with *attr*. |
| 1547 | |
| 1548 | This is done by querying the docstring of the setter for a line that |
| 1549 | begins with "ACCEPTS:" or ".. ACCEPTS:", and then by looking for a |
| 1550 | numpydoc-style documentation for the setter's first argument. |
| 1551 | """ |
| 1552 | |
| 1553 | name = 'set_%s' % attr |
| 1554 | if not hasattr(self.o, name): |
| 1555 | raise AttributeError(f'{self.o} has no function {name}') |
| 1556 | func = getattr(self.o, name) |
| 1557 | |
| 1558 | if hasattr(func, '_kwarg_doc'): |
| 1559 | return func._kwarg_doc |
| 1560 | |
| 1561 | docstring = inspect.getdoc(func) |
| 1562 | if docstring is None: |
| 1563 | return 'unknown' |
| 1564 | |
| 1565 | if docstring.startswith('Alias for '): |
| 1566 | return None |
| 1567 | |
| 1568 | match = self._get_valid_values_regex.search(docstring) |
| 1569 | if match is not None: |
| 1570 | return re.sub("\n *", " ", match.group(1)) |
| 1571 | |
| 1572 | # Much faster than list(inspect.signature(func).parameters)[1], |
| 1573 | # although barely relevant wrt. matplotlib's total import time. |
| 1574 | param_name = func.__code__.co_varnames[1] |
| 1575 | # We could set the presence * based on whether the parameter is a |
| 1576 | # varargs (it can't be a varkwargs) but it's not really worth it. |
| 1577 | match = re.search(fr"(?m)^ *\*?{param_name} : (.+)", docstring) |
| 1578 | if match: |
| 1579 | return match.group(1) |
| 1580 | |
| 1581 | return 'unknown' |
| 1582 | |
| 1583 | def _replace_path(self, source_class): |
| 1584 | """ |