Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix visit_assign and visit_subscript to handle dictionary assignments #10053

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2072,17 +2072,31 @@
non-sequences as well as in case self/cls get assigned.
"""
self._check_self_cls_assign(node)

if isinstance(node.targets[0], nodes.Subscript):
try:
if isinstance(node.value, nodes.Dict):
return
else:
return

Check notice on line 2081 in pylint/checkers/variables.py

View workflow job for this annotation

GitHub Actions / pylint

R1705

Unnecessary "else" after "return", remove the "else" and de-indent the code inside it
except Exception as e:

Check warning on line 2082 in pylint/checkers/variables.py

View workflow job for this annotation

GitHub Actions / pylint

W0718

Catching too general exception Exception
print(f"Error in assignment: {e}")
return

if not isinstance(node.targets[0], (nodes.Tuple, nodes.List)):
return

targets = node.targets[0].itered()

# Check if we have starred nodes.
if any(isinstance(target, nodes.Starred) for target in targets):
return

try:
inferred = utils.safe_infer(node.value)

if isinstance(node.value, nodes.Dict):
return

if inferred is not None:
self._check_unpacking(inferred, node, targets)
except astroid.InferenceError:
Expand Down Expand Up @@ -3326,6 +3340,10 @@
def visit_subscript(self, node: nodes.Subscript) -> None:
inferred_slice = utils.safe_infer(node.slice)

inferred_value = utils.safe_infer(node.value)
if isinstance(inferred_value, nodes.Dict):
return

self._check_potential_index_error(node, inferred_slice)

def _check_potential_index_error(
Expand Down
Loading