From a0e38e078294f2f4a174a4d6f121b99410ca2c67 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 2 Jul 2023 10:10:48 -0400 Subject: [PATCH] Merge `assignment-from-no-return` into `assignment-from-none` --- .../a/assignment-from-no-return/bad.py | 5 --- .../a/assignment-from-no-return/good.py | 5 --- doc/user_guide/checkers/features.rst | 3 -- doc/user_guide/messages/messages_overview.rst | 1 - doc/whatsnew/fragments/8810.other | 4 +++ pylint/checkers/typecheck.py | 33 ++++++++----------- .../a/assignment/assignment_from_no_return.py | 4 +-- .../assignment/assignment_from_no_return.txt | 4 +-- .../assignment/assignment_from_no_return_2.py | 2 +- .../assignment_from_no_return_2.txt | 2 +- .../singledispatch_functions.py | 2 +- 11 files changed, 25 insertions(+), 40 deletions(-) delete mode 100644 doc/data/messages/a/assignment-from-no-return/bad.py delete mode 100644 doc/data/messages/a/assignment-from-no-return/good.py create mode 100644 doc/whatsnew/fragments/8810.other diff --git a/doc/data/messages/a/assignment-from-no-return/bad.py b/doc/data/messages/a/assignment-from-no-return/bad.py deleted file mode 100644 index ea3822a795..0000000000 --- a/doc/data/messages/a/assignment-from-no-return/bad.py +++ /dev/null @@ -1,5 +0,0 @@ -def add(x, y): - print(x + y) - - -value = add(10, 10) # [assignment-from-no-return] diff --git a/doc/data/messages/a/assignment-from-no-return/good.py b/doc/data/messages/a/assignment-from-no-return/good.py deleted file mode 100644 index c019007e17..0000000000 --- a/doc/data/messages/a/assignment-from-no-return/good.py +++ /dev/null @@ -1,5 +0,0 @@ -def add(x, y): - return x + y - - -value = add(10, 10) diff --git a/doc/user_guide/checkers/features.rst b/doc/user_guide/checkers/features.rst index 5d5848b6d3..33e5a24cc5 100644 --- a/doc/user_guide/checkers/features.rst +++ b/doc/user_guide/checkers/features.rst @@ -1193,9 +1193,6 @@ Typecheck checker Messages Used when a function call would result in assigning multiple values to a function parameter, one value from a positional argument and one from a keyword argument. -:assignment-from-no-return (E1111): *Assigning result of a function call, where the function has no return* - Used when an assignment is done on a function call but the inferred function - doesn't return anything. :assignment-from-none (E1128): *Assigning result of a function call, where the function returns None* Used when an assignment is done on a function call but the inferred function returns nothing but None. diff --git a/doc/user_guide/messages/messages_overview.rst b/doc/user_guide/messages/messages_overview.rst index 173fa53514..da7dd3c531 100644 --- a/doc/user_guide/messages/messages_overview.rst +++ b/doc/user_guide/messages/messages_overview.rst @@ -51,7 +51,6 @@ All messages in the error category: error/abstract-class-instantiated error/access-member-before-definition error/assigning-non-slot - error/assignment-from-no-return error/assignment-from-none error/await-outside-async error/bad-configuration-section diff --git a/doc/whatsnew/fragments/8810.other b/doc/whatsnew/fragments/8810.other new file mode 100644 index 0000000000..dbc2566e3a --- /dev/null +++ b/doc/whatsnew/fragments/8810.other @@ -0,0 +1,4 @@ +Merged ``assignment-from-no-return`` message into ``assignment-from-none``. +The historical name will still work. + +Closes #8810 diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 11b367fec4..4b5ed9f07d 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -263,12 +263,6 @@ def _missing_member_hint( "Used when an object being called has been inferred to a non " "callable object.", ), - "E1111": ( - "Assigning result of a function call, where the function has no return", - "assignment-from-no-return", - "Used when an assignment is done on a function call but the " - "inferred function doesn't return anything.", - ), "E1120": ( "No value for argument %s in %s call", "no-value-for-parameter", @@ -318,7 +312,12 @@ def _missing_member_hint( "assignment-from-none", "Used when an assignment is done on a function call but the " "inferred function returns nothing but None.", - {"old_names": [("W1111", "old-assignment-from-none")]}, + { + "old_names": [ + ("W1111", "old-assignment-from-none"), + ("E1111", "assignment-from-no-return"), + ] + }, ), "E1129": ( "Context manager '%s' doesn't implement __enter__ and __exit__.", @@ -1239,7 +1238,6 @@ def _get_nomember_msgid_hint( return msg, hint # type: ignore[return-value] @only_required_for_messages( - "assignment-from-no-return", "assignment-from-none", "non-str-assignment-to-dunder-name", ) @@ -1287,18 +1285,15 @@ def _check_assignment_from_function_call(self, node: nodes.Assign) -> None: return_nodes = list( function_node.nodes_of_class(nodes.Return, skip_klass=nodes.FunctionDef) ) - if not return_nodes: - self.add_message("assignment-from-no-return", node=node) + for ret_node in return_nodes: + if not ( + isinstance(ret_node.value, nodes.Const) + and ret_node.value.value is None + or ret_node.value is None + ): + break else: - for ret_node in return_nodes: - if not ( - isinstance(ret_node.value, nodes.Const) - and ret_node.value.value is None - or ret_node.value is None - ): - break - else: - self.add_message("assignment-from-none", node=node) + self.add_message("assignment-from-none", node=node) @staticmethod def _is_ignored_function( diff --git a/tests/functional/a/assignment/assignment_from_no_return.py b/tests/functional/a/assignment/assignment_from_no_return.py index 7084beb2fa..c37670efa8 100644 --- a/tests/functional/a/assignment/assignment_from_no_return.py +++ b/tests/functional/a/assignment/assignment_from_no_return.py @@ -23,12 +23,12 @@ def some_other_decorated_method(self): pass def some_other_method(self): - value = self.some_method() # [assignment-from-no-return] + value = self.some_method() # [assignment-from-none] other_value = self.some_other_decorated_method() return value + other_value -VALUE = some_func() # [assignment-from-no-return] +VALUE = some_func() # [assignment-from-none] class Parent: diff --git a/tests/functional/a/assignment/assignment_from_no_return.txt b/tests/functional/a/assignment/assignment_from_no_return.txt index a48e2b22b0..6c3ba75e78 100644 --- a/tests/functional/a/assignment/assignment_from_no_return.txt +++ b/tests/functional/a/assignment/assignment_from_no_return.txt @@ -1,2 +1,2 @@ -assignment-from-no-return:26:8:26:34:Class.some_other_method:Assigning result of a function call, where the function has no return:UNDEFINED -assignment-from-no-return:31:0:31:19::Assigning result of a function call, where the function has no return:UNDEFINED +assignment-from-none:26:8:26:34:Class.some_other_method:Assigning result of a function call, where the function returns None:UNDEFINED +assignment-from-none:31:0:31:19::Assigning result of a function call, where the function returns None:UNDEFINED diff --git a/tests/functional/a/assignment/assignment_from_no_return_2.py b/tests/functional/a/assignment/assignment_from_no_return_2.py index 5df0eddaa5..31ec55a8ca 100644 --- a/tests/functional/a/assignment/assignment_from_no_return_2.py +++ b/tests/functional/a/assignment/assignment_from_no_return_2.py @@ -14,7 +14,7 @@ def func_no_return(): """function without return""" print('dougloup') -A = func_no_return() # [assignment-from-no-return] +A = func_no_return() # [assignment-from-none] def func_return_none(): diff --git a/tests/functional/a/assignment/assignment_from_no_return_2.txt b/tests/functional/a/assignment/assignment_from_no_return_2.txt index f18190c82a..850d5802e3 100644 --- a/tests/functional/a/assignment/assignment_from_no_return_2.txt +++ b/tests/functional/a/assignment/assignment_from_no_return_2.txt @@ -1,4 +1,4 @@ -assignment-from-no-return:17:0:17:20::Assigning result of a function call, where the function has no return:UNDEFINED +assignment-from-none:17:0:17:20::Assigning result of a function call, where the function returns None:UNDEFINED assignment-from-none:25:0:25:22::Assigning result of a function call, where the function returns None:UNDEFINED assignment-from-none:32:0:32:31::Assigning result of a function call, where the function returns None:UNDEFINED assignment-from-none:35:0:35:14::Assigning result of a function call, where the function returns None:INFERENCE diff --git a/tests/functional/s/singledispatch/singledispatch_functions.py b/tests/functional/s/singledispatch/singledispatch_functions.py index 931bfd30d6..d18d08132f 100644 --- a/tests/functional/s/singledispatch/singledispatch_functions.py +++ b/tests/functional/s/singledispatch/singledispatch_functions.py @@ -1,4 +1,4 @@ -# pylint: disable=missing-docstring,import-error,unused-import,assignment-from-no-return +# pylint: disable=missing-docstring,import-error,unused-import,assignment-from-none # pylint: disable=invalid-name, too-few-public-methods from UNINFERABLE import uninferable_func