@@ -31,12 +31,14 @@ class TypeAnnotationChecker(checkers.BaseChecker):
3131 "missing-return-type-annotation" ,
3232 "Used when a function or method does not have a return type annotation. "
3333 "Type annotations improve code readability and help with static type checking." ,
34+ {"default_enabled" : False },
3435 ),
3536 "C3802" : (
3637 "Missing type annotation for parameter %r in function %r" ,
3738 "missing-param-type-annotation" ,
3839 "Used when a function or method parameter does not have a type annotation. "
3940 "Type annotations improve code readability and help with static type checking." ,
41+ {"default_enabled" : False },
4042 ),
4143 }
4244
@@ -48,13 +50,7 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
4850 self ._check_return_type_annotation (node )
4951 self ._check_param_type_annotations (node )
5052
51- @utils .only_required_for_messages (
52- "missing-return-type-annotation" , "missing-param-type-annotation"
53- )
54- def visit_asyncfunctiondef (self , node : nodes .AsyncFunctionDef ) -> None :
55- """Check for missing type annotations in async functions."""
56- self ._check_return_type_annotation (node )
57- self ._check_param_type_annotations (node )
53+ visit_asyncfunctiondef = visit_functiondef
5854
5955 def _check_return_type_annotation (
6056 self , node : nodes .FunctionDef | nodes .AsyncFunctionDef
@@ -64,35 +60,28 @@ def _check_return_type_annotation(
6460 Args:
6561 node: The function definition node to check
6662 """
67- # Skip if function already has return type annotation
6863 if node .returns is not None :
6964 return
7065
71- # Skip if function has type comment with return type
7266 if node .type_comment_returns :
7367 return
7468
75- # Skip __init__ methods as they implicitly return None
7669 if node .name == "__init__" :
7770 return
7871
79- # Skip abstract methods (often overridden with proper annotations)
8072 if utils .decorated_with (node , ["abc.abstractmethod" , "abc.abstractproperty" ]):
8173 return
8274
83- # Skip overload decorators (stub definitions)
8475 if utils .decorated_with (
8576 node , ["typing.overload" , "typing_extensions.overload" ]
8677 ):
8778 return
8879
89- # Skip property setters and delete methods (return value not meaningful)
9080 if utils .decorated_with (
9181 node , ["property" , "*.setter" , "*.deleter" , "builtins.property" ]
9282 ):
9383 return
9484
95- # Emit the message
9685 self .add_message ("missing-return-type-annotation" , node = node , args = (node .name ,))
9786
9887 def _check_param_type_annotations (
@@ -103,11 +92,9 @@ def _check_param_type_annotations(
10392 Args:
10493 node: The function definition node to check
10594 """
106- # Skip abstract methods
10795 if utils .decorated_with (node , ["abc.abstractmethod" , "abc.abstractproperty" ]):
10896 return
10997
110- # Skip overload decorators
11198 if utils .decorated_with (
11299 node , ["typing.overload" , "typing_extensions.overload" ]
113100 ):
@@ -132,7 +119,6 @@ def _check_param_type_annotations(
132119 if arguments .args :
133120 annotations = arguments .annotations or []
134121 start_idx = 0
135- # Skip 'self' or 'cls' for methods
136122 if (
137123 arguments .args
138124 and arguments .args [0 ].name in {"self" , "cls" }
0 commit comments