File tree Expand file tree Collapse file tree 3 files changed +59
-9
lines changed Expand file tree Collapse file tree 3 files changed +59
-9
lines changed Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ def get_signature(self) -> Optional[inspect.Signature]:
74
74
source = self ._get_source ()
75
75
76
76
try :
77
- return inspect .signature (source )
77
+ return inspect .signature (source , follow_wrapped = True )
78
78
except (ValueError , TypeError ):
79
79
return None
80
80
@@ -130,10 +130,13 @@ def get_child_spec(self, name: str) -> "Spec":
130
130
elif isinstance (child_source , staticmethod ):
131
131
child_source = child_source .__func__
132
132
133
- elif inspect .isfunction (child_source ):
134
- # consume the `self` argument of the method to ensure proper
135
- # signature reporting by wrapping it in a partial
136
- child_source = functools .partial (child_source , None )
133
+ else :
134
+ child_source = inspect .unwrap (child_source )
135
+
136
+ if inspect .isfunction (child_source ):
137
+ # consume the `self` argument of the method to ensure proper
138
+ # signature reporting by wrapping it in a partial
139
+ child_source = functools .partial (child_source , None )
137
140
138
141
return Spec (source = child_source , name = child_name , module_name = self ._module_name )
139
142
Original file line number Diff line number Diff line change 1
1
"""Common test interfaces."""
2
+ from functools import lru_cache
2
3
from typing import Any
3
4
4
5
@@ -27,6 +28,11 @@ def primitive_property(self) -> str:
27
28
"""Get a primitive computed property."""
28
29
...
29
30
31
+ @lru_cache (maxsize = None )
32
+ def some_wrapped_method (self , val : str ) -> str :
33
+ """Get a thing through a wrapped method."""
34
+ ...
35
+
30
36
31
37
class SomeNestedClass :
32
38
"""Nested testing class."""
@@ -75,17 +81,22 @@ async def __call__(self, val: int) -> int:
75
81
...
76
82
77
83
78
- # NOTE: these `Any`s are forward references for call signature testing purposes
79
84
def noop (* args : Any , ** kwargs : Any ) -> Any :
80
85
"""No-op."""
81
- pass
86
+ ...
82
87
83
88
84
89
def some_func (val : str ) -> str :
85
90
"""Test function."""
86
- return "can't touch this"
91
+ ...
87
92
88
93
89
94
async def some_async_func (val : str ) -> str :
90
95
"""Async test function."""
91
- return "can't touch this"
96
+ ...
97
+
98
+
99
+ @lru_cache (maxsize = None )
100
+ def some_wrapped_func (val : str ) -> str :
101
+ """Wrapped test function."""
102
+ ...
Original file line number Diff line number Diff line change 13
13
SomeNestedClass ,
14
14
some_func ,
15
15
some_async_func ,
16
+ some_wrapped_func ,
16
17
)
17
18
18
19
@@ -184,6 +185,34 @@ class GetSignatureSpec(NamedTuple):
184
185
return_annotation = int ,
185
186
),
186
187
),
188
+ GetSignatureSpec (
189
+ subject = Spec (source = some_wrapped_func , name = None ),
190
+ expected_signature = inspect .Signature (
191
+ parameters = [
192
+ inspect .Parameter (
193
+ name = "val" ,
194
+ kind = inspect .Parameter .POSITIONAL_OR_KEYWORD ,
195
+ annotation = str ,
196
+ )
197
+ ],
198
+ return_annotation = str ,
199
+ ),
200
+ ),
201
+ GetSignatureSpec (
202
+ subject = Spec (source = SomeClass , name = None ).get_child_spec (
203
+ "some_wrapped_method"
204
+ ),
205
+ expected_signature = inspect .Signature (
206
+ parameters = [
207
+ inspect .Parameter (
208
+ name = "val" ,
209
+ kind = inspect .Parameter .POSITIONAL_OR_KEYWORD ,
210
+ annotation = str ,
211
+ )
212
+ ],
213
+ return_annotation = str ,
214
+ ),
215
+ ),
187
216
],
188
217
)
189
218
def test_get_signature (
@@ -315,6 +344,13 @@ class GetBindArgsSpec(NamedTuple):
315
344
expected_args = ("hello" ,),
316
345
expected_kwargs = {},
317
346
),
347
+ GetBindArgsSpec (
348
+ subject = Spec (source = some_wrapped_func , name = None ),
349
+ input_args = (),
350
+ input_kwargs = {"val" : "hello" },
351
+ expected_args = ("hello" ,),
352
+ expected_kwargs = {},
353
+ ),
318
354
],
319
355
)
320
356
def test_bind_args (
You can’t perform that action at this time.
0 commit comments