@@ -291,6 +291,9 @@ def visit_FunctionDef(self, node: FunctionDef) -> None:
291291 if hasattr (argument , 'annotation' ) and argument .annotation :
292292 self .visit (argument .annotation )
293293
294+ if node .returns :
295+ self .visit (node .returns )
296+
294297 def visit_AsyncFunctionDef (self , node : AsyncFunctionDef ) -> None :
295298 """Remove and map function arguments and returns."""
296299 if self ._function_is_wrapped_by_validate_arguments (node ):
@@ -299,6 +302,9 @@ def visit_AsyncFunctionDef(self, node: AsyncFunctionDef) -> None:
299302 if hasattr (argument , 'annotation' ) and argument .annotation :
300303 self .visit (argument .annotation )
301304
305+ if node .returns :
306+ self .visit (node .returns )
307+
302308
303309class SQLAlchemyAnnotationVisitor (AnnotationVisitor ):
304310 """Adds any names in the annotation to mapped names."""
@@ -548,24 +554,13 @@ def handle_fastapi_decorator(self, node: AsyncFunctionDef | FunctionDef) -> None
548554
549555 To achieve this, we just visit the annotations to register them as "uses".
550556 """
551- for path in [node .args .args , node .args .kwonlyargs ]:
557+ for path in [node .args .args , node .args .kwonlyargs , node . args . posonlyargs ]:
552558 for argument in path :
553559 if hasattr (argument , 'annotation' ) and argument .annotation :
554560 self .visit (argument .annotation )
555- if (
556- hasattr (node .args , 'kwarg' )
557- and node .args .kwarg
558- and hasattr (node .args .kwarg , 'annotation' )
559- and node .args .kwarg .annotation
560- ):
561- self .visit (node .args .kwarg .annotation )
562- if (
563- hasattr (node .args , 'vararg' )
564- and node .args .vararg
565- and hasattr (node .args .vararg , 'annotation' )
566- and node .args .vararg .annotation
567- ):
568- self .visit (node .args .vararg .annotation )
561+
562+ if node .returns :
563+ self .visit (node .returns )
569564
570565
571566class FunctoolsSingledispatchMixin :
@@ -627,6 +622,9 @@ def handle_singledispatch_decorator(self, node: FunctionDef | AsyncFunctionDef)
627622 if hasattr (argument , 'annotation' ) and argument .annotation :
628623 self .visit (argument .annotation )
629624
625+ if node .returns :
626+ self .visit (node .returns )
627+
630628
631629@dataclass
632630class ImportName :
0 commit comments