diff options
-rw-r--r-- | doc/whatsnew/fragments/8120.false_positive | 3 | ||||
-rw-r--r-- | pylint/extensions/redefined_variable_type.py | 4 | ||||
-rw-r--r-- | tests/functional/ext/redefined_variable_type/redefined_variable_type.py | 25 |
3 files changed, 30 insertions, 2 deletions
diff --git a/doc/whatsnew/fragments/8120.false_positive b/doc/whatsnew/fragments/8120.false_positive new file mode 100644 index 000000000..6c0f3c0d0 --- /dev/null +++ b/doc/whatsnew/fragments/8120.false_positive @@ -0,0 +1,3 @@ +Fix a false positive for ``redefined-variable-type`` when ``async`` methods are present. + +Closes #8120 diff --git a/pylint/extensions/redefined_variable_type.py b/pylint/extensions/redefined_variable_type.py index ae7344cc1..8d88d856e 100644 --- a/pylint/extensions/redefined_variable_type.py +++ b/pylint/extensions/redefined_variable_type.py @@ -46,8 +46,8 @@ class MultipleTypesChecker(BaseChecker): def leave_classdef(self, _: nodes.ClassDef) -> None: self._check_and_add_messages() - visit_functiondef = visit_classdef - leave_functiondef = leave_module = leave_classdef + visit_functiondef = visit_asyncfunctiondef = visit_classdef + leave_functiondef = leave_asyncfunctiondef = leave_module = leave_classdef def visit_module(self, _: nodes.Module) -> None: self._assigns: list[dict[str, list[tuple[nodes.Assign, str]]]] = [{}] diff --git a/tests/functional/ext/redefined_variable_type/redefined_variable_type.py b/tests/functional/ext/redefined_variable_type/redefined_variable_type.py index 7cd14b81e..1d31bc968 100644 --- a/tests/functional/ext/redefined_variable_type/redefined_variable_type.py +++ b/tests/functional/ext/redefined_variable_type/redefined_variable_type.py @@ -83,3 +83,28 @@ def func2(x): else: var4 = 2. var4 = 'baz' # [redefined-variable-type] + + +# Test that ``redefined-variable-type`` is not emitted +# https://github.com/PyCQA/pylint/issues/8120 + +async def test_a(): + data = [ + {'test': 1}, + {'test': 2}, + ] + return data + +async def test_b(): + data = {'test': 1} + return data + + +class AsyncFunctions: + async def funtion1(self): + potato = 1 + print(potato) + + async def funtion2(self): + potato = {} + print(potato) |