Skip to content

Commit dc1f5f6

Browse files
Emit assignment-from-no-return for builtin methods like dict.update() (#8817)
Follow-up to 32effc5.
1 parent b00d3c9 commit dc1f5f6

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
Emit ``assignment-from-none`` for calls to builtin methods like ``dict.update()``.
1+
Emit ``assignment-from-no-return`` for calls to builtin methods like ``dict.update()``.
2+
Calls to ``list.sort()`` now raise ``assignment-from-no-return``
3+
rather than ``assignment-from-none`` for consistency.
24

35
Closes #8714
6+
Closes #8810

pylint/checkers/typecheck.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
nodes.Arguments,
7575
nodes.FunctionDef,
7676
)
77-
BUILTINS_RETURN_NONE = {
77+
BUILTINS_IMPLICIT_RETURN_NONE = {
7878
"builtins.dict": {"clear", "update"},
7979
"builtins.list": {
8080
"append",
@@ -1278,7 +1278,9 @@ def _check_assignment_from_function_call(self, node: nodes.Assign) -> None:
12781278

12791279
# Handle builtins such as list.sort() or dict.update()
12801280
if self._is_builtin_no_return(node):
1281-
self.add_message("assignment-from-none", node=node, confidence=INFERENCE)
1281+
self.add_message(
1282+
"assignment-from-no-return", node=node, confidence=INFERENCE
1283+
)
12821284
return
12831285

12841286
if not function_node.root().fully_defined():
@@ -1319,7 +1321,7 @@ def _is_builtin_no_return(node: nodes.Assign) -> bool:
13191321
and bool(inferred := utils.safe_infer(node.value.func.expr))
13201322
and isinstance(inferred, bases.Instance)
13211323
and node.value.func.attrname
1322-
in BUILTINS_RETURN_NONE.get(inferred.pytype(), ())
1324+
in BUILTINS_IMPLICIT_RETURN_NONE.get(inferred.pytype(), ())
13231325
)
13241326

13251327
def _check_dundername_is_string(self, node: nodes.Assign) -> None:

tests/functional/a/assignment/assignment_from_no_return_2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ def func_implicit_return_none():
3232
A = func_implicit_return_none() # [assignment-from-none]
3333

3434
lst = [3, 2]
35-
A = lst.sort() # [assignment-from-none]
35+
A = lst.sort() # [assignment-from-no-return]
3636
my_dict = {3: 2}
37-
B = my_dict.update({2: 1}) # [assignment-from-none]
37+
B = my_dict.update({2: 1}) # [assignment-from-no-return]
3838
my_set = set()
39-
C = my_set.symmetric_difference_update([6]) # [assignment-from-none]
39+
C = my_set.symmetric_difference_update([6]) # [assignment-from-no-return]
4040

4141
def func_return_none_and_smth():
4242
"""function returning none and something else"""
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
assignment-from-no-return:17:0:17:20::Assigning result of a function call, where the function has no return:UNDEFINED
22
assignment-from-none:25:0:25:22::Assigning result of a function call, where the function returns None:UNDEFINED
33
assignment-from-none:32:0:32:31::Assigning result of a function call, where the function returns None:UNDEFINED
4-
assignment-from-none:35:0:35:14::Assigning result of a function call, where the function returns None:INFERENCE
5-
assignment-from-none:37:0:37:26::Assigning result of a function call, where the function returns None:INFERENCE
6-
assignment-from-none:39:0:39:43::Assigning result of a function call, where the function returns None:INFERENCE
4+
assignment-from-no-return:35:0:35:14::Assigning result of a function call, where the function has no return:INFERENCE
5+
assignment-from-no-return:37:0:37:26::Assigning result of a function call, where the function has no return:INFERENCE
6+
assignment-from-no-return:39:0:39:43::Assigning result of a function call, where the function has no return:INFERENCE

0 commit comments

Comments
 (0)