@@ -33,6 +33,18 @@ def _f_pass():
33
33
34
34
35
35
class FunctionParser (BaseParser ):
36
+ @property
37
+ def bound (self ):
38
+ # class A:
39
+ # class B:
40
+ # def f():
41
+ # f.__qualname__ = 'A.B.f'
42
+ # f.bound -> 'A.B'
43
+ name = self .obj .__qualname__
44
+ if '.' in name :
45
+ return '.' .join (name .split ('.' )[:- 1 ])
46
+ return None
47
+
36
48
@classmethod
37
49
def function_pass (cls , f ):
38
50
if not inspect .isfunction (f ):
@@ -299,10 +311,12 @@ def generate_return_types(self):
299
311
if not self .return_annotation :
300
312
return
301
313
302
- self .return_type = self .parse_annotation (annotation = self .return_annotation )
314
+ self .return_type = self .parse_annotation (
315
+ annotation = self .return_annotation
316
+ )
303
317
304
318
# https://docs.python.org/3/library/typing.html#typing.Generator
305
- if self .return_type and issubclass (self .return_type , Rule ):
319
+ if self .return_type and isinstance ( self . return_type , type ) and issubclass (self .return_type , Rule ):
306
320
if self .is_generator :
307
321
if self .return_type .__origin__ in (Iterable , Iterator ):
308
322
self .generator_yield_type = self .return_type .__args__ [0 ]
@@ -406,6 +420,7 @@ def generate_fields(self):
406
420
forward_refs = self .forward_refs ,
407
421
options = self .options ,
408
422
positional_only = param .kind == param .POSITIONAL_ONLY ,
423
+ bound = self .bound ,
409
424
** self .kwargs
410
425
)
411
426
except Exception as e :
@@ -760,6 +775,7 @@ def get_sync_generator(
760
775
@wraps (self .obj )
761
776
def eager_generator (* args , ** kwargs ) -> Generator :
762
777
context = (options or self .options ).make_context ()
778
+ self .resolve_forward_refs ()
763
779
args , kwargs = self .get_params (
764
780
args ,
765
781
kwargs ,
@@ -846,6 +862,7 @@ def get_async_generator(
846
862
@wraps (self .obj )
847
863
def eager_generator (* args , ** kwargs ) -> AsyncGenerator :
848
864
context = (options or self .options ).make_context ()
865
+ self .resolve_forward_refs ()
849
866
args , kwargs = self .get_params (
850
867
args ,
851
868
kwargs ,
@@ -886,6 +903,7 @@ def get_async_call(
886
903
@wraps (self .obj )
887
904
def eager_call (* args , ** kwargs ):
888
905
context = (options or self .options ).make_context ()
906
+ self .resolve_forward_refs ()
889
907
args , kwargs = self .get_params (
890
908
args ,
891
909
kwargs ,
@@ -915,6 +933,7 @@ def sync_call(
915
933
parse_params : bool = None ,
916
934
parse_result : bool = None ,
917
935
):
936
+ self .resolve_forward_refs ()
918
937
args , kwargs = self .get_params (
919
938
args ,
920
939
kwargs ,
0 commit comments