Skip to content

Commit 74eb013

Browse files
committed
corrections
Signed-off-by: Alvaro Frias <[email protected]>
1 parent a4e8361 commit 74eb013

File tree

3 files changed

+7
-21
lines changed

3 files changed

+7
-21
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
def greet(name): # [missing-param-type-annotation]
1+
def greet(name) -> str: # [missing-param-type-annotation]
22
return f"Hello, {name}!"
33

44

55
def add(x, y) -> int: # [missing-param-type-annotation, missing-param-type-annotation]
66
return x + y
77

88

9-
def process(*args, **kwargs): # [missing-param-type-annotation, missing-param-type-annotation]
9+
def process(*args, **kwargs) -> dict: # [missing-param-type-annotation, missing-param-type-annotation]
1010
return combine(args, kwargs)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
def calculate_sum(numbers): # [missing-return-type-annotation]
1+
def calculate_sum(numbers: list[int]): # [missing-return-type-annotation]
22
return sum(numbers)
33

44

5-
async def fetch_data(url): # [missing-return-type-annotation]
5+
async def fetch_data(url: str): # [missing-return-type-annotation]
66
return await get(url)

pylint/checkers/type_annotations.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)