Return the list of default arguments of obj if it is callable, or empty list otherwise.
(self, obj)
| 1454 | return ret |
| 1455 | |
| 1456 | def _default_arguments(self, obj): |
| 1457 | """Return the list of default arguments of obj if it is callable, |
| 1458 | or empty list otherwise.""" |
| 1459 | call_obj = obj |
| 1460 | ret = [] |
| 1461 | if inspect.isbuiltin(obj): |
| 1462 | pass |
| 1463 | elif not (inspect.isfunction(obj) or inspect.ismethod(obj)): |
| 1464 | if inspect.isclass(obj): |
| 1465 | #for cython embedsignature=True the constructor docstring |
| 1466 | #belongs to the object itself not __init__ |
| 1467 | ret += self._default_arguments_from_docstring( |
| 1468 | getattr(obj, '__doc__', '')) |
| 1469 | # for classes, check for __init__,__new__ |
| 1470 | call_obj = (getattr(obj, '__init__', None) or |
| 1471 | getattr(obj, '__new__', None)) |
| 1472 | # for all others, check if they are __call__able |
| 1473 | elif hasattr(obj, '__call__'): |
| 1474 | call_obj = obj.__call__ |
| 1475 | ret += self._default_arguments_from_docstring( |
| 1476 | getattr(call_obj, '__doc__', '')) |
| 1477 | |
| 1478 | _keeps = (inspect.Parameter.KEYWORD_ONLY, |
| 1479 | inspect.Parameter.POSITIONAL_OR_KEYWORD) |
| 1480 | |
| 1481 | try: |
| 1482 | sig = inspect.signature(call_obj) |
| 1483 | ret.extend(k for k, v in sig.parameters.items() if |
| 1484 | v.kind in _keeps) |
| 1485 | except ValueError: |
| 1486 | pass |
| 1487 | |
| 1488 | return list(set(ret)) |
| 1489 | |
| 1490 | def python_func_kw_matches(self,text): |
| 1491 | """Match named parameters (kwargs) of the last open function""" |
no test coverage detected