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
Пример #2
0
    def _check_complex_argument_defaults(
        self,
        node: AnyFunctionDefAndLambda,
    ) -> None:
        all_defaults = filter(None, (
            *node.args.defaults,
            *node.args.kw_defaults,
        ))

        for arg in all_defaults:
            real_arg = operators.unwrap_unary_node(arg)
            parts = attributes.parts(real_arg) if isinstance(
                real_arg,
                ast.Attribute,
            ) else [real_arg]

            has_incorrect_part = any(
                not isinstance(part, self._allowed_default_value_types)
                for part in parts)

            if has_incorrect_part:
                self.add_violation(ComplexDefaultValueViolation(arg))
Пример #3
0
 def _check_argument_default_values(self, node: AnyFunctionDef) -> None:
     for arg in node.args.defaults:
         real_arg = operators.unwrap_unary_node(arg)
         if not isinstance(real_arg, self._allowed_default_value_types):
             self.add_violation(ComplexDefaultValueViolation(node))