From 76e009b3ba95a92fde64afc183b0f43829402017 Mon Sep 17 00:00:00 2001 From: Martin Imre Date: Thu, 8 Feb 2024 20:19:16 +0100 Subject: [PATCH] asfsf --- bugbear.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bugbear.py b/bugbear.py index 1fc7e1d..2f10622 100644 --- a/bugbear.py +++ b/bugbear.py @@ -8,7 +8,7 @@ import re import sys import warnings -from collections import namedtuple +from collections import defaultdict, namedtuple from contextlib import suppress from functools import lru_cache, partial from keyword import iskeyword @@ -1620,17 +1620,18 @@ class B909Checker(ast.NodeVisitor): def __init__(self, name: str): self.name = name - self.mutations = [] + self.mutations = defaultdict(list) + self._conditional_block = 0 def visit_Assign(self, node: ast.Assign): for target in node.targets: if isinstance(target, ast.Subscript) and _to_name_str(target.value): - self.mutations.append(node) + self.mutations[self._conditional_block].append(node) self.generic_visit(node) def visit_AugAssign(self, node: ast.AugAssign): if _to_name_str(node.target) == self.name: - self.mutations.append(node) + self.mutations[self._conditional_block].append(node) self.generic_visit(node) def visit_Delete(self, node: ast.Delete): @@ -1644,7 +1645,7 @@ def visit_Delete(self, node: ast.Delete): self.generic_visit(target) if name == self.name: - self.mutations.append(node) + self.mutations[self._conditional_block].append(node) def visit_Call(self, node: ast.Call): if isinstance(node.func, ast.Attribute): @@ -1656,7 +1657,7 @@ def visit_Call(self, node: ast.Call): function_object == self.name and function_name in self.MUTATING_FUNCTIONS ): - self.mutations.append(node) + self.mutations[self._conditional_block].append(node) self.generic_visit(node)