Exemple #1
0
    def visit_FunctionDef(self, node):
        decorator_names = [
            utils.get_decorator_name(decorator)
            for decorator in node.decorator_list
        ]
        typ = 'property' if '@property' in decorator_names else 'function'
        if any(
                _match(name, self.ignore_decorators)
                for name in decorator_names):
            self._log('Ignoring {} "{}" (decorator whitelisted)'.format(
                typ, node.name))
        elif typ == 'property':
            self._define(self.defined_props, node.name, node)
        else:
            # Function is not a property.
            self._define(self.defined_funcs,
                         node.name,
                         node,
                         ignore=_ignore_function)

        # Detect *args and **kwargs parameters. Python 3 recognizes them
        # in visit_Name. For Python 2 we use this workaround. We can't
        # use visit_arguments, because its node has no lineno.
        for param in [node.args.vararg, node.args.kwarg]:
            if param and isinstance(param, str):
                self._define_variable(param, node, confidence=100)
Exemple #2
0
    def visit_FunctionDef(self, node):
        decorator_names = [
            utils.get_decorator_name(decorator)
            for decorator in node.decorator_list
        ]

        first_arg = node.args.args[0].arg if node.args.args else None

        if "@property" in decorator_names:
            typ = "property"
        elif ("@staticmethod" in decorator_names
              or "@classmethod" in decorator_names or first_arg == "self"):
            typ = "method"
        else:
            typ = "function"

        if any(
                _match(name, self.ignore_decorators)
                for name in decorator_names):
            self._log(f'Ignoring {typ} "{node.name}" (decorator whitelisted)')
        elif typ == "property":
            self._define(self.defined_props, node.name, node)
        elif typ == "method":
            self._define(self.defined_methods,
                         node.name,
                         node,
                         ignore=_ignore_method)
        else:
            self._define(self.defined_funcs,
                         node.name,
                         node,
                         ignore=_ignore_function)
Exemple #3
0
 def visit_ClassDef(self, node):
     for decorator in node.decorator_list:
         if _match(utils.get_decorator_name(decorator),
                   self.ignore_decorators):
             self._log('Ignoring class "{}" (decorator whitelisted)'.format(
                 node.name))
             break
     else:
         self._define(
             self.defined_classes, node.name, node, ignore=_ignore_class)
Exemple #4
0
    def visit_FunctionDef(self, node):
        decorator_names = [
            utils.get_decorator_name(decorator)
            for decorator in node.decorator_list
        ]

        first_arg = None
        if node.args.args:
            try:
                first_arg = node.args.args[0].arg
            except AttributeError:
                # Python 2.7
                first_arg = node.args.args[0].id

        if "@property" in decorator_names:
            typ = "property"
        elif (
            "@staticmethod" in decorator_names
            or "@classmethod" in decorator_names
            or first_arg == "self"
        ):
            typ = "method"
        else:
            typ = "function"

        if any(
            _match(name, self.ignore_decorators) for name in decorator_names
        ):
            self._log(
                'Ignoring {} "{}" (decorator whitelisted)'.format(
                    typ, node.name
                )
            )
        elif typ == "property":
            self._define(self.defined_props, node.name, node)
        elif typ == "method":
            self._define(
                self.defined_methods, node.name, node, ignore=_ignore_method
            )
        else:
            self._define(
                self.defined_funcs, node.name, node, ignore=_ignore_function
            )

        # Detect *args and **kwargs parameters. Python 3 recognizes them
        # in visit_Name. For Python 2 we use this workaround. We can't
        # use visit_arguments, because its node has no lineno.
        for param in [node.args.vararg, node.args.kwarg]:
            if param and isinstance(param, str):
                self._define_variable(param, node, confidence=100)
Exemple #5
0
 def visit_FunctionDef(node):
     for decorator in node.decorator_list:
         decorator_names.append(utils.get_decorator_name(decorator))