@utils.check_messages("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL><INDENT>def visit_assignname(self, node):<DEDENT>

self._check_assign_to_new_keyword_violation(node.name, node)<EOL>frame = node.frame()<EOL>assign_type = node.assign_type()<EOL>if isinstance(assign_type, astroid.Comprehension):<EOL><INDENT>self._check_name("<STR_LIT>", node.name, node)<EOL><DEDENT>elif isinstance(frame, astroid.Module):<EOL><INDENT>if isinstance(assign_type, astroid.Assign) and not in_loop(assign_type):<EOL><INDENT>if isinstance(utils.safe_infer(assign_type.value), astroid.ClassDef):<EOL><INDENT>self._check_name("<STR_LIT:class>", node.name, node)<EOL><DEDENT>else:<EOL><INDENT>if not _redefines_import(node):<EOL><INDENT>self._check_name("<STR_LIT>", node.name, node)<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(assign_type, astroid.ExceptHandler):<EOL><INDENT>self._check_name("<STR_LIT>", node.name, node)<EOL><DEDENT><DEDENT>elif isinstance(frame, astroid.FunctionDef):<EOL><INDENT>if node.name in frame and node.name not in frame.argnames():<EOL><INDENT>if not _redefines_import(node):<EOL><INDENT>self._check_name("<STR_LIT>", node.name, node)<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(frame, astroid.ClassDef):<EOL><INDENT>if not list(frame.local_attr_ancestors(node.name)):<EOL><INDENT>self._check_name("<STR_LIT>", node.name, node)<EOL><DEDENT><DEDENT>


def _recursive_check_names(self, args, node):

for arg in args:<EOL><INDENT>if isinstance(arg, astroid.AssignName):<EOL><INDENT>self._check_name("<STR_LIT>", arg.name, node)<EOL><DEDENT>else:<EOL><INDENT>self._recursive_check_names(arg.elts, node)<EOL><DEDENT><DEDENT>

check names in a possibly recursive list <arg>


def _check_name(self, node_type, name, node, confidence=interfaces.HIGH):

def _should_exempt_from_invalid_name(node):<EOL><INDENT>if node_type == "<STR_LIT>":<EOL><INDENT>inferred = utils.safe_infer(node)<EOL>if isinstance(inferred, astroid.ClassDef):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL><DEDENT>if utils.is_inside_except(node):<EOL><INDENT>clobbering, _ = utils.clobber_in_except(node)<EOL>if clobbering:<EOL><INDENT>return<EOL><DEDENT><DEDENT>if name in self.config.good_names:<EOL><INDENT>return<EOL><DEDENT>if name in self.config.bad_names:<EOL><INDENT>self.stats["<STR_LIT>" + node_type] += <NUM_LIT:1><EOL>self.add_message("<STR_LIT>", node=node, args=name)<EOL>return<EOL><DEDENT>regexp = self._name_regexps[node_type]<EOL>match = regexp.match(name)<EOL>if _is_multi_naming_match(match, node_type, confidence):<EOL><INDENT>name_group = self._find_name_group(node_type)<EOL>bad_name_group = self._bad_names.setdefault(name_group, {})<EOL>warnings = bad_name_group.setdefault(match.lastgroup, [])<EOL>warnings.append((node, node_type, name, confidence))<EOL><DEDENT>if match is None and not _should_exempt_from_invalid_name(node):<EOL><INDENT>self._raise_name_warning(node, node_type, name, confidence)<EOL><DEDENT>

check for a name using the type's regexp


def _check_docstring(<EOL>self, node_type, node, report_missing=True, confidence=interfaces.HIGH<EOL>):

docstring = node.doc<EOL>if docstring is None:<EOL><INDENT>if not report_missing:<EOL><INDENT>return<EOL><DEDENT>lines = utils.get_node_last_lineno(node) - node.lineno<EOL>if node_type == "<STR_LIT>" and not lines:<EOL><INDENT>return<EOL><DEDENT>max_lines = self.config.docstring_min_length<EOL>if node_type != "<STR_LIT>" and max_lines > -<NUM_LIT:1> and lines < max_lines:<EOL><INDENT>return<EOL><DEDENT>self.stats["<STR_LIT>" + node_type] += <NUM_LIT:1><EOL>if (<EOL>node.body<EOL>and isinstance(node.body[<NUM_LIT:0>], astroid.Expr)<EOL>and isinstance(node.body[<NUM_LIT:0>].value, astroid.Call)<EOL>):<EOL><INDENT>func = utils.safe_infer(node.body[<NUM_LIT:0>].value.func)<EOL>if isinstance(func, astroid.BoundMethod) and isinstance(<EOL>func.bound, astroid.Instance<EOL>):<EOL><INDENT>if PY3K and func.bound.name == "<STR_LIT:str>":<EOL><INDENT>return<EOL><DEDENT>if func.bound.name in ("<STR_LIT:str>", "<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>self.add_message(<EOL>"<STR_LIT>", node=node, args=(node_type,), confidence=confidence<EOL>)<EOL><DEDENT>elif not docstring.strip():<EOL><INDENT>self.stats["<STR_LIT>" + node_type] += <NUM_LIT:1><EOL>self.add_message(<EOL>"<STR_LIT>", node=node, args=(node_type,), confidence=confidence<EOL>)<EOL><DEDENT>

check the node has a non empty docstring


def _check_literal_comparison(self, literal, node):

nodes = (astroid.List, astroid.Tuple, astroid.Dict, astroid.Set)<EOL>is_other_literal = isinstance(literal, nodes)<EOL>is_const = False<EOL>if isinstance(literal, astroid.Const):<EOL><INDENT>if isinstance(literal.value, bool) or literal.value is None:<EOL><INDENT>return<EOL><DEDENT>is_const = isinstance(literal.value, (bytes, str, int, float))<EOL><DEDENT>if is_const or is_other_literal:<EOL><INDENT>self.add_message("<STR_LIT>", node=node)<EOL><DEDENT>

Check if we compare to a literal, which is usually what we do not want to do.


left_operand = node.left<EOL>right_operand = node.ops[<NUM_LIT:0>][<NUM_LIT:1>]<EOL>operator = node.ops[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>if isinstance(left_operand, astroid.Const) and isinstance(<EOL>right_operand, astroid.Const<EOL>):<EOL><INDENT>left_operand = left_operand.value<EOL>right_operand = right_operand.value<EOL><DEDENT>elif isinstance(left_operand, astroid.Name) and isinstance(<EOL>right_operand, astroid.Name<EOL>):<EOL><INDENT>left_operand = left_operand.name<EOL>right_operand = right_operand.name<EOL><DEDENT>if left_operand == right_operand:<EOL><INDENT>suggestion = "<STR_LIT>" % (left_operand, operator, right_operand)<EOL>self.add_message("<STR_LIT>", node=node, args=(suggestion,))<EOL><DEDENT>

Check if identifier is compared against itself.
        :param node: Compare node
        :type node: astroid.node_classes.Compare
        :Example:
        val = 786
        if val == val:  # [comparison-with-itself]
            pass


def _check_type_x_is_y(self, node, left, operator, right):

left_func = utils.safe_infer(left.func)<EOL>if not (<EOL>isinstance(left_func, astroid.ClassDef) and left_func.qname() == TYPE_QNAME<EOL>):<EOL><INDENT>return<EOL><DEDENT>if operator in ("<STR_LIT>", "<STR_LIT>") and _is_one_arg_pos_call(right):<EOL><INDENT>right_func = utils.safe_infer(right.func)<EOL>if (<EOL>isinstance(right_func, astroid.ClassDef)<EOL>and right_func.qname() == TYPE_QNAME<EOL>):<EOL><INDENT>right_arg = utils.safe_infer(right.args[<NUM_LIT:0>])<EOL>if not isinstance(right_arg, LITERAL_NODE_TYPES):<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>self.add_message("<STR_LIT>", node=node)<EOL>

Check for expressions like type(x) == Y.


if definition.kwargs:<EOL><INDENT>same_kw_variadics = definition.kwargs in call.starred_kws<EOL><DEDENT>else:<EOL><INDENT>same_kw_variadics = not call.starred_kws<EOL><DEDENT>if definition.varargs:<EOL><INDENT>same_args_variadics = definition.varargs in call.starred_args<EOL><DEDENT>else:<EOL><INDENT>same_args_variadics = not call.starred_args<EOL><DEDENT>same_kwonlyargs = all(kw in call.kws for kw in definition.kwonlyargs)<EOL>same_args = definition.args == call.args<EOL>no_additional_kwarg_arguments = True<EOL>if call.kws:<EOL><INDENT>for keyword in call.kws:<EOL><INDENT>is_arg = keyword in call.args<EOL>is_kwonly = keyword in definition.kwonlyargs<EOL>if not is_arg and not is_kwonly:<EOL><INDENT>no_additional_kwarg_arguments = False<EOL>break<EOL><DEDENT><DEDENT><DEDENT>return all(<EOL>(<EOL>same_args,<EOL>same_kwonlyargs,<EOL>same_args_variadics,<EOL>same_kw_variadics,<EOL>no_additional_kwarg_arguments,<EOL>)<EOL>)<EOL>

Check if a definition signature is equivalent to a call.


for potential_type in potential_types:<EOL><INDENT>if isinstance(node, potential_type):<EOL><INDENT>return potential_type<EOL><DEDENT><DEDENT>return None<EOL>

Return the type of the node if it exists in potential_types.

Args:
    node (astroid.node): node to get the type of.
    potential_types (tuple): potential types of the node.

Returns:
    type: type of the node or None.


def _check_arg_equality(node_a, node_b, attr_name):

return getattr(node_a, attr_name) == getattr(node_b, attr_name)<EOL>

Check equality of nodes based on the comparison of their attributes named attr_name.

Args:
    node_a (astroid.node): first node to compare.
    node_b (astroid.node): second node to compare.
    attr_name (str): name of the nodes attribute to use for comparison.

Returns:
    bool: True if node_a.attr_name == node_b.attr_name, False otherwise.


if original.args is None or overridden.args is None:<EOL><INDENT>return False<EOL><DEDENT>all_args = chain(original.args, original.kwonlyargs)<EOL>original_param_names = [param.name for param in all_args]<EOL>default_missing = object()<EOL>for param_name in original_param_names:<EOL><INDENT>try:<EOL><INDENT>original_default = original.default_value(param_name)<EOL><DEDENT>except astroid.exceptions.NoDefault:<EOL><INDENT>original_default = default_missing<EOL><DEDENT>try:<EOL><INDENT>overridden_default = overridden.default_value(param_name)<EOL><DEDENT>except astroid.exceptions.NoDefault:<EOL><INDENT>overridden_default = default_missing<EOL><DEDENT>default_list = [<EOL>arg == default_missing for arg in (original_default, overridden_default)<EOL>]<EOL>if any(default_list) and not all(default_list):<EOL><INDENT>return True<EOL><DEDENT>astroid_type_compared_attr = {<EOL>astroid.Const: "<STR_LIT:value>",<EOL>astroid.ClassDef: "<STR_LIT:name>",<EOL>astroid.Tuple: "<STR_LIT>",<EOL>astroid.List: "<STR_LIT>",<EOL>}<EOL>handled_types = tuple(<EOL>astroid_type for astroid_type in astroid_type_compared_attr<EOL>)<EOL>original_type = _get_node_type(original_default, handled_types)<EOL>if original_type:<EOL><INDENT>if not isinstance(overridden_default, original_type):<EOL><INDENT>return True<EOL><DEDENT>if not _check_arg_equality(<EOL>original_default,<EOL>overridden_default,<EOL>astroid_type_compared_attr[original_type],<EOL>):<EOL><INDENT>return True<EOL><DEDENT><DEDENT><DEDENT>return False<EOL>

Check if original and overridden methods arguments have different default values

Return True if one of the overridden arguments has a default
value different from the default value of the original argument
If one of the method doesn't have argument (.args is None)
return False


def _different_parameters(original, overridden, dummy_parameter_regex):

original_parameters = _positional_parameters(original)<EOL>overridden_parameters = _positional_parameters(overridden)<EOL>different_positional = _has_different_parameters(<EOL>original_parameters, overridden_parameters, dummy_parameter_regex<EOL>)<EOL>different_kwonly = _has_different_parameters(<EOL>original.args.kwonlyargs, overridden.args.kwonlyargs, dummy_parameter_regex<EOL>)<EOL>if original.name in PYMETHODS:<EOL><INDENT>different_positional = different_kwonly = False<EOL><DEDENT>different_kwarg = (<EOL>sum(<NUM_LIT:1> for param in (original.args.kwarg, overridden.args.kwarg) if not param)<EOL>== <NUM_LIT:1><EOL>)<EOL>different_vararg = (<EOL>sum(<NUM_LIT:1> for param in (original.args.vararg, overridden.args.vararg) if not param)<EOL>== <NUM_LIT:1><EOL>)<EOL>return any(<EOL>(different_positional, different_kwarg, different_vararg, different_kwonly)<EOL>)<EOL>

Determine if the two methods have different parameters

    They are considered to have different parameters if:

       * they have different positional parameters, including different names

       * one of the methods is having variadics, while the other is not

       * they have different keyword only parameters.


def _called_in_methods(func, klass, methods):

if not isinstance(func, astroid.FunctionDef):<EOL><INDENT>return False<EOL><DEDENT>for method in methods:<EOL><INDENT>try:<EOL><INDENT>infered = klass.getattr(method)<EOL><DEDENT>except astroid.NotFoundError:<EOL><INDENT>continue<EOL><DEDENT>for infer_method in infered:<EOL><INDENT>for call in infer_method.nodes_of_class(astroid.Call):<EOL><INDENT>try:<EOL><INDENT>bound = next(call.func.infer())<EOL><DEDENT>except (astroid.InferenceError, StopIteration):<EOL><INDENT>continue<EOL><DEDENT>if not isinstance(bound, astroid.BoundMethod):<EOL><INDENT>continue<EOL><DEDENT>func_obj = bound._proxied<EOL>if isinstance(func_obj, astroid.UnboundMethod):<EOL><INDENT>func_obj = func_obj._proxied<EOL><DEDENT>if func_obj.name == func.name:<EOL><INDENT>return True<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return False<EOL>

Check if the func was called in any of the given methods,
    belonging to the *klass*. Returns True if so, False otherwise.


try:<EOL><INDENT>attributes = klass.getattr(name)<EOL><DEDENT>except astroid.NotFoundError:<EOL><INDENT>return False<EOL><DEDENT>property_name = "<STR_LIT>".format(BUILTINS)<EOL>for attr in attributes:<EOL><INDENT>if attr is astroid.Uninferable:<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>infered = next(attr.infer())<EOL><DEDENT>except astroid.InferenceError:<EOL><INDENT>continue<EOL><DEDENT>if isinstance(infered, astroid.FunctionDef) and decorated_with_property(<EOL>infered<EOL>):<EOL><INDENT>return True<EOL><DEDENT>if infered.pytype() == property_name:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>

Check if the given attribute *name* is a property
    in the given *klass*.

    It will look for `property` calls or for functions
    with the given name, decorated by `property` or `property`
    subclasses.
    Returns ``True`` if the name is a property in the given klass,
    ``False`` otherwise.


def _safe_infer_call_result(node, caller, context=None):

try:<EOL><INDENT>inferit = node.infer_call_result(caller, context=context)<EOL>value = next(inferit)<EOL><DEDENT>except astroid.InferenceError:<EOL><INDENT>return None  <EOL><DEDENT>except StopIteration:<EOL><INDENT>return None  <EOL><DEDENT>try:<EOL><INDENT>next(inferit)<EOL>return None  <EOL><DEDENT>except astroid.InferenceError:<EOL><INDENT>return None  <EOL><DEDENT>except StopIteration:<EOL><INDENT>return value<EOL><DEDENT>

Safely infer the return value of a function.

Returns None if inference failed or if there is some ambiguity (more than
one node has been inferred). Otherwise returns infered value.


to_call = {}<EOL>for base_node in klass_node.ancestors(recurs=False):<EOL><INDENT>try:<EOL><INDENT>to_call[base_node] = next(base_node.igetattr(method))<EOL><DEDENT>except astroid.InferenceError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>return to_call<EOL>

return a dictionary where keys are the list of base classes providing
    the queried method, and so that should/may be called from the method node


linter.register_checker(ClassChecker(linter))<EOL>linter.register_checker(SpecialMethodsChecker(linter))<EOL>

required method to auto register this checker


frame = node_frame_class(node)<EOL>if frame is None:<EOL><INDENT>return<EOL><DEDENT>self._scopes[frame][node.attrname].append(node)<EOL>


return self._scopes.get(scope, {})<EOL>

Get the accessed variables for the given scope.


self._check_bases_classes(node)<EOL>if node.type == "<STR_LIT:class>" and has_known_bases(node):<EOL><INDENT>try:<EOL><INDENT>node.local_attr("<STR_LIT>")<EOL><DEDENT>except astroid.NotFoundError:<EOL><INDENT>self.add_message("<STR_LIT>", args=node, node=node)<EOL><DEDENT><DEDENT>self._check_slots(node)<EOL>self._check_proper_bases(node)<EOL>self._check_consistent_mro(node)<EOL>


try:<EOL><INDENT>node.mro()<EOL><DEDENT>except InconsistentMroError:<EOL><INDENT>self.add_message("<STR_LIT>", args=node.name, node=node)<EOL><DEDENT>except DuplicateBasesError:<EOL><INDENT>self.add_message("<STR_LIT>", args=node.name, node=node)<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>pass<EOL><DEDENT>

Detect that a class has a consistent mro or duplicate bases.


for base in node.bases:<EOL><INDENT>ancestor = safe_infer(base)<EOL>if ancestor in (astroid.Uninferable, None):<EOL><INDENT>continue<EOL><DEDENT>if isinstance(ancestor, astroid.Instance) and ancestor.is_subtype_of(<EOL>"<STR_LIT>" % (BUILTINS,)<EOL>):<EOL><INDENT>continue<EOL><DEDENT>if not isinstance(ancestor, astroid.ClassDef) or _is_invalid_base_class(<EOL>ancestor<EOL>):<EOL><INDENT>self.add_message("<STR_LIT>", args=base.as_string(), node=node)<EOL><DEDENT>if ancestor.name == object.__name__:<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", args=node.name, node=node<EOL>)<EOL><DEDENT><DEDENT>

Detect that a class inherits something which is not
a class or a type.


<EOL>if self._ignore_mixin and cnode.name[-<NUM_LIT:5>:].lower() == "<STR_LIT>":<EOL><INDENT>return<EOL><DEDENT>accessed = self._accessed.accessed(cnode)<EOL>if cnode.type != "<STR_LIT>":<EOL><INDENT>self._check_accessed_members(cnode, accessed)<EOL><DEDENT>if not self.linter.is_message_enabled("<STR_LIT>"):<EOL><INDENT>return<EOL><DEDENT>defining_methods = self.config.defining_attr_methods<EOL>current_module = cnode.root()<EOL>for attr, nodes in cnode.instance_attrs.items():<EOL><INDENT>nodes = [<EOL>n<EOL>for n in nodes<EOL>if not isinstance(n.statement(), (astroid.Delete, astroid.AugAssign))<EOL>and n.root() is current_module<EOL>]<EOL>if not nodes:<EOL><INDENT>continue  <EOL><DEDENT>if any(node.frame().name in defining_methods for node in nodes):<EOL><INDENT>continue<EOL><DEDENT>for parent in cnode.instance_attr_ancestors(attr):<EOL><INDENT>attr_defined = False<EOL>for node in parent.instance_attrs[attr]:<EOL><INDENT>if node.frame().name in defining_methods:<EOL><INDENT>attr_defined = True<EOL><DEDENT><DEDENT>if attr_defined:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>cnode.local_attr(attr)<EOL><DEDENT>except astroid.NotFoundError:<EOL><INDENT>for node in nodes:<EOL><INDENT>if node.frame().name not in defining_methods:<EOL><INDENT>if _called_in_methods(<EOL>node.frame(), cnode, defining_methods<EOL>):<EOL><INDENT>continue<EOL><DEDENT>self.add_message(<EOL>"<STR_LIT>", args=attr, node=node<EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>

close a class node:
        check that instance attributes are defined in __init__ and check
        access to existent members


<EOL>if not node.is_method():<EOL><INDENT>return<EOL><DEDENT>self._check_useless_super_delegation(node)<EOL>klass = node.parent.frame()<EOL>self._meth_could_be_func = True<EOL>self._check_first_arg_for_type(node, klass.type == "<STR_LIT>")<EOL>if node.name == "<STR_LIT>":<EOL><INDENT>self._check_init(node)<EOL>return<EOL><DEDENT>for overridden in klass.local_attr_ancestors(node.name):<EOL><INDENT>try:<EOL><INDENT>meth_node = overridden[node.name]<EOL><DEDENT>except KeyError:<EOL><INDENT>continue<EOL><DEDENT>if not isinstance(meth_node, astroid.FunctionDef):<EOL><INDENT>continue<EOL><DEDENT>self._check_signature(node, meth_node, "<STR_LIT>", klass)<EOL>break<EOL><DEDENT>if node.decorators:<EOL><INDENT>for decorator in node.decorators.nodes:<EOL><INDENT>if isinstance(decorator, astroid.Attribute) and decorator.attrname in (<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>):<EOL><INDENT>return<EOL><DEDENT>if isinstance(decorator, astroid.Name):<EOL><INDENT>if decorator.name == "<STR_LIT>":<EOL><INDENT>return<EOL><DEDENT><DEDENT>inferred = safe_infer(decorator)<EOL>if not inferred:<EOL><INDENT>return<EOL><DEDENT>if isinstance(inferred, astroid.FunctionDef):<EOL><INDENT>try:<EOL><INDENT>inferred = next(inferred.infer_call_result(inferred))<EOL><DEDENT>except astroid.InferenceError:<EOL><INDENT>return<EOL><DEDENT><DEDENT>try:<EOL><INDENT>if (<EOL>isinstance(inferred, (astroid.Instance, astroid.ClassDef))<EOL>and inferred.getattr("<STR_LIT>")<EOL>and inferred.getattr("<STR_LIT>")<EOL>):<EOL><INDENT>return<EOL><DEDENT><DEDENT>except astroid.AttributeInferenceError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>overridden = klass.instance_attr(node.name)[<NUM_LIT:0>]  <EOL>overridden_frame = overridden.frame()<EOL>if (<EOL>isinstance(overridden_frame, astroid.FunctionDef)<EOL>and overridden_frame.type == "<STR_LIT>"<EOL>):<EOL><INDENT>overridden_frame = overridden_frame.parent.frame()<EOL><DEDENT>if isinstance(overridden_frame, astroid.ClassDef) and klass.is_subtype_of(<EOL>overridden_frame.qname()<EOL>):<EOL><INDENT>args = (overridden.root().name, overridden.fromlineno)<EOL>self.add_message("<STR_LIT>", args=args, node=node)<EOL><DEDENT><DEDENT>except astroid.NotFoundError:<EOL><INDENT>pass<EOL><DEDENT>


if (<EOL>not function.is_method()<EOL>or function.decorators<EOL>):<EOL><INDENT>return<EOL><DEDENT>body = function.body<EOL>if len(body) != <NUM_LIT:1>:<EOL><INDENT>return<EOL><DEDENT>statement = body[<NUM_LIT:0>]<EOL>if not isinstance(statement, (astroid.Expr, astroid.Return)):<EOL><INDENT>return<EOL><DEDENT>call = statement.value<EOL>if (<EOL>not isinstance(call, astroid.Call)<EOL>or not isinstance(call.func, astroid.Attribute)<EOL>):<EOL><INDENT>return<EOL><DEDENT>try:<EOL><INDENT>super_call = next(call.func.expr.infer())<EOL><DEDENT>except astroid.InferenceError:<EOL><INDENT>return<EOL><DEDENT>else:<EOL><INDENT>if not isinstance(super_call, objects.Super):<EOL><INDENT>return<EOL><DEDENT><DEDENT>if call.func.attrname != function.name:<EOL><INDENT>return<EOL><DEDENT>current_scope = function.parent.scope()<EOL>if (<EOL>super_call.mro_pointer != current_scope<EOL>or not isinstance(super_call.type, astroid.Instance)<EOL>or super_call.type.name != current_scope.name<EOL>):<EOL><INDENT>return<EOL><DEDENT>klass = function.parent.frame()<EOL>meth_node = None<EOL>for overridden in klass.local_attr_ancestors(function.name):<EOL><INDENT>try:<EOL><INDENT>meth_node = overridden[function.name]<EOL><DEDENT>except KeyError:<EOL><INDENT>continue<EOL><DEDENT>if (<EOL>not isinstance(meth_node, astroid.FunctionDef)<EOL>or _has_different_parameters_default_value(<EOL>meth_node.args, function.args<EOL>)<EOL>):<EOL><INDENT>return<EOL><DEDENT>break<EOL><DEDENT>params = _signature_from_arguments(function.args)<EOL>args = _signature_from_call(call)<EOL>if meth_node is not None:<EOL><INDENT>def form_annotations(annotations):<EOL><INDENT>return [<EOL>annotation.as_string() for annotation in filter(None, annotations)<EOL>]<EOL><DEDENT>called_annotations = form_annotations(function.args.annotations)<EOL>overridden_annotations = form_annotations(meth_node.args.annotations)<EOL>if called_annotations and overridden_annotations:<EOL><INDENT>if called_annotations != overridden_annotations:<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>if _definition_equivalent_to_call(params, args):<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", node=function, args=(function.name,)<EOL>)<EOL><DEDENT>

Check if the given function node is an useless method override

        We consider it *useless* if it uses the super() builtin, but having
        nothing additional whatsoever than not implementing the method at all.
        If the method uses super() to delegate an operation to the rest of the MRO,
        and if the method called is the same as the current one, the arguments
        passed to super() are the same as the parameters that were passed to
        this method, then the method could be removed altogether, by letting
        other implementation to take precedence.


if node.is_method():<EOL><INDENT>if node.args.args is not None:<EOL><INDENT>self._first_attrs.pop()<EOL><DEDENT>if not self.linter.is_message_enabled("<STR_LIT>"):<EOL><INDENT>return<EOL><DEDENT>class_node = node.parent.frame()<EOL>if (<EOL>self._meth_could_be_func<EOL>and node.type == "<STR_LIT>"<EOL>and node.name not in PYMETHODS<EOL>and not (<EOL>node.is_abstract()<EOL>or overrides_a_method(class_node, node.name)<EOL>or decorated_with_property(node)<EOL>or _has_bare_super_call(node)<EOL>)<EOL>):<EOL><INDENT>self.add_message("<STR_LIT>", node=node)<EOL><DEDENT><DEDENT>

on method node, check if this method couldn't be a function

        ignore class, static and abstract methods, initializer,
        methods overridden from a parent class.


check if the getattr is an access to a class member
        if so, register it. Also check for access to protected
        class member from outside its class (but ignore __special__
        methods)


inferred = safe_infer(node.expr)<EOL>if not isinstance(inferred, astroid.Instance):<EOL><INDENT>return<EOL><DEDENT>klass = inferred._proxied<EOL>if not has_known_bases(klass):<EOL><INDENT>return<EOL><DEDENT>if "<STR_LIT>" not in klass.locals or not klass.newstyle:<EOL><INDENT>return<EOL><DEDENT>slots = klass.slots()<EOL>if slots is None:<EOL><INDENT>return<EOL><DEDENT>if any(<EOL>"<STR_LIT>" not in ancestor.locals and ancestor.name != "<STR_LIT:object>"<EOL>for ancestor in klass.ancestors()<EOL>):<EOL><INDENT>return<EOL><DEDENT>if not any(slot.value == node.attrname for slot in slots):<EOL><INDENT>if not any(slot.value == "<STR_LIT>" for slot in slots):<EOL><INDENT>if _is_attribute_property(node.attrname, klass):<EOL><INDENT>return<EOL><DEDENT>if node.attrname in klass.locals and _has_data_descriptor(<EOL>klass, node.attrname<EOL>):<EOL><INDENT>return<EOL><DEDENT>if node.attrname == "<STR_LIT>" and _has_same_layout_slots(<EOL>slots, node.parent.value<EOL>):<EOL><INDENT>return<EOL><DEDENT>self.add_message("<STR_LIT>", args=(node.attrname,), node=node)<EOL><DEDENT><DEDENT>

Check that the given AssignAttr node
        is defined in the class slots.


if not isinstance(node.value, astroid.Call):<EOL><INDENT>return<EOL><DEDENT>func = node.value.func<EOL>if not isinstance(func, astroid.Name) or func.name not in (<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>):<EOL><INDENT>return<EOL><DEDENT>msg = (<EOL>"<STR_LIT>"<EOL>if func.name == "<STR_LIT>"<EOL>else "<STR_LIT>"<EOL>)<EOL>parent_class = node.scope()<EOL>if not isinstance(parent_class, astroid.ClassDef):<EOL><INDENT>return<EOL><DEDENT>classmeth_arg = node.value.args[<NUM_LIT:0>]<EOL>if not isinstance(classmeth_arg, astroid.Name):<EOL><INDENT>return<EOL><DEDENT>method_name = classmeth_arg.name<EOL>if any(method_name == member.name for member in parent_class.mymethods()):<EOL><INDENT>self.add_message(msg, node=node.targets[<NUM_LIT:0>])<EOL><DEDENT>

Checks for uses of classmethod() or staticmethod()

        When a @classmethod or @staticmethod decorator should be used instead.
        A message will be emitted only if the assignment is at a class scope
        and only if the classmethod's argument belongs to the class where it
        is defined.
        `node` is an assign node.


attrname = node.attrname<EOL>if (<EOL>is_attr_protected(attrname)<EOL>and attrname not in self.config.exclude_protected<EOL>):<EOL><INDENT>klass = node_frame_class(node)<EOL>callee = node.expr.as_string()<EOL>if klass is None:<EOL><INDENT>self.add_message("<STR_LIT>", node=node, args=attrname)<EOL>return<EOL><DEDENT>if (<EOL>isinstance(node.expr, astroid.Call)<EOL>and isinstance(node.expr.func, astroid.Name)<EOL>and node.expr.func.name == "<STR_LIT>"<EOL>):<EOL><INDENT>return<EOL><DEDENT>if self._is_type_self_call(node.expr):<EOL><INDENT>return<EOL><DEDENT>if not (callee == klass.name or callee in klass.basenames):<EOL><INDENT>stmt = node.parent.statement()<EOL>if (<EOL>isinstance(stmt, astroid.Assign)<EOL>and len(stmt.targets) == <NUM_LIT:1><EOL>and isinstance(stmt.targets[<NUM_LIT:0>], astroid.AssignName)<EOL>):<EOL><INDENT>name = stmt.targets[<NUM_LIT:0>].name<EOL>if _is_attribute_property(name, klass):<EOL><INDENT>return<EOL><DEDENT><DEDENT>self.add_message("<STR_LIT>", node=node, args=attrname)<EOL><DEDENT><DEDENT>

Given an attribute access node (set or get), check if attribute
        access is legitimate. Call _check_first_attr with node before calling
        this method. Valid cases are:
        * self._attr in a method or cls._attr in a classmethod. Checked by
        _check_first_attr.
        * Klass._attr inside "Klass" class.
        * Klass2._attr inside "Klass" class when Klass2 is a base class of
            Klass.


if self._first_attrs and (<EOL>node.name == self._first_attrs[-<NUM_LIT:1>] or not self._first_attrs[-<NUM_LIT:1>]<EOL>):<EOL><INDENT>self._meth_could_be_func = False<EOL><DEDENT>

check if the name handle an access to a class member
        if so, register it


def _check_accessed_members(self, node, accessed):

<EOL>excs = ("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>for attr, nodes in accessed.items():<EOL><INDENT>try:<EOL><INDENT>node.local_attr(attr)<EOL>continue<EOL><DEDENT>except astroid.NotFoundError:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>next(node.instance_attr_ancestors(attr))<EOL>continue<EOL><DEDENT>except StopIteration:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>defstmts = node.instance_attr(attr)<EOL><DEDENT>except astroid.NotFoundError:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>defstmts = [stmt for stmt in defstmts if stmt not in nodes]<EOL>if not defstmts:<EOL><INDENT>continue<EOL><DEDENT>scope = defstmts[<NUM_LIT:0>].scope()<EOL>defstmts = [<EOL>stmt<EOL>for i, stmt in enumerate(defstmts)<EOL>if i == <NUM_LIT:0> or stmt.scope() is not scope<EOL>]<EOL>if len(defstmts) == <NUM_LIT:1>:<EOL><INDENT>defstmt = defstmts[<NUM_LIT:0>]<EOL>frame = defstmt.frame()<EOL>lno = defstmt.fromlineno<EOL>for _node in nodes:<EOL><INDENT>if (<EOL>_node.frame() is frame<EOL>and _node.fromlineno < lno<EOL>and not astroid.are_exclusive(<EOL>_node.statement(), defstmt, excs<EOL>)<EOL>):<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>",<EOL>node=_node,<EOL>args=(attr, lno),<EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>


def _check_first_arg_for_type(self, node, metaclass=<NUM_LIT:0>):

<EOL>if node.args.args is None:<EOL><INDENT>return<EOL><DEDENT>first_arg = node.args.args and node.argnames()[<NUM_LIT:0>]<EOL>self._first_attrs.append(first_arg)<EOL>first = self._first_attrs[-<NUM_LIT:1>]<EOL>if node.type == "<STR_LIT>":<EOL><INDENT>if (<EOL>first_arg == "<STR_LIT>"<EOL>or first_arg in self.config.valid_classmethod_first_arg<EOL>or first_arg in self.config.valid_metaclass_classmethod_first_arg<EOL>):<EOL><INDENT>self.add_message("<STR_LIT>", args=first, node=node)<EOL>return<EOL><DEDENT>self._first_attrs[-<NUM_LIT:1>] = None<EOL><DEDENT>elif not node.args.args:<EOL><INDENT>self.add_message("<STR_LIT>", node=node)<EOL><DEDENT>elif metaclass:<EOL><INDENT>if node.type == "<STR_LIT>":<EOL><INDENT>self._check_first_arg_config(<EOL>first,<EOL>self.config.valid_metaclass_classmethod_first_arg,<EOL>node,<EOL>"<STR_LIT>",<EOL>node.name,<EOL>)<EOL><DEDENT>else:<EOL><INDENT>self._check_first_arg_config(<EOL>first,<EOL>self.config.valid_classmethod_first_arg,<EOL>node,<EOL>"<STR_LIT>",<EOL>node.name,<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if node.type == "<STR_LIT>" or node.name == "<STR_LIT>":<EOL><INDENT>self._check_first_arg_config(<EOL>first,<EOL>self.config.valid_classmethod_first_arg,<EOL>node,<EOL>"<STR_LIT>",<EOL>node.name,<EOL>)<EOL><DEDENT>elif first != "<STR_LIT>":<EOL><INDENT>self.add_message("<STR_LIT>", node=node)<EOL><DEDENT><DEDENT>

check the name of first argument, expect:

        * 'self' for a regular method
        * 'cls' for a class method or a metaclass regular method (actually
          valid-classmethod-first-arg value)
        * 'mcs' for a metaclass class method (actually
          valid-metaclass-classmethod-first-arg)
        * not one of the above for a static method


def is_abstract(method):<EOL><INDENT>return method.is_abstract(pass_is_abstract=False)<EOL><DEDENT>if class_is_abstract(node):<EOL><INDENT>return<EOL><DEDENT>methods = sorted(<EOL>unimplemented_abstract_methods(node, is_abstract).items(),<EOL>key=lambda item: item[<NUM_LIT:0>],<EOL>)<EOL>for name, method in methods:<EOL><INDENT>owner = method.parent.frame()<EOL>if owner is node:<EOL><INDENT>continue<EOL><DEDENT>if name in node.locals:<EOL><INDENT>continue<EOL><DEDENT>self.add_message("<STR_LIT>", node=node, args=(name, owner.name))<EOL><DEDENT>

check that the given class node implements abstract methods from
        base classes


if not self.linter.is_message_enabled(<EOL>"<STR_LIT>"<EOL>) and not self.linter.is_message_enabled("<STR_LIT>"):<EOL><INDENT>return<EOL><DEDENT>klass_node = node.parent.frame()<EOL>to_call = _ancestors_to_call(klass_node)<EOL>not_called_yet = dict(to_call)<EOL>for stmt in node.nodes_of_class(astroid.Call):<EOL><INDENT>expr = stmt.func<EOL>if not isinstance(expr, astroid.Attribute) or expr.attrname != "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>if (<EOL>isinstance(expr.expr, astroid.Call)<EOL>and isinstance(expr.expr.func, astroid.Name)<EOL>and expr.expr.func.name == "<STR_LIT>"<EOL>):<EOL><INDENT>return<EOL><DEDENT>try:<EOL><INDENT>for klass in expr.expr.infer():<EOL><INDENT>if klass is astroid.Uninferable:<EOL><INDENT>continue<EOL><DEDENT>if (<EOL>isinstance(klass, astroid.Instance)<EOL>and isinstance(klass._proxied, astroid.ClassDef)<EOL>and is_builtin_object(klass._proxied)<EOL>and klass._proxied.name == "<STR_LIT>"<EOL>):<EOL><INDENT>return<EOL><DEDENT>if isinstance(klass, objects.Super):<EOL><INDENT>return<EOL><DEDENT>try:<EOL><INDENT>del not_called_yet[klass]<EOL><DEDENT>except KeyError:<EOL><INDENT>if klass not in to_call:<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", node=expr, args=klass.name<EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except astroid.InferenceError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>for klass, method in not_called_yet.items():<EOL><INDENT>cls = node_frame_class(method)<EOL>if klass.name == "<STR_LIT:object>" or (cls and cls.name == "<STR_LIT:object>"):<EOL><INDENT>continue<EOL><DEDENT>self.add_message("<STR_LIT>", args=klass.name, node=node)<EOL><DEDENT>

check that the __init__ method call super or ancestors'__init__
        method


def _check_signature(self, method1, refmethod, class_type, cls):

if not (<EOL>isinstance(method1, astroid.FunctionDef)<EOL>and isinstance(refmethod, astroid.FunctionDef)<EOL>):<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", args=(method1, refmethod), node=method1<EOL>)<EOL>return<EOL><DEDENT>instance = cls.instantiate_class()<EOL>method1 = function_to_method(method1, instance)<EOL>refmethod = function_to_method(refmethod, instance)<EOL>if method1.args.args is None or refmethod.args.args is None:<EOL><INDENT>return<EOL><DEDENT>if is_attr_private(method1.name):<EOL><INDENT>return<EOL><DEDENT>if method1.decorators:<EOL><INDENT>for decorator in method1.decorators.nodes:<EOL><INDENT>if (<EOL>isinstance(decorator, astroid.Attribute)<EOL>and decorator.attrname == "<STR_LIT>"<EOL>):<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>if _different_parameters(<EOL>refmethod, method1, dummy_parameter_regex=self._dummy_rgx<EOL>):<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", args=(class_type, method1.name), node=method1<EOL>)<EOL><DEDENT>elif len(method1.args.defaults) < len(refmethod.args.defaults):<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", args=(class_type, method1.name), node=method1<EOL>)<EOL><DEDENT>

check that the signature of the two given methods match


return self._is_mandatory_method_param(node.expr)<EOL>

Check that attribute lookup name use first attribute variable name

        Name is `self` for method, `cls` for classmethod and `mcs` for metaclass.


return (<EOL>self._first_attrs<EOL>and isinstance(node, astroid.Name)<EOL>and node.name == self._first_attrs[-<NUM_LIT:1>]<EOL>)<EOL>

Check if astroid.Name corresponds to first attribute variable name

        Name is `self` for method, `cls` for classmethod and `mcs` for metaclass.


linter.register_checker(AsyncChecker(linter))<EOL>

required method to auto register this checker


linter.register_checker(SpellingChecker(linter))<EOL>


docstring = node.doc<EOL>if not docstring:<EOL><INDENT>return<EOL><DEDENT>start_line = node.lineno + <NUM_LIT:1><EOL>for idx, line in enumerate(docstring.splitlines()):<EOL><INDENT>self._check_spelling("<STR_LIT>", line, start_line + idx)<EOL><DEDENT>


def table_lines_from_stats(stats, _, columns):

lines = []<EOL>for m_type in columns:<EOL><INDENT>new = stats[m_type]<EOL>new = "<STR_LIT>" % new if isinstance(new, float) else str(new)<EOL>lines += (m_type.replace("<STR_LIT:_>", "<STR_LIT:U+0020>"), new, "<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>return lines<EOL>

get values listed in <columns> from <stats> and <old_stats>,
    and return a formated list of values, designed to be given to a
    ureport.Table object


register_plugins(linter, __path__[<NUM_LIT:0>])<EOL>

initialize linter with checkers in this package


result = "<STR_LIT>"<EOL>for char in line:<EOL><INDENT>if char in "<STR_LIT>":<EOL><INDENT>result += char<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return result<EOL>

Return the indention string of the given line.


result = <NUM_LIT:0><EOL>for char in line:<EOL><INDENT>if char == "<STR_LIT:U+0020>":<EOL><INDENT>result += <NUM_LIT:1><EOL><DEDENT>elif char == "<STR_LIT:\t>":<EOL><INDENT>result += _TAB_LENGTH<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return result<EOL>

Return the length of the indentation on the given token's line.


if not bar_positions:<EOL><INDENT>return ("<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>bar_positions = [_get_indent_length(indent) for indent in bar_positions]<EOL>bad_position = _get_indent_length(bad_position)<EOL>delta_message = "<STR_LIT>"<EOL>markers = [(pos, "<STR_LIT:|>") for pos in bar_positions]<EOL>if len(markers) == <NUM_LIT:1>:<EOL><INDENT>expected_position = markers[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>delta = abs(expected_position - bad_position)<EOL>direction = "<STR_LIT>" if expected_position > bad_position else "<STR_LIT>"<EOL>delta_message = _CONTINUATION_HINT_MESSAGE % (<EOL>direction,<EOL>delta,<EOL>"<STR_LIT:s>" if delta > <NUM_LIT:1> else "<STR_LIT>",<EOL>)<EOL><DEDENT>markers.append((bad_position, "<STR_LIT>"))<EOL>markers.sort()<EOL>line = ["<STR_LIT:U+0020>"] * (markers[-<NUM_LIT:1>][<NUM_LIT:0>] + <NUM_LIT:1>)<EOL>for position, marker in markers:<EOL><INDENT>line[position] = marker<EOL><DEDENT>return ("<STR_LIT>".join(line), delta_message)<EOL>

Return a line with |s for each of the positions in the given lists.


return {a: None for a in args}<EOL>

Valid indentation strings for a continued line.


return {single: SINGLE_LINE, with_body: WITH_BODY}<EOL>

Valid alternative indentation strings for continued lines before blocks.

    :param int single: Valid indentation string for statements on a single logical line.
    :param int with_body: Valid indentation string for statements on several lines.

    :returns: A dictionary mapping indent offsets to a string representing
        whether the indent if for a line or block.
    :rtype: dict


linter.register_checker(FormatChecker(linter))<EOL>


return _get_indent_string(self.line(idx))<EOL>

Get the string of TABs and Spaces used for indentation of the line of this token


line_indent = self.line_indent(idx)<EOL>return line_indent + "<STR_LIT:U+0020>" * (self.start_col(idx) - len(line_indent))<EOL>

Get an indentation string for hanging indentation, consisting of the line-indent plus
        a number of spaces to fill up to the column of this token.

        e.g. the token indent for foo
        in "<TAB><TAB>print(foo)"
        is "<TAB><TAB>      "


if self._line_start > -<NUM_LIT:1>:<EOL><INDENT>return<EOL><DEDENT>check_token_position = pos<EOL>if self._tokens.token(pos) == _ASYNC_TOKEN:<EOL><INDENT>check_token_position += <NUM_LIT:1><EOL><DEDENT>self._is_block_opener = (<EOL>self._tokens.token(check_token_position) in _CONTINUATION_BLOCK_OPENERS<EOL>)<EOL>self._line_start = pos<EOL>

Record the first non-junk token at the start of a line.


self._line_start = -<NUM_LIT:1><EOL>self._is_block_opener = False<EOL>

Prepares the tracker for a new physical line (NL).


self.next_physical_line()<EOL>self.retained_warnings = []<EOL>self._cont_stack = []<EOL>

Prepares the tracker for a new logical line (NEWLINE).

        A new logical line only starts with block indentation.


<EOL>stack_top = -<NUM_LIT:1><EOL>if (<EOL>self._tokens.token(idx) in ("<STR_LIT:}>", "<STR_LIT>")<EOL>and self._cont_stack[-<NUM_LIT:1>].token == "<STR_LIT::>"<EOL>):<EOL><INDENT>stack_top = -<NUM_LIT:2><EOL><DEDENT>indent = self._cont_stack[stack_top]<EOL>if self._tokens.token(idx) in _CLOSING_BRACKETS:<EOL><INDENT>valid_indentations = indent.valid_outdent_strings<EOL><DEDENT>else:<EOL><INDENT>valid_indentations = indent.valid_continuation_strings<EOL><DEDENT>return indent, valid_indentations.copy()<EOL>

Returns the valid offsets for the token at the given position.


def _hanging_indent_after_bracket(self, bracket, position):

indentation = self._tokens.line_indent(position)<EOL>if (<EOL>self._is_block_opener<EOL>and self._continuation_string == self._block_indent_string<EOL>):<EOL><INDENT>return _ContinuedIndent(<EOL>HANGING_BLOCK,<EOL>bracket,<EOL>position,<EOL>_Indentations(indentation + self._continuation_string, indentation),<EOL>_BeforeBlockIndentations(<EOL>indentation + self._continuation_string,<EOL>indentation + self._continuation_string * <NUM_LIT:2>,<EOL>),<EOL>)<EOL><DEDENT>if bracket == "<STR_LIT::>":<EOL><INDENT>paren_align = self._cont_stack[-<NUM_LIT:1>].valid_outdent_strings<EOL>next_align = self._cont_stack[-<NUM_LIT:1>].valid_continuation_strings.copy()<EOL>next_align_keys = list(next_align.keys())<EOL>next_align[next_align_keys[<NUM_LIT:0>] + self._continuation_string] = True<EOL>return _ContinuedIndent(<EOL>HANGING_DICT_VALUE, bracket, position, paren_align, next_align<EOL>)<EOL><DEDENT>return _ContinuedIndent(<EOL>HANGING,<EOL>bracket,<EOL>position,<EOL>_Indentations(indentation, indentation + self._continuation_string),<EOL>_Indentations(indentation + self._continuation_string),<EOL>)<EOL>

Extracts indentation information for a hanging indent

        Case of hanging indent after a bracket (including parenthesis)

        :param str bracket: bracket in question
        :param int position: Position of bracket in self._tokens

        :returns: the state and valid positions for hanging indentation
        :rtype: _ContinuedIndent


def _continuation_inside_bracket(self, bracket, position):

indentation = self._tokens.line_indent(position)<EOL>token_indent = self._tokens.token_indent(position)<EOL>next_token_indent = self._tokens.token_indent(position + <NUM_LIT:1>)<EOL>if (<EOL>self._is_block_opener<EOL>and next_token_indent == indentation + self._block_indent_string<EOL>):<EOL><INDENT>return _ContinuedIndent(<EOL>CONTINUED_BLOCK,<EOL>bracket,<EOL>position,<EOL>_Indentations(token_indent),<EOL>_BeforeBlockIndentations(<EOL>next_token_indent, next_token_indent + self._continuation_string<EOL>),<EOL>)<EOL><DEDENT>return _ContinuedIndent(<EOL>CONTINUED,<EOL>bracket,<EOL>position,<EOL>_Indentations(token_indent, next_token_indent),<EOL>_Indentations(next_token_indent),<EOL>)<EOL>

Extracts indentation information for a continued indent.


Pushes a new token for continued indentation on the stack.

        Tokens that can modify continued indentation offsets are:
          * opening brackets
          * 'lambda'
          * : inside dictionaries

        push_token relies on the caller to filter out those
        interesting tokens.

        :param int token: The concrete token
        :param int position: The position of the token in the stream.


def new_line(self, tokens, line_end, line_start):

if _last_token_on_line_is(tokens, line_end, "<STR_LIT:;>"):<EOL><INDENT>self.add_message("<STR_LIT>", line=tokens.start_line(line_end))<EOL><DEDENT>line_num = tokens.start_line(line_start)<EOL>line = tokens.line(line_start)<EOL>if tokens.type(line_start) not in _JUNK_TOKENS:<EOL><INDENT>self._lines[line_num] = line.split("<STR_LIT:\n>")[<NUM_LIT:0>]<EOL><DEDENT>self.check_lines(line, line_num)<EOL>

a new line has been encountered, process it if necessary


def _check_keyword_parentheses(self, tokens, start):

<EOL>if self._inside_brackets("<STR_LIT::>") and tokens[start][<NUM_LIT:1>] == "<STR_LIT>":<EOL><INDENT>self._pop_token()<EOL><DEDENT>if tokens[start + <NUM_LIT:1>][<NUM_LIT:1>] != "<STR_LIT:(>":<EOL><INDENT>return<EOL><DEDENT>found_and_or = False<EOL>depth = <NUM_LIT:0><EOL>keyword_token = str(tokens[start][<NUM_LIT:1>])<EOL>line_num = tokens[start][<NUM_LIT:2>][<NUM_LIT:0>]<EOL>for i in range(start, len(tokens) - <NUM_LIT:1>):<EOL><INDENT>token = tokens[i]<EOL>if token[<NUM_LIT:0>] == tokenize.NL:<EOL><INDENT>return<EOL><DEDENT>if token[<NUM_LIT:1>] == "<STR_LIT:(>":<EOL><INDENT>depth += <NUM_LIT:1><EOL><DEDENT>elif token[<NUM_LIT:1>] == "<STR_LIT:)>":<EOL><INDENT>depth -= <NUM_LIT:1><EOL>if depth:<EOL><INDENT>continue<EOL><DEDENT>if tokens[i + <NUM_LIT:1>][<NUM_LIT:1>] in ("<STR_LIT::>", "<STR_LIT:)>", "<STR_LIT:]>", "<STR_LIT:}>", "<STR_LIT>") or tokens[i + <NUM_LIT:1>][<EOL><NUM_LIT:0><EOL>] in (tokenize.NEWLINE, tokenize.ENDMARKER, tokenize.COMMENT):<EOL><INDENT>if i == start + <NUM_LIT:2>:<EOL><INDENT>return<EOL><DEDENT>if keyword_token == "<STR_LIT>":<EOL><INDENT>if not found_and_or:<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", line=line_num, args=keyword_token<EOL>)<EOL><DEDENT><DEDENT>elif keyword_token in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", line=line_num, args=keyword_token<EOL>)<EOL><DEDENT>elif keyword_token not in self._keywords_with_parens:<EOL><INDENT>if not found_and_or:<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", line=line_num, args=keyword_token<EOL>)<EOL><DEDENT><DEDENT><DEDENT>return<EOL><DEDENT>elif depth == <NUM_LIT:1>:<EOL><INDENT>if token[<NUM_LIT:1>] == "<STR_LIT:U+002C>":<EOL><INDENT>return<EOL><DEDENT>if token[<NUM_LIT:1>] in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>found_and_or = True<EOL><DEDENT>elif token[<NUM_LIT:1>] == "<STR_LIT>":<EOL><INDENT>return<EOL><DEDENT>elif token[<NUM_LIT:1>] == "<STR_LIT>":<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>

Check that there are not unnecessary parens after a keyword.

        Parens are unnecessary if there is exactly one balanced outer pair on a
        line, and it is followed by a colon, and contains no commas (i.e. is not a
        tuple).

        Args:
        tokens: list of Tokens; the entire list of Tokens.
        start: int; the position of the keyword in the token list.


def _has_valid_type_annotation(self, tokens, i):

if not self._inside_brackets("<STR_LIT:(>"):<EOL><INDENT>return False<EOL><DEDENT>bracket_level = <NUM_LIT:0><EOL>for token in tokens[i - <NUM_LIT:1> :: -<NUM_LIT:1>]:<EOL><INDENT>if token[<NUM_LIT:1>] == "<STR_LIT::>":<EOL><INDENT>return True<EOL><DEDENT>if token[<NUM_LIT:1>] == "<STR_LIT:(>":<EOL><INDENT>return False<EOL><DEDENT>if token[<NUM_LIT:1>] == "<STR_LIT:]>":<EOL><INDENT>bracket_level += <NUM_LIT:1><EOL><DEDENT>elif token[<NUM_LIT:1>] == "<STR_LIT:[>":<EOL><INDENT>bracket_level -= <NUM_LIT:1><EOL><DEDENT>elif token[<NUM_LIT:1>] == "<STR_LIT:U+002C>":<EOL><INDENT>if not bracket_level:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>elif token[<NUM_LIT:1>] in ("<STR_LIT:.>", "<STR_LIT>"):<EOL><INDENT>continue<EOL><DEDENT>elif token[<NUM_LIT:0>] not in (tokenize.NAME, tokenize.STRING, tokenize.NL):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return False<EOL>

Extended check of PEP-484 type hint presence


def _check_equals_spacing(self, tokens, i):

if self._has_valid_type_annotation(tokens, i):<EOL><INDENT>self._check_space(tokens, i, (_MUST, _MUST))<EOL><DEDENT>elif self._inside_brackets("<STR_LIT:(>") or self._inside_brackets("<STR_LIT>"):<EOL><INDENT>self._check_space(tokens, i, (_MUST_NOT, _MUST_NOT))<EOL><DEDENT>else:<EOL><INDENT>self._check_space(tokens, i, (_MUST, _MUST))<EOL><DEDENT>

Check the spacing of a single equals sign.


def _check_surrounded_by_space(self, tokens, i):

self._check_space(tokens, i, (_MUST, _MUST))<EOL>

Check that a binary operator is surrounded by exactly one space.


self._bracket_stack = [None]<EOL>indents = [<NUM_LIT:0>]<EOL>check_equal = False<EOL>line_num = <NUM_LIT:0><EOL>self._lines = {}<EOL>self._visited_lines = {}<EOL>token_handlers = self._prepare_token_dispatcher()<EOL>self._last_line_ending = None<EOL>last_blank_line_num = <NUM_LIT:0><EOL>self._current_line = ContinuedLineState(tokens, self.config)<EOL>for idx, (tok_type, token, start, _, line) in enumerate(tokens):<EOL><INDENT>if start[<NUM_LIT:0>] != line_num:<EOL><INDENT>line_num = start[<NUM_LIT:0>]<EOL>if tok_type == tokenize.INDENT:<EOL><INDENT>self.new_line(TokenWrapper(tokens), idx - <NUM_LIT:1>, idx + <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>self.new_line(TokenWrapper(tokens), idx - <NUM_LIT:1>, idx)<EOL><DEDENT><DEDENT>if tok_type == tokenize.NEWLINE:<EOL><INDENT>check_equal = True<EOL>self._process_retained_warnings(TokenWrapper(tokens), idx)<EOL>self._current_line.next_logical_line()<EOL>self._check_line_ending(token, line_num)<EOL><DEDENT>elif tok_type == tokenize.INDENT:<EOL><INDENT>check_equal = False<EOL>self.check_indent_level(token, indents[-<NUM_LIT:1>] + <NUM_LIT:1>, line_num)<EOL>indents.append(indents[-<NUM_LIT:1>] + <NUM_LIT:1>)<EOL><DEDENT>elif tok_type == tokenize.DEDENT:<EOL><INDENT>check_equal = True<EOL>if len(indents) > <NUM_LIT:1>:<EOL><INDENT>del indents[-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>elif tok_type == tokenize.NL:<EOL><INDENT>if not line.strip("<STR_LIT:\r\n>"):<EOL><INDENT>last_blank_line_num = line_num<EOL><DEDENT>self._check_continued_indentation(TokenWrapper(tokens), idx + <NUM_LIT:1>)<EOL>self._current_line.next_physical_line()<EOL><DEDENT>elif tok_type not in (tokenize.COMMENT, tokenize.ENCODING):<EOL><INDENT>self._current_line.handle_line_start(idx)<EOL>if check_equal:<EOL><INDENT>check_equal = False<EOL>self.check_indent_level(line, indents[-<NUM_LIT:1>], line_num)<EOL><DEDENT><DEDENT>if tok_type == tokenize.NUMBER and token.endswith("<STR_LIT:l>"):<EOL><INDENT>self.add_message("<STR_LIT>", line=line_num)<EOL><DEDENT>try:<EOL><INDENT>handler = token_handlers[token]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>handler(tokens, idx)<EOL><DEDENT><DEDENT>line_num -= <NUM_LIT:1>  <EOL>if line_num > self.config.max_module_lines:<EOL><INDENT>message_definition = self.linter.msgs_store.get_message_definitions(<EOL>"<STR_LIT>"<EOL>)[<NUM_LIT:0>]<EOL>names = (message_definition.msgid, "<STR_LIT>")<EOL>line = next(filter(None, map(self.linter._pragma_lineno.get, names)), <NUM_LIT:1>)<EOL>self.add_message(<EOL>"<STR_LIT>",<EOL>args=(line_num, self.config.max_module_lines),<EOL>line=line,<EOL>)<EOL><DEDENT>if line_num == last_blank_line_num and line_num > <NUM_LIT:0>:<EOL><INDENT>self.add_message("<STR_LIT>", line=line_num)<EOL><DEDENT>

process tokens and search for :

         _ non strict indentation (i.e. not always using the <indent> parameter as
           indent unit)
         _ too long lines (i.e. longer than <max_chars>)
         _ optionally bad construct (if given, bad_construct must be a compiled
           regular expression).


if not node.is_statement:<EOL><INDENT>return<EOL><DEDENT>if not node.root().pure_python:<EOL><INDENT>return  <EOL><DEDENT>prev_sibl = node.previous_sibling()<EOL>if prev_sibl is not None:<EOL><INDENT>prev_line = prev_sibl.fromlineno<EOL><DEDENT>else:<EOL><INDENT>if (<EOL>isinstance(node.parent, nodes.TryFinally)<EOL>and node in node.parent.finalbody<EOL>):<EOL><INDENT>prev_line = node.parent.body[<NUM_LIT:0>].tolineno + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>prev_line = node.parent.statement().fromlineno<EOL><DEDENT><DEDENT>line = node.fromlineno<EOL>assert line, node<EOL>if prev_line == line and self._visited_lines.get(line) != <NUM_LIT:2>:<EOL><INDENT>self._check_multi_statement_line(node, line)<EOL>return<EOL><DEDENT>if line in self._visited_lines:<EOL><INDENT>return<EOL><DEDENT>try:<EOL><INDENT>tolineno = node.blockstart_tolineno<EOL><DEDENT>except AttributeError:<EOL><INDENT>tolineno = node.tolineno<EOL><DEDENT>assert tolineno, node<EOL>lines = []<EOL>for line in range(line, tolineno + <NUM_LIT:1>):<EOL><INDENT>self._visited_lines[line] = <NUM_LIT:1><EOL>try:<EOL><INDENT>lines.append(self._lines[line].rstrip())<EOL><DEDENT>except KeyError:<EOL><INDENT>lines.append("<STR_LIT>")<EOL><DEDENT><DEDENT>

check the node line number and check it if not yet done


def _check_multi_statement_line(self, node, line):

<EOL>if isinstance(node, nodes.With):<EOL><INDENT>return<EOL><DEDENT>if isinstance(node, nodes.TryExcept) and isinstance(<EOL>node.parent, nodes.TryFinally<EOL>):<EOL><INDENT>return<EOL><DEDENT>if (<EOL>isinstance(node.parent, nodes.If)<EOL>and not node.parent.orelse<EOL>and self.config.single_line_if_stmt<EOL>):<EOL><INDENT>return<EOL><DEDENT>if (<EOL>isinstance(node.parent, nodes.ClassDef)<EOL>and len(node.parent.body) == <NUM_LIT:1><EOL>and self.config.single_line_class_stmt<EOL>):<EOL><INDENT>return<EOL><DEDENT>self.add_message("<STR_LIT>", node=node)<EOL>self._visited_lines[line] = <NUM_LIT:2><EOL>

Check for lines containing multiple statements.


max_chars = self.config.max_line_length<EOL>ignore_long_line = self.config.ignore_long_lines<EOL>def check_line(line, i):<EOL><INDENT>if not line.endswith("<STR_LIT:\n>"):<EOL><INDENT>self.add_message("<STR_LIT>", line=i)<EOL><DEDENT>else:<EOL><INDENT>stripped_line = line.rstrip("<STR_LIT>")<EOL>if not stripped_line and _EMPTY_LINE in self.config.no_space_check:<EOL><INDENT>pass<EOL><DEDENT>elif line[len(stripped_line) :] not in ("<STR_LIT:\n>", "<STR_LIT:\r\n>"):<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", line=i, col_offset=len(stripped_line)<EOL>)<EOL><DEDENT>line = stripped_line<EOL><DEDENT>mobj = OPTION_RGX.search(line)<EOL>if mobj and "<STR_LIT:=>" in line:<EOL><INDENT>front_of_equal, _, back_of_equal = mobj.group(<NUM_LIT:1>).partition("<STR_LIT:=>")<EOL>if front_of_equal.strip() == "<STR_LIT>":<EOL><INDENT>if "<STR_LIT>" in {<EOL>_msg_id.strip() for _msg_id in back_of_equal.split("<STR_LIT:U+002C>")<EOL>}:<EOL><INDENT>return None<EOL><DEDENT>line = line.rsplit("<STR_LIT:#>", <NUM_LIT:1>)[<NUM_LIT:0>].rstrip()<EOL><DEDENT><DEDENT>if len(line) > max_chars and not ignore_long_line.search(line):<EOL><INDENT>self.add_message("<STR_LIT>", line=i, args=(len(line), max_chars))<EOL><DEDENT>return i + <NUM_LIT:1><EOL><DEDENT>unsplit_ends = {<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>}<EOL>unsplit = []<EOL>for line in lines.splitlines(True):<EOL><INDENT>if line[-<NUM_LIT:1>] in unsplit_ends:<EOL><INDENT>unsplit.append(line)<EOL>continue<EOL><DEDENT>if unsplit:<EOL><INDENT>unsplit.append(line)<EOL>line = "<STR_LIT>".join(unsplit)<EOL>unsplit = []<EOL><DEDENT>i = check_line(line, i)<EOL>if i is None:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if unsplit:<EOL><INDENT>check_line("<STR_LIT>".join(unsplit), i)<EOL><DEDENT>

check lines have less than a maximum number of characters


def check_indent_level(self, string, expected, line_num):

indent = self.config.indent_string<EOL>if indent == "<STR_LIT>":  <EOL><INDENT>indent = "<STR_LIT:\t>"<EOL><DEDENT>level = <NUM_LIT:0><EOL>unit_size = len(indent)<EOL>while string[:unit_size] == indent:<EOL><INDENT>string = string[unit_size:]<EOL>level += <NUM_LIT:1><EOL><DEDENT>suppl = "<STR_LIT>"<EOL>while string and string[<NUM_LIT:0>] in "<STR_LIT>":<EOL><INDENT>if string[<NUM_LIT:0>] != indent[<NUM_LIT:0>]:<EOL><INDENT>if string[<NUM_LIT:0>] == "<STR_LIT:\t>":<EOL><INDENT>args = ("<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>args = ("<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>self.add_message("<STR_LIT>", args=args, line=line_num)<EOL>return level<EOL><DEDENT>suppl += string[<NUM_LIT:0>]<EOL>string = string[<NUM_LIT:1>:]<EOL><DEDENT>if level != expected or suppl:<EOL><INDENT>i_type = "<STR_LIT>"<EOL>if indent[<NUM_LIT:0>] == "<STR_LIT:\t>":<EOL><INDENT>i_type = "<STR_LIT>"<EOL><DEDENT>self.add_message(<EOL>"<STR_LIT>",<EOL>line=line_num,<EOL>args=(level * unit_size + len(suppl), i_type, expected * unit_size),<EOL>)<EOL><DEDENT>return None<EOL>


def stripped_lines(lines, ignore_comments, ignore_docstrings, ignore_imports):

if ignore_imports:<EOL><INDENT>tree = astroid.parse("<STR_LIT>".join(lines))<EOL>node_is_import_by_lineno = (<EOL>(node.lineno, isinstance(node, (astroid.Import, astroid.ImportFrom)))<EOL>for node in tree.body<EOL>)<EOL>line_begins_import = {<EOL>lineno: all(is_import for _, is_import in node_is_import_group)<EOL>for lineno, node_is_import_group in groupby(<EOL>node_is_import_by_lineno, key=lambda x: x[<NUM_LIT:0>]<EOL>)<EOL>}<EOL>current_line_is_import = False<EOL><DEDENT>strippedlines = []<EOL>docstring = None<EOL>for lineno, line in enumerate(lines, start=<NUM_LIT:1>):<EOL><INDENT>line = line.strip()<EOL>if ignore_docstrings:<EOL><INDENT>if not docstring and any(<EOL>line.startswith(i) for i in ['<STR_LIT>', "<STR_LIT>", '<STR_LIT>', "<STR_LIT>"]<EOL>):<EOL><INDENT>docstring = line[:<NUM_LIT:3>]<EOL>line = line[<NUM_LIT:3>:]<EOL><DEDENT>if docstring:<EOL><INDENT>if line.endswith(docstring):<EOL><INDENT>docstring = None<EOL><DEDENT>line = "<STR_LIT>"<EOL><DEDENT><DEDENT>if ignore_imports:<EOL><INDENT>current_line_is_import = line_begins_import.get(<EOL>lineno, current_line_is_import<EOL>)<EOL>if current_line_is_import:<EOL><INDENT>line = "<STR_LIT>"<EOL><DEDENT><DEDENT>if ignore_comments:<EOL><INDENT>line = line.split("<STR_LIT:#>", <NUM_LIT:1>)[<NUM_LIT:0>].strip()<EOL><DEDENT>strippedlines.append(line)<EOL><DEDENT>return strippedlines<EOL>

return lines with leading/trailing whitespace and any ignored code
    features removed


def report_similarities(sect, stats, old_stats):

lines = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>lines += table_lines_from_stats(<EOL>stats, old_stats, ("<STR_LIT>", "<STR_LIT>")<EOL>)<EOL>sect.append(Table(children=lines, cols=<NUM_LIT:4>, rheaders=<NUM_LIT:1>, cheaders=<NUM_LIT:1>))<EOL>

make a layout with some stats about duplication


linter.register_checker(SimilarChecker(linter))<EOL>

required method to auto register this checker


print("<STR_LIT>")<EOL>print()<EOL>print(<EOL>"<STR_LIT>"<EOL>)<EOL>sys.exit(status)<EOL>


if argv is None:<EOL><INDENT>argv = sys.argv[<NUM_LIT:1>:]<EOL><DEDENT>from getopt import getopt<EOL>s_opts = "<STR_LIT>"<EOL>l_opts = (<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>)<EOL>min_lines = <NUM_LIT:4><EOL>ignore_comments = False<EOL>ignore_docstrings = False<EOL>ignore_imports = False<EOL>opts, args = getopt(argv, s_opts, l_opts)<EOL>for opt, val in opts:<EOL><INDENT>if opt in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>min_lines = int(val)<EOL><DEDENT>elif opt in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>usage()<EOL><DEDENT>elif opt in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>ignore_comments = True<EOL><DEDENT>elif opt in ("<STR_LIT>",):<EOL><INDENT>ignore_docstrings = True<EOL><DEDENT>elif opt in ("<STR_LIT>",):<EOL><INDENT>ignore_imports = True<EOL><DEDENT><DEDENT>if not args:<EOL><INDENT>usage(<NUM_LIT:1>)<EOL><DEDENT>sim = Similar(min_lines, ignore_comments, ignore_docstrings, ignore_imports)<EOL>for filename in args:<EOL><INDENT>with open(filename) as stream:<EOL><INDENT>sim.append_stream(filename, stream)<EOL><DEDENT><DEDENT>sim.run()<EOL>sys.exit(<NUM_LIT:0>)<EOL>


def append_stream(self, streamid, stream, encoding=None):

if encoding is None:<EOL><INDENT>readlines = stream.readlines<EOL><DEDENT>else:<EOL><INDENT>readlines = decoding_stream(stream, encoding).readlines<EOL><DEDENT>try:<EOL><INDENT>self.linesets.append(<EOL>LineSet(<EOL>streamid,<EOL>readlines(),<EOL>self.ignore_comments,<EOL>self.ignore_docstrings,<EOL>self.ignore_imports,<EOL>)<EOL>)<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>pass<EOL><DEDENT>

append a file to search for similarities


self._display_sims(self._compute_sims())<EOL>

start looking for similarities and display results on stdout


no_duplicates = defaultdict(list)<EOL>for num, lineset1, idx1, lineset2, idx2 in self._iter_sims():<EOL><INDENT>duplicate = no_duplicates[num]<EOL>for couples in duplicate:<EOL><INDENT>if (lineset1, idx1) in couples or (lineset2, idx2) in couples:<EOL><INDENT>couples.add((lineset1, idx1))<EOL>couples.add((lineset2, idx2))<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>duplicate.append({(lineset1, idx1), (lineset2, idx2)})<EOL><DEDENT><DEDENT>sims = []<EOL>for num, ensembles in no_duplicates.items():<EOL><INDENT>for couples in ensembles:<EOL><INDENT>sims.append((num, couples))<EOL><DEDENT><DEDENT>sims.sort()<EOL>sims.reverse()<EOL>return sims<EOL>


nb_lignes_dupliquees = <NUM_LIT:0><EOL>for num, couples in sims:<EOL><INDENT>print()<EOL>print(num, "<STR_LIT>", len(couples), "<STR_LIT>")<EOL>couples = sorted(couples)<EOL>for lineset, idx in couples:<EOL><INDENT>print("<STR_LIT>" % (lineset.name, idx))<EOL><DEDENT>for line in lineset._real_lines[idx : idx + num]:<EOL><INDENT>print("<STR_LIT:U+0020>", line.rstrip())<EOL><DEDENT>nb_lignes_dupliquees += num * (len(couples) - <NUM_LIT:1>)<EOL><DEDENT>nb_total_lignes = sum([len(lineset) for lineset in self.linesets])<EOL>print(<EOL>"<STR_LIT>"<EOL>% (<EOL>nb_total_lignes,<EOL>nb_lignes_dupliquees,<EOL>nb_lignes_dupliquees * <NUM_LIT> / nb_total_lignes,<EOL>)<EOL>)<EOL>


def _find_common(self, lineset1, lineset2):

lines1 = lineset1.enumerate_stripped<EOL>lines2 = lineset2.enumerate_stripped<EOL>find = lineset2.find<EOL>index1 = <NUM_LIT:0><EOL>min_lines = self.min_lines<EOL>while index1 < len(lineset1):<EOL><INDENT>skip = <NUM_LIT:1><EOL>num = <NUM_LIT:0><EOL>for index2 in find(lineset1[index1]):<EOL><INDENT>non_blank = <NUM_LIT:0><EOL>for num, ((_, line1), (_, line2)) in enumerate(<EOL>zip(lines1(index1), lines2(index2))<EOL>):<EOL><INDENT>if line1 != line2:<EOL><INDENT>if non_blank > min_lines:<EOL><INDENT>yield num, lineset1, index1, lineset2, index2<EOL><DEDENT>skip = max(skip, num)<EOL>break<EOL><DEDENT>if line1:<EOL><INDENT>non_blank += <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>num += <NUM_LIT:1><EOL>if non_blank > min_lines:<EOL><INDENT>yield num, lineset1, index1, lineset2, index2<EOL><DEDENT>skip = max(skip, num)<EOL><DEDENT><DEDENT>index1 += skip<EOL><DEDENT>

find similarities in the two given linesets


for idx, lineset in enumerate(self.linesets[:-<NUM_LIT:1>]):<EOL><INDENT>for lineset2 in self.linesets[idx + <NUM_LIT:1> :]:<EOL><INDENT>for sim in self._find_common(lineset, lineset2):<EOL><INDENT>yield sim<EOL><DEDENT><DEDENT><DEDENT>

iterate on similarities among all files, by making a cartesian
        product


idx = start_at<EOL>if start_at:<EOL><INDENT>lines = self._stripped_lines[start_at:]<EOL><DEDENT>else:<EOL><INDENT>lines = self._stripped_lines<EOL><DEDENT>for line in lines:<EOL><INDENT>yield idx, line<EOL>idx += <NUM_LIT:1><EOL><DEDENT>

return an iterator on stripped lines, starting from a given index
        if specified, else 0


return self._index.get(stripped_line, ())<EOL>

return positions of the given stripped line in this set


index = defaultdict(list)<EOL>for line_no, line in enumerate(self._stripped_lines):<EOL><INDENT>if line:<EOL><INDENT>index[line].append(line_no)<EOL><DEDENT><DEDENT>return index<EOL>


def set_option(self, optname, value, action=None, optdict=None):

BaseChecker.set_option(self, optname, value, action, optdict)<EOL>if optname == "<STR_LIT>":<EOL><INDENT>self.min_lines = self.config.min_similarity_lines<EOL><DEDENT>elif optname == "<STR_LIT>":<EOL><INDENT>self.ignore_comments = self.config.ignore_comments<EOL><DEDENT>elif optname == "<STR_LIT>":<EOL><INDENT>self.ignore_docstrings = self.config.ignore_docstrings<EOL><DEDENT>elif optname == "<STR_LIT>":<EOL><INDENT>self.ignore_imports = self.config.ignore_imports<EOL><DEDENT>

method called to set an option (registered in the options list)

        overridden to report options setting to Similar


self.linesets = []<EOL>self.stats = self.linter.add_stats(<EOL>nb_duplicated_lines=<NUM_LIT:0>, percent_duplicated_lines=<NUM_LIT:0><EOL>)<EOL>

init the checkers: reset linesets and statistics information


with node.stream() as stream:<EOL><INDENT>self.append_stream(self.linter.current_name, stream, node.file_encoding)<EOL><DEDENT>

process a module

        the module's content is accessible via the stream object

        stream must implement the readlines method


total = sum(len(lineset) for lineset in self.linesets)<EOL>duplicated = <NUM_LIT:0><EOL>stats = self.stats<EOL>for num, couples in self._compute_sims():<EOL><INDENT>msg = []<EOL>for lineset, idx in couples:<EOL><INDENT>msg.append("<STR_LIT>" % (lineset.name, idx))<EOL><DEDENT>msg.sort()<EOL>for line in lineset._real_lines[idx : idx + num]:<EOL><INDENT>msg.append(line.rstrip())<EOL><DEDENT>self.add_message("<STR_LIT>", args=(len(couples), "<STR_LIT:\n>".join(msg)))<EOL>duplicated += num * (len(couples) - <NUM_LIT:1>)<EOL><DEDENT>stats["<STR_LIT>"] = duplicated<EOL>stats["<STR_LIT>"] = total and duplicated * <NUM_LIT> / total<EOL>

compute and display similarities on closing (i.e. end of parsing)


def _is_owner_ignored(owner, name, ignored_classes, ignored_modules):

ignored_modules = set(ignored_modules)<EOL>module_name = owner.root().name<EOL>module_qname = owner.root().qname()<EOL>if any(<EOL>module_name in ignored_modules<EOL>or module_qname in ignored_modules<EOL>or fnmatch.fnmatch(module_qname, ignore)<EOL>for ignore in ignored_modules<EOL>):<EOL><INDENT>return True<EOL><DEDENT>ignored_classes = set(ignored_classes)<EOL>if hasattr(owner, "<STR_LIT>"):<EOL><INDENT>qname = owner.qname()<EOL><DEDENT>else:<EOL><INDENT>qname = "<STR_LIT>"<EOL><DEDENT>return any(ignore in (name, qname) for ignore in ignored_classes)<EOL>

Check if the given owner should be ignored

    This will verify if the owner's module is in *ignored_modules*
    or the owner's module fully qualified name is in *ignored_modules*
    or if the *ignored_modules* contains a pattern which catches
    the fully qualified name of the module.

    Also, similar checks are done for the owner itself, if its name
    matches any name from the *ignored_classes* or if its qualified
    name can be found in *ignored_classes*.


def _similar_names(owner, attrname, distance_threshold, max_choices):

possible_names = []<EOL>names = _node_names(owner)<EOL>for name in names:<EOL><INDENT>if name == attrname:<EOL><INDENT>continue<EOL><DEDENT>distance = _string_distance(attrname, name)<EOL>if distance <= distance_threshold:<EOL><INDENT>possible_names.append((name, distance))<EOL><DEDENT><DEDENT>picked = [<EOL>name<EOL>for (name, _) in heapq.nsmallest(<EOL>max_choices, possible_names, key=operator.itemgetter(<NUM_LIT:1>)<EOL>)<EOL>]<EOL>return sorted(picked)<EOL>

Given an owner and a name, try to find similar names

    The similar names are searched given a distance metric and only
    a given number of choices will be returned.


def _emit_no_member(node, owner, owner_name, ignored_mixins=True, ignored_none=True):

<EOL>if node_ignores_exception(node, AttributeError):<EOL><INDENT>return False<EOL><DEDENT>if ignored_none and isinstance(owner, astroid.Const) and owner.value is None:<EOL><INDENT>return False<EOL><DEDENT>if is_super(owner) or getattr(owner, "<STR_LIT:type>", None) == "<STR_LIT>":<EOL><INDENT>return False<EOL><DEDENT>if ignored_mixins and owner_name[-<NUM_LIT:5>:].lower() == "<STR_LIT>":<EOL><INDENT>return False<EOL><DEDENT>if isinstance(owner, astroid.FunctionDef) and owner.decorators:<EOL><INDENT>return False<EOL><DEDENT>if isinstance(owner, (astroid.Instance, astroid.ClassDef)):<EOL><INDENT>if owner.has_dynamic_getattr():<EOL><INDENT>try:<EOL><INDENT>metaclass = owner.metaclass()<EOL><DEDENT>except exceptions.MroError:<EOL><INDENT>return False<EOL><DEDENT>if metaclass:<EOL><INDENT>return metaclass.qname() == "<STR_LIT>"<EOL><DEDENT>return False<EOL><DEDENT>if not has_known_bases(owner):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>if isinstance(owner, objects.Super):<EOL><INDENT>try:<EOL><INDENT>owner.super_mro()<EOL><DEDENT>except (exceptions.MroError, exceptions.SuperError):<EOL><INDENT>return False<EOL><DEDENT>if not all(map(has_known_bases, owner.type.mro())):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>if isinstance(owner, astroid.Module):<EOL><INDENT>try:<EOL><INDENT>owner.getattr("<STR_LIT>")<EOL>return False<EOL><DEDENT>except astroid.NotFoundError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if node.attrname.startswith("<STR_LIT:_>" + owner_name):<EOL><INDENT>unmangled_name = node.attrname.split("<STR_LIT:_>" + owner_name)[-<NUM_LIT:1>]<EOL>try:<EOL><INDENT>if owner.getattr(unmangled_name, context=None) is not None:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>except astroid.NotFoundError:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return True<EOL>

Try to see if no-member should be emitted for the given owner.

    The following cases are ignored:

        * the owner is a function and it has decorators.
        * the owner is an instance and it has __getattr__, __getattribute__ implemented
        * the module is explicitly ignored from no-member checks
        * the owner is a class and the name can be found in its metaclass.
        * The access node is protected by an except handler, which handles
          AttributeError, Exception or bare except.


def _has_parent_of_type(node, node_type, statement):

parent = node.parent<EOL>while not isinstance(parent, node_type) and statement.parent_of(parent):<EOL><INDENT>parent = parent.parent<EOL><DEDENT>return isinstance(parent, node_type)<EOL>

Check if the given node has a parent of the given type.


return any(<EOL>variadic.value == name or variadic.value.parent_of(name)<EOL>for variadic in variadics<EOL>)<EOL>

Check if the given name is used as a variadic argument.


def _no_context_variadic(node, variadic_name, variadic_type, variadics):

statement = node.statement()<EOL>for name in statement.nodes_of_class(astroid.Name):<EOL><INDENT>if name.name != variadic_name:<EOL><INDENT>continue<EOL><DEDENT>inferred = safe_infer(name)<EOL>if isinstance(inferred, (astroid.List, astroid.Tuple)):<EOL><INDENT>length = len(inferred.elts)<EOL><DEDENT>elif isinstance(inferred, astroid.Dict):<EOL><INDENT>length = len(inferred.items)<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT>inferred_statement = inferred.statement()<EOL>if not length and isinstance(inferred_statement, astroid.FunctionDef):<EOL><INDENT>is_in_starred_context = _has_parent_of_type(node, variadic_type, statement)<EOL>used_as_starred_argument = _is_name_used_as_variadic(name, variadics)<EOL>if is_in_starred_context or used_as_starred_argument:<EOL><INDENT>return True<EOL><DEDENT><DEDENT><DEDENT>return False<EOL>

Verify if the given call node has variadic nodes without context

    This is a workaround for handling cases of nested call functions
    which don't have the specific call context at hand.
    Variadic arguments (variable positional arguments and variable
    keyword arguments) are inferred, inherently wrong, by astroid
    as a Tuple, respectively a Dict with empty elements.
    This can lead pylint to believe that a function call receives
    too few arguments.


context = astroid.context.InferenceContext()<EOL>class_bases = astroid.List()<EOL>class_bases.postinit(elts=cls.bases)<EOL>attrs = astroid.Dict()<EOL>local_names = [(name, values[-<NUM_LIT:1>]) for name, values in cls.locals.items()]<EOL>attrs.postinit(local_names)<EOL>builder_args = astroid.Tuple()<EOL>builder_args.postinit([cls.name, class_bases, attrs])<EOL>context.callcontext = astroid.context.CallContext(builder_args)<EOL>try:<EOL><INDENT>inferred = next(func.infer_call_result(func, context), None)<EOL><DEDENT>except astroid.InferenceError:<EOL><INDENT>return None<EOL><DEDENT>return inferred or None<EOL>

Try to infer what the given *func* constructor is building

    :param astroid.FunctionDef func:
        A metaclass constructor. Metaclass definitions can be
        functions, which should accept three arguments, the name of
        the class, the bases of the class and the attributes.
        The function could return anything, but usually it should
        be a proper metaclass.
    :param astroid.ClassDef cls:
        The class for which the *func* parameter should generate
        a metaclass.
    :returns:
        The class generated by the function or None,
        if we couldn't infer it.
    :rtype: astroid.ClassDef


linter.register_checker(TypeChecker(linter))<EOL>linter.register_checker(IterableChecker(linter))<EOL>

required method to auto register this checker


@check_messages("<STR_LIT>", "<STR_LIT>")<EOL><INDENT>def visit_attribute(self, node):<DEDENT>

for pattern in self.config.generated_members:<EOL><INDENT>if re.match(pattern, node.attrname):<EOL><INDENT>return<EOL><DEDENT>if re.match(pattern, node.as_string()):<EOL><INDENT>return<EOL><DEDENT><DEDENT>try:<EOL><INDENT>inferred = list(node.expr.infer())<EOL><DEDENT>except exceptions.InferenceError:<EOL><INDENT>return<EOL><DEDENT>missingattr = set()<EOL>non_opaque_inference_results = [<EOL>owner<EOL>for owner in inferred<EOL>if owner is not astroid.Uninferable<EOL>and not isinstance(owner, astroid.nodes.Unknown)<EOL>]<EOL>if (<EOL>len(non_opaque_inference_results) != len(inferred)<EOL>and self.config.ignore_on_opaque_inference<EOL>):<EOL><INDENT>return<EOL><DEDENT>for owner in non_opaque_inference_results:<EOL><INDENT>name = getattr(owner, "<STR_LIT:name>", None)<EOL>if _is_owner_ignored(<EOL>owner, name, self.config.ignored_classes, self.config.ignored_modules<EOL>):<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>if not [<EOL>n<EOL>for n in owner.getattr(node.attrname)<EOL>if not isinstance(n.statement(), astroid.AugAssign)<EOL>]:<EOL><INDENT>missingattr.add((owner, name))<EOL>continue<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>continue<EOL><DEDENT>except exceptions.NotFoundError:<EOL><INDENT>if not _emit_no_member(<EOL>node,<EOL>owner,<EOL>name,<EOL>ignored_mixins=self.config.ignore_mixin_members,<EOL>ignored_none=self.config.ignore_none,<EOL>):<EOL><INDENT>continue<EOL><DEDENT>missingattr.add((owner, name))<EOL>continue<EOL><DEDENT>break<EOL><DEDENT>else:<EOL><INDENT>done = set()<EOL>for owner, name in missingattr:<EOL><INDENT>if isinstance(owner, astroid.Instance):<EOL><INDENT>actual = owner._proxied<EOL><DEDENT>else:<EOL><INDENT>actual = owner<EOL><DEDENT>if actual in done:<EOL><INDENT>continue<EOL><DEDENT>done.add(actual)<EOL>msg, hint = self._get_nomember_msgid_hint(node, owner)<EOL>self.add_message(<EOL>msg,<EOL>node=node,<EOL>args=(owner.display_type(), name, node.attrname, hint),<EOL>confidence=INFERENCE,<EOL>)<EOL><DEDENT><DEDENT>

check that the accessed attribute exists

        to avoid too much false positives for now, we'll consider the code as
        correct if a single of the inferred nodes has the accessed attribute.

        function/method, super call and metaclasses are ignored


@check_messages("<STR_LIT>", "<STR_LIT>")<EOL><INDENT>def visit_assign(self, node):<DEDENT>

if not isinstance(node.value, astroid.Call):<EOL><INDENT>return<EOL><DEDENT>function_node = safe_infer(node.value.func)<EOL>funcs = (astroid.FunctionDef, astroid.UnboundMethod, astroid.BoundMethod)<EOL>if not (<EOL>isinstance(function_node, funcs)<EOL>and function_node.root().fully_defined()<EOL>and not function_node.decorators<EOL>):<EOL><INDENT>return<EOL><DEDENT>if (<EOL>function_node.is_generator()<EOL>or function_node.is_abstract(pass_is_abstract=False)<EOL>or isinstance(function_node, astroid.AsyncFunctionDef)<EOL>):<EOL><INDENT>return<EOL><DEDENT>returns = list(<EOL>function_node.nodes_of_class(astroid.Return, skip_klass=astroid.FunctionDef)<EOL>)<EOL>if not returns:<EOL><INDENT>self.add_message("<STR_LIT>", node=node)<EOL><DEDENT>else:<EOL><INDENT>for rnode in returns:<EOL><INDENT>if not (<EOL>isinstance(rnode.value, astroid.Const)<EOL>and rnode.value.value is None<EOL>or rnode.value is None<EOL>):<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.add_message("<STR_LIT>", node=node)<EOL><DEDENT><DEDENT>

check that if assigning to a function call, the function is
        possibly returning something valuable


if not isinstance(node.func, astroid.Attribute):<EOL><INDENT>return<EOL><DEDENT>expr = node.func.expr<EOL>klass = safe_infer(expr)<EOL>if (<EOL>klass is None<EOL>or klass is astroid.Uninferable<EOL>or not isinstance(klass, astroid.Instance)<EOL>):<EOL><INDENT>return<EOL><DEDENT>try:<EOL><INDENT>attrs = klass._proxied.getattr(node.func.attrname)<EOL><DEDENT>except exceptions.NotFoundError:<EOL><INDENT>return<EOL><DEDENT>for attr in attrs:<EOL><INDENT>if attr is astroid.Uninferable:<EOL><INDENT>continue<EOL><DEDENT>if not isinstance(attr, astroid.FunctionDef):<EOL><INDENT>continue<EOL><DEDENT>if decorated_with_property(attr):<EOL><INDENT>try:<EOL><INDENT>all_returns_are_callable = all(<EOL>return_node.callable() or return_node is astroid.Uninferable<EOL>for return_node in attr.infer_call_result(node)<EOL>)<EOL><DEDENT>except astroid.InferenceError:<EOL><INDENT>continue<EOL><DEDENT>if not all_returns_are_callable:<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", node=node, args=node.func.as_string()<EOL>)<EOL>break<EOL><DEDENT><DEDENT><DEDENT>

Check that the given uninferable Call node does not
call an actual function.


called = safe_infer(node.func)<EOL>if called and not called.callable():<EOL><INDENT>if isinstance(called, astroid.Instance) and (<EOL>not has_known_bases(called)<EOL>or (<EOL>isinstance(called.scope(), astroid.ClassDef)<EOL>and "<STR_LIT>" in called.locals<EOL>)<EOL>):<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>self.add_message("<STR_LIT>", node=node, args=node.func.as_string())<EOL><DEDENT><DEDENT>self._check_uninferable_call(node)<EOL>try:<EOL><INDENT>called, implicit_args, callable_name = _determine_callable(called)<EOL><DEDENT>except ValueError:<EOL><INDENT>return<EOL><DEDENT>if called.args.args is None:<EOL><INDENT>return<EOL><DEDENT>if len(called.argnames()) != len(set(called.argnames())):<EOL><INDENT>return<EOL><DEDENT>call_site = astroid.arguments.CallSite.from_call(node)<EOL>for keyword in call_site.duplicated_keywords:<EOL><INDENT>self.add_message("<STR_LIT>", node=node, args=(keyword,))<EOL><DEDENT>if call_site.has_invalid_arguments() or call_site.has_invalid_keywords():<EOL><INDENT>return<EOL><DEDENT>num_positional_args = len(call_site.positional_arguments)<EOL>keyword_args = list(call_site.keyword_arguments.keys())<EOL>if isinstance(node.scope(), astroid.FunctionDef):<EOL><INDENT>has_no_context_positional_variadic = _no_context_variadic_positional(node)<EOL>has_no_context_keywords_variadic = _no_context_variadic_keywords(node)<EOL><DEDENT>else:<EOL><INDENT>has_no_context_positional_variadic = (<EOL>has_no_context_keywords_variadic<EOL>) = False<EOL><DEDENT>already_filled_positionals = getattr(called, "<STR_LIT>", <NUM_LIT:0>)<EOL>already_filled_keywords = getattr(called, "<STR_LIT>", {})<EOL>keyword_args += list(already_filled_keywords)<EOL>num_positional_args += implicit_args + already_filled_positionals<EOL>num_mandatory_parameters = len(called.args.args) - len(called.args.defaults)<EOL>parameters = []<EOL>parameter_name_to_index = {}<EOL>for i, arg in enumerate(called.args.args):<EOL><INDENT>if isinstance(arg, astroid.Tuple):<EOL><INDENT>name = None<EOL><DEDENT>else:<EOL><INDENT>assert isinstance(arg, astroid.AssignName)<EOL>name = arg.name<EOL>parameter_name_to_index[name] = i<EOL><DEDENT>if i >= num_mandatory_parameters:<EOL><INDENT>defval = called.args.defaults[i - num_mandatory_parameters]<EOL><DEDENT>else:<EOL><INDENT>defval = None<EOL><DEDENT>parameters.append([(name, defval), False])<EOL><DEDENT>kwparams = {}<EOL>for i, arg in enumerate(called.args.kwonlyargs):<EOL><INDENT>if isinstance(arg, astroid.Keyword):<EOL><INDENT>name = arg.arg<EOL><DEDENT>else:<EOL><INDENT>assert isinstance(arg, astroid.AssignName)<EOL>name = arg.name<EOL><DEDENT>kwparams[name] = [called.args.kw_defaults[i], False]<EOL><DEDENT>for i in range(num_positional_args):<EOL><INDENT>if i < len(parameters):<EOL><INDENT>parameters[i][<NUM_LIT:1>] = True<EOL><DEDENT>elif called.args.vararg is not None:<EOL><INDENT>break<EOL><DEDENT>else:<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", node=node, args=(callable_name,)<EOL>)<EOL>break<EOL><DEDENT><DEDENT>for keyword in keyword_args:<EOL><INDENT>if keyword in parameter_name_to_index:<EOL><INDENT>i = parameter_name_to_index[keyword]<EOL>if parameters[i][<NUM_LIT:1>]:<EOL><INDENT>if not (keyword == "<STR_LIT>" and called.qname() in STR_FORMAT):<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>",<EOL>node=node,<EOL>args=(keyword, callable_name),<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>parameters[i][<NUM_LIT:1>] = True<EOL><DEDENT><DEDENT>elif keyword in kwparams:<EOL><INDENT>if kwparams[keyword][<NUM_LIT:1>]:  <EOL><INDENT>self.add_message(<EOL>"<STR_LIT>",<EOL>node=node,<EOL>args=(keyword, callable_name),<EOL>)<EOL><DEDENT>else:<EOL><INDENT>kwparams[keyword][<NUM_LIT:1>] = True<EOL><DEDENT><DEDENT>elif called.args.kwarg is not None:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>", node=node, args=(keyword, callable_name)<EOL>)<EOL><DEDENT><DEDENT>if node.kwargs:<EOL><INDENT>for i, [(name, defval), assigned] in enumerate(parameters):<EOL><INDENT>if name is not None:<EOL><INDENT>parameters[i][<NUM_LIT:1>] = True<EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>for [(name, defval), assigned] in parameters:<EOL><INDENT>if (defval is None) and not assigned:<EOL><INDENT>if name is None:<EOL><INDENT>display_name = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>display_name = repr(name)<EOL><DEDENT>if not has_no_context_positional_variadic:<EOL><INDENT>self.add_message(<EOL>"<STR_LIT>",<EOL>node=node,<EOL>args=(display_name, callable_name),<EOL>)<EOL><DEDENT><DEDENT><DEDENT>for name in kwparams:<EOL><INDENT>defval, assigned = kwparams[name]<EOL>if defval is None and not assigned and not has_no_context_keywords_variadic:<EOL><INDENT>self.add_message("<STR_LIT>", node=node, args=(name, callable_name))<EOL><DEDENT><DEDENT>

check that called functions/methods are inferred to callable objects,
        and that the arguments passed to the function match the parameters in
        the inferred function's definition


for error in node.type_errors():<EOL><INDENT>self.add_message("<STR_LIT>", args=str(error), node=node)<EOL><DEDENT>


Detect TypeErrors for binary arithmetic operands.


Detect TypeErrors for augmented binary arithmetic operands.


if self.name is not None:<EOL><INDENT>self.name = self.name.lower()<EOL><DEDENT>OptionsProviderMixIn.__init__(self)<EOL>self.linter = linter<EOL>

checker instances should have the linter as argument

        :param ILinter linter: is an object implementing ILinter.


checker_id = None<EOL>existing_ids = []<EOL>for message in self.messages:<EOL><INDENT>if checker_id is not None and checker_id != message.msgid[<NUM_LIT:1>:<NUM_LIT:3>]:<EOL><INDENT>error_msg = "<STR_LIT>"<EOL>error_msg += "<STR_LIT>".format(<EOL>message.msgid, checker_id=checker_id<EOL>)<EOL>error_msg += "<STR_LIT>".format(<EOL>existing_ids=existing_ids<EOL>)<EOL>raise InvalidMessageError(error_msg)<EOL><DEDENT>checker_id = message.msgid[<NUM_LIT:1>:<NUM_LIT:3>]<EOL>existing_ids.append(message.msgid)<EOL><DEDENT>

Check the consistency of msgid.

        msg ids for a checker should be a string of len 4, where the two first
        characters are the checker id and the two last the msg id in this
        checker.

        :raises InvalidMessageError: If the checker id in the messages are not
        always the same.


called before visiting project (i.e set of modules)


called after visiting project (i.e set of modules)


raise NotImplementedError()<EOL>


current = node<EOL>while current and not isinstance(current.parent, astroid.ExceptHandler):<EOL><INDENT>current = current.parent<EOL><DEDENT>return current and current is current.parent.name<EOL>

Returns true if node is inside the name of an except handler.


def is_inside_lambda(node: astroid.node_classes.NodeNG) -> bool:

parent = node.parent<EOL>while parent is not None:<EOL><INDENT>if isinstance(parent, astroid.Lambda):<EOL><INDENT>return True<EOL><DEDENT>parent = parent.parent<EOL><DEDENT>return False<EOL>

Return true if given node is inside lambda


def get_all_elements(<EOL>node: astroid.node_classes.NodeNG<EOL>) -> Iterable[astroid.node_classes.NodeNG]:

if isinstance(node, (astroid.Tuple, astroid.List)):<EOL><INDENT>for child in node.elts:<EOL><INDENT>for e in get_all_elements(child):<EOL><INDENT>yield e<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>yield node<EOL><DEDENT>

Recursively returns all atoms in nested lists and tuples.


def clobber_in_except(<EOL>node: astroid.node_classes.NodeNG<EOL>) -> Tuple[bool, Tuple[str, str]]:

if isinstance(node, astroid.AssignAttr):<EOL><INDENT>return True, (node.attrname, "<STR_LIT>" % (node.expr.as_string(),))<EOL><DEDENT>if isinstance(node, astroid.AssignName):<EOL><INDENT>name = node.name<EOL>if is_builtin(name):<EOL><INDENT>return (True, (name, "<STR_LIT>"))<EOL><DEDENT>stmts = node.lookup(name)[<NUM_LIT:1>]<EOL>if stmts and not isinstance(<EOL>stmts[<NUM_LIT:0>].assign_type(),<EOL>(astroid.Assign, astroid.AugAssign, astroid.ExceptHandler),<EOL>):<EOL><INDENT>return True, (name, "<STR_LIT>" % stmts[<NUM_LIT:0>].fromlineno)<EOL><DEDENT><DEDENT>return False, None<EOL>

Checks if an assignment node in an except handler clobbers an existing
    variable.

    Returns (True, args for W0623) if assignment clobbers an existing variable,
    (False, None) otherwise.


def is_super(node: astroid.node_classes.NodeNG) -> bool:

if getattr(node, "<STR_LIT:name>", None) == "<STR_LIT>" and node.root().name == BUILTINS_NAME:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>

return True if the node is referencing the "super" builtin function


def is_error(node: astroid.node_classes.NodeNG) -> bool:

for child_node in node.get_children():<EOL><INDENT>if isinstance(child_node, astroid.Raise):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>

return true if the function does nothing but raising an exception


def is_builtin_object(node: astroid.node_classes.NodeNG) -> bool:

return node and node.root().name == BUILTINS_NAME<EOL>

Returns True if the given node is an object from the __builtin__ module.


return name in builtins or name in SPECIAL_BUILTINS<EOL>

return true if <name> could be considered as a builtin defined by python


def is_defined_before(var_node: astroid.node_classes.NodeNG) -> bool:

varname = var_node.name<EOL>_node = var_node.parent<EOL>while _node:<EOL><INDENT>if is_defined_in_scope(var_node, varname, _node):<EOL><INDENT>return True<EOL><DEDENT>_node = _node.parent<EOL><DEDENT>stmt = var_node.statement()<EOL>_node = stmt.previous_sibling()<EOL>lineno = stmt.fromlineno<EOL>while _node and _node.fromlineno == lineno:<EOL><INDENT>for assign_node in _node.nodes_of_class(astroid.AssignName):<EOL><INDENT>if assign_node.name == varname:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>for imp_node in _node.nodes_of_class((astroid.ImportFrom, astroid.Import)):<EOL><INDENT>if varname in [name[<NUM_LIT:1>] or name[<NUM_LIT:0>] for name in imp_node.names]:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>_node = _node.previous_sibling()<EOL><DEDENT>return False<EOL>

return True if the variable node is defined by a parent node (list,
    set, dict, or generator comprehension, lambda) or in a previous sibling
    node on the same line (statement_defining ; statement_using)


def is_default_argument(node: astroid.node_classes.NodeNG) -> bool:

parent = node.scope()<EOL>if isinstance(parent, (astroid.FunctionDef, astroid.Lambda)):<EOL><INDENT>for default_node in parent.args.defaults:<EOL><INDENT>for default_name_node in default_node.nodes_of_class(astroid.Name):<EOL><INDENT>if default_name_node is node:<EOL><INDENT>return True<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return False<EOL>

return true if the given Name node is used in function or lambda
    default argument's value


def is_func_decorator(node: astroid.node_classes.NodeNG) -> bool:

parent = node.parent<EOL>while parent is not None:<EOL><INDENT>if isinstance(parent, astroid.Decorators):<EOL><INDENT>return True<EOL><DEDENT>if parent.is_statement or isinstance(<EOL>parent,<EOL>(astroid.Lambda, scoped_nodes.ComprehensionScope, scoped_nodes.ListComp),<EOL>):<EOL><INDENT>break<EOL><DEDENT>parent = parent.parent<EOL><DEDENT>return False<EOL>

return true if the name is used in function decorator


def is_ancestor_name(<EOL>frame: astroid.node_classes.NodeNG, node: astroid.node_classes.NodeNG<EOL>) -> bool:

try:<EOL><INDENT>bases = frame.bases<EOL><DEDENT>except AttributeError:<EOL><INDENT>return False<EOL><DEDENT>for base in bases:<EOL><INDENT>if node in base.nodes_of_class(astroid.Name):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>

return True if `frame` is an astroid.Class node with `node` in the
    subtree of its bases attribute


def assign_parent(node: astroid.node_classes.NodeNG) -> astroid.node_classes.NodeNG:

while node and isinstance(node, (astroid.AssignName, astroid.Tuple, astroid.List)):<EOL><INDENT>node = node.parent<EOL><DEDENT>return node<EOL>

return the higher parent which is not an AssignName, Tuple or List node


def overrides_a_method(class_node: astroid.node_classes.NodeNG, name: str) -> bool:

for ancestor in class_node.ancestors():<EOL><INDENT>if name in ancestor and isinstance(ancestor[name], astroid.FunctionDef):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>

return True if <name> is a method overridden from an ancestor


def check_messages(*messages: str) -> Callable:

def store_messages(func):<EOL><INDENT>func.checks_msgs = messages<EOL>return func<EOL><DEDENT>return store_messages<EOL>

decorator to store messages that are handled by a checker method


def parse_format_string(<EOL>format_string: str<EOL>) -> Tuple[Set[str], int, Dict[str, str], List[str]]:

keys = set()<EOL>key_types = dict()<EOL>pos_types = []<EOL>num_args = <NUM_LIT:0><EOL>def next_char(i):<EOL><INDENT>i += <NUM_LIT:1><EOL>if i == len(format_string):<EOL><INDENT>raise IncompleteFormatString<EOL><DEDENT>return (i, format_string[i])<EOL><DEDENT>i = <NUM_LIT:0><EOL>while i < len(format_string):<EOL><INDENT>char = format_string[i]<EOL>if char == "<STR_LIT:%>":<EOL><INDENT>i, char = next_char(i)<EOL>key = None<EOL>if char == "<STR_LIT:(>":<EOL><INDENT>depth = <NUM_LIT:1><EOL>i, char = next_char(i)<EOL>key_start = i<EOL>while depth != <NUM_LIT:0>:<EOL><INDENT>if char == "<STR_LIT:(>":<EOL><INDENT>depth += <NUM_LIT:1><EOL><DEDENT>elif char == "<STR_LIT:)>":<EOL><INDENT>depth -= <NUM_LIT:1><EOL><DEDENT>i, char = next_char(i)<EOL><DEDENT>key_end = i - <NUM_LIT:1><EOL>key = format_string[key_start:key_end]<EOL><DEDENT>while char in "<STR_LIT>":<EOL><INDENT>i, char = next_char(i)<EOL><DEDENT>if char == "<STR_LIT:*>":<EOL><INDENT>num_args += <NUM_LIT:1><EOL>i, char = next_char(i)<EOL><DEDENT>else:<EOL><INDENT>while char in string.digits:<EOL><INDENT>i, char = next_char(i)<EOL><DEDENT><DEDENT>if char == "<STR_LIT:.>":<EOL><INDENT>i, char = next_char(i)<EOL>if char == "<STR_LIT:*>":<EOL><INDENT>num_args += <NUM_LIT:1><EOL>i, char = next_char(i)<EOL><DEDENT>else:<EOL><INDENT>while char in string.digits:<EOL><INDENT>i, char = next_char(i)<EOL><DEDENT><DEDENT><DEDENT>if char in "<STR_LIT>":<EOL><INDENT>i, char = next_char(i)<EOL><DEDENT>if PY3K:<EOL><INDENT>flags = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>flags = "<STR_LIT>"<EOL><DEDENT>if char not in flags:<EOL><INDENT>raise UnsupportedFormatCharacter(i)<EOL><DEDENT>if key:<EOL><INDENT>keys.add(key)<EOL>key_types[key] = char<EOL><DEDENT>elif char != "<STR_LIT:%>":<EOL><INDENT>num_args += <NUM_LIT:1><EOL>pos_types.append(char)<EOL><DEDENT><DEDENT>i += <NUM_LIT:1><EOL><DEDENT>return keys, num_args, key_types, pos_types<EOL>

Parses a format string, returning a tuple of (keys, num_args), where keys
    is the set of mapping keys in the format string, and num_args is the number
    of arguments required by the format string.  Raises
    IncompleteFormatString or UnsupportedFormatCharacter if a
    parse error occurs.


def collect_string_fields(format_string) -> Iterable[Optional[str]]:

formatter = string.Formatter()<EOL>try:<EOL><INDENT>parseiterator = formatter.parse(format_string)<EOL>for result in parseiterator:<EOL><INDENT>if all(item is None for item in result[<NUM_LIT:1>:]):<EOL><INDENT>continue<EOL><DEDENT>name = result[<NUM_LIT:1>]<EOL>nested = result[<NUM_LIT:2>]<EOL>yield name<EOL>if nested:<EOL><INDENT>for field in collect_string_fields(nested):<EOL><INDENT>yield field<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except ValueError as exc:<EOL><INDENT>if exc.args[<NUM_LIT:0>].startswith("<STR_LIT>"):<EOL><INDENT>yield "<STR_LIT>"<EOL>yield "<STR_LIT:1>"<EOL>return<EOL><DEDENT>raise IncompleteFormatString(format_string)<EOL><DEDENT>

Given a format string, return an iterator
    of all the valid format fields. It handles nested fields
    as well.


def parse_format_method_string(<EOL>format_string: str<EOL>) -> Tuple[List[Tuple[str, List[Tuple[bool, str]]]], int, int]:

keyword_arguments = []<EOL>implicit_pos_args_cnt = <NUM_LIT:0><EOL>explicit_pos_args = set()<EOL>for name in collect_string_fields(format_string):<EOL><INDENT>if name and str(name).isdigit():<EOL><INDENT>explicit_pos_args.add(str(name))<EOL><DEDENT>elif name:<EOL><INDENT>keyname, fielditerator = split_format_field_names(name)<EOL>if isinstance(keyname, numbers.Number):<EOL><INDENT>explicit_pos_args.add(str(keyname))<EOL>keyname = int(keyname)<EOL><DEDENT>try:<EOL><INDENT>keyword_arguments.append((keyname, list(fielditerator)))<EOL><DEDENT>except ValueError:<EOL><INDENT>raise IncompleteFormatString()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>implicit_pos_args_cnt += <NUM_LIT:1><EOL><DEDENT><DEDENT>return keyword_arguments, implicit_pos_args_cnt, len(explicit_pos_args)<EOL>

Parses a PEP 3101 format string, returning a tuple of
(keyword_arguments, implicit_pos_args_cnt, explicit_pos_args),
where keyword_arguments is the set of mapping keys in the format string, implicit_pos_args_cnt
is the number of arguments required by the format string and
explicit_pos_args is the number of arguments passed with the position.


def is_attr_protected(attrname: str) -> bool:

return (<EOL>attrname[<NUM_LIT:0>] == "<STR_LIT:_>"<EOL>and attrname != "<STR_LIT:_>"<EOL>and not (attrname.startswith("<STR_LIT>") and attrname.endswith("<STR_LIT>"))<EOL>)<EOL>

return True if attribute name is protected (start with _ and some other
    details), False otherwise.


def node_frame_class(<EOL>node: astroid.node_classes.NodeNG<EOL>) -> Optional[astroid.node_classes.NodeNG]:

klass = node.frame()<EOL>while klass is not None and not isinstance(klass, astroid.ClassDef):<EOL><INDENT>if klass.parent is None:<EOL><INDENT>klass = None<EOL><DEDENT>else:<EOL><INDENT>klass = klass.parent.frame()<EOL><DEDENT><DEDENT>return klass<EOL>

return klass node for a method node (or a staticmethod or a
    classmethod), return null otherwise


def is_attr_private(attrname: str) -> Optional[Match[str]]:

regex = re.compile("<STR_LIT>")<EOL>return regex.match(attrname)<EOL>

Check that attribute name is private (at least two leading underscores,
    at most one trailing underscore)


def get_argument_from_call(<EOL>call_node: astroid.Call, position: int = None, keyword: str = None<EOL>) -> astroid.Name:

if position is None and keyword is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if position is not None:<EOL><INDENT>try:<EOL><INDENT>return call_node.args[position]<EOL><DEDENT>except IndexError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if keyword and call_node.keywords:<EOL><INDENT>for arg in call_node.keywords:<EOL><INDENT>if arg.arg == keyword:<EOL><INDENT>return arg.value<EOL><DEDENT><DEDENT><DEDENT>raise NoSuchArgumentError<EOL>

Returns the specified argument from a function call.

    :param astroid.Call call_node: Node representing a function call to check.
    :param int position: position of the argument.
    :param str keyword: the keyword of the argument.

    :returns: The node representing the argument, None if the argument is not found.
    :rtype: astroid.Name
    :raises ValueError: if both position and keyword are None.
    :raises NoSuchArgumentError: if no argument at the provided position or with
    the provided keyword.


def inherit_from_std_ex(node: astroid.node_classes.NodeNG) -> bool:

ancestors = node.ancestors() if hasattr(node, "<STR_LIT>") else []<EOL>for ancestor in itertools.chain([node], ancestors):<EOL><INDENT>if (<EOL>ancestor.name in ("<STR_LIT>", "<STR_LIT>")<EOL>and ancestor.root().name == EXCEPTIONS_MODULE<EOL>):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>

Return true if the given class node is subclass of
exceptions.Exception.


def error_of_type(handler: astroid.ExceptHandler, error_type) -> bool:

def stringify_error(error):<EOL><INDENT>if not isinstance(error, str):<EOL><INDENT>return error.__name__<EOL><DEDENT>return error<EOL><DEDENT>if not isinstance(error_type, tuple):<EOL><INDENT>error_type = (error_type,)  <EOL><DEDENT>expected_errors = {stringify_error(error) for error in error_type}  <EOL>if not handler.type:<EOL><INDENT>return True<EOL><DEDENT>return handler.catch(expected_errors)<EOL>

Check if the given exception handler catches
the given error_type.

The *handler* parameter is a node, representing an ExceptHandler node.
The *error_type* can be an exception, such as AttributeError,
the name of an exception, or it can be a tuple of errors.
The function will return True if the handler catches any of the
given errors.


def decorated_with_property(node: astroid.FunctionDef) -> bool:

if not node.decorators:<EOL><INDENT>return False<EOL><DEDENT>for decorator in node.decorators.nodes:<EOL><INDENT>if not isinstance(decorator, astroid.Name):<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>if _is_property_decorator(decorator):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>except astroid.InferenceError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return False<EOL>

Detect if the given function node is decorated with a property.


def decorated_with(func: astroid.FunctionDef, qnames: Iterable[str]) -> bool:

decorators = func.decorators.nodes if func.decorators else []<EOL>for decorator_node in decorators:<EOL><INDENT>try:<EOL><INDENT>if any(<EOL>i is not None and i.qname() in qnames for i in decorator_node.infer()<EOL>):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>except astroid.InferenceError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>return False<EOL>

Determine if the `func` node has a decorator with the qualified name `qname`.


@lru_cache(maxsize=<NUM_LIT>)<EOL>def unimplemented_abstract_methods(<EOL>node: astroid.node_classes.NodeNG, is_abstract_cb: astroid.FunctionDef = None<EOL>) -> Dict[str, astroid.node_classes.NodeNG]:

if is_abstract_cb is None:<EOL><INDENT>is_abstract_cb = partial(decorated_with, qnames=ABC_METHODS)<EOL><DEDENT>visited = {}  <EOL>try:<EOL><INDENT>mro = reversed(node.mro())<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>return {}<EOL><DEDENT>except astroid.ResolveError:<EOL><INDENT>return {}<EOL><DEDENT>for ancestor in mro:<EOL><INDENT>for obj in ancestor.values():<EOL><INDENT>infered = obj<EOL>if isinstance(obj, astroid.AssignName):<EOL><INDENT>infered = safe_infer(obj)<EOL>if not infered:<EOL><INDENT>if obj.name in visited:<EOL><INDENT>del visited[obj.name]<EOL><DEDENT>continue<EOL><DEDENT>if not isinstance(infered, astroid.FunctionDef):<EOL><INDENT>if obj.name in visited:<EOL><INDENT>del visited[obj.name]<EOL><DEDENT><DEDENT><DEDENT>if isinstance(infered, astroid.FunctionDef):<EOL><INDENT>abstract = is_abstract_cb(infered)<EOL>if abstract:<EOL><INDENT>visited[obj.name] = infered<EOL><DEDENT>elif not abstract and obj.name in visited:<EOL><INDENT>del visited[obj.name]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return visited<EOL>

Get the unimplemented abstract methods for the given *node*.

A method can be considered abstract if the callback *is_abstract_cb*
returns a ``True`` value. The check defaults to verifying that
a method is decorated with abstract methods.
The function will work only for new-style classes. For old-style
classes, it will simply return an empty dictionary.
For the rest of them, it will return a dictionary of abstract method
names and their inferred objects.