|
3 | 3 | Classes in this module are heavily inspired by the |
4 | 4 | [unittest.mock library](https://docs.python.org/3/library/unittest.mock.html). |
5 | 5 | """ |
6 | | -from inspect import isclass, iscoroutinefunction, isfunction, signature |
| 6 | +from inspect import getattr_static, isclass, iscoroutinefunction, isfunction, signature |
7 | 7 | from functools import partial |
8 | 8 | from typing import get_type_hints, Any, Callable, Dict, NamedTuple, Optional |
9 | 9 |
|
@@ -105,15 +105,19 @@ def __getattr__(self, name: str) -> Any: |
105 | 105 | except Exception: |
106 | 106 | child_hint = None |
107 | 107 |
|
108 | | - child_spec = getattr(self._spec, name, child_hint) |
| 108 | + child_spec = getattr_static(self._spec, name, child_hint) |
109 | 109 |
|
110 | 110 | if isinstance(child_spec, property): |
111 | 111 | child_spec = _get_type_hints(child_spec.fget).get("return") |
112 | 112 |
|
| 113 | + if isinstance(child_spec, staticmethod): |
| 114 | + child_spec = child_spec.__func__ |
| 115 | + |
113 | 116 | elif isclass(self._spec) and isfunction(child_spec): |
114 | 117 | # `iscoroutinefunction` does not work for `partial` on Python < 3.8 |
115 | 118 | # check before we wrap it |
116 | 119 | child_is_async = iscoroutinefunction(child_spec) |
| 120 | + |
117 | 121 | # consume the `self` argument of the method to ensure proper |
118 | 122 | # signature reporting by wrapping it in a partial |
119 | 123 | child_spec = partial(child_spec, None) # type: ignore[arg-type] |
|
0 commit comments