def _check_argument_default_values(self, node: AnyFunctionDef) -> None: for arg in node.args.defaults: real_arg = operators.unwrap_unary_node(arg) parts = prop_access.parts(real_arg) if isinstance( real_arg, ast.Attribute, ) else [real_arg] for part in parts: if not isinstance(part, self._allowed_default_value_types): self.add_violation(ComplexDefaultValueViolation(arg)) return
def _is_correct_base_class(self, base: ast.AST) -> bool: if isinstance(base, ast.Name): return True elif isinstance(base, ast.Attribute): return all( isinstance(sub_node, (ast.Name, ast.Attribute)) for sub_node in prop_access.parts(base)) elif isinstance(base, ast.Subscript): parts = list(prop_access.parts(base)) subscripts = list( filter( lambda part: isinstance(part, ast.Subscript), parts, )) correct_items = all( isinstance(sub_node, (ast.Name, ast.Attribute, ast.Subscript)) for sub_node in parts) return len(subscripts) == 1 and correct_items return False
def _check_consecutive_access_number(self, node: AnyAccess) -> None: if node in self._visited_accesses: return consecutive_access = cast( Set[AnyAccess], set(takewhile( self._is_any_access, parts(node), ))) self._visited_accesses.update(consecutive_access) access_number = len(consecutive_access) if access_number > self.options.max_access_level: self.add_violation( TooDeepAccessViolation( node, text=str(access_number), ), )