From fcadcc2ea44651540f1118778a3826bbd4afec48 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Wed, 4 Nov 2015 12:58:43 +0200 Subject: Fix pylint warnings. --- astroid/arguments.py | 4 +-- astroid/helpers.py | 2 +- astroid/scoped_nodes.py | 68 +++++++++++++++++++++++++------------------------ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/astroid/arguments.py b/astroid/arguments.py index e80f5f4..ab841a9 100644 --- a/astroid/arguments.py +++ b/astroid/arguments.py @@ -183,12 +183,12 @@ class CallSite(object): else: # XXX can do better ? boundnode = funcnode.parent.frame() - + if isinstance(boundnode, nodes.ClassDef): # Verify that we're accessing a method # of the metaclass through a class, as in # `cls.metaclass_method`. In this case, the - # first argument is always the class. + # first argument is always the class. method_scope = funcnode.parent.scope() if method_scope is boundnode.metaclass(): return iter((boundnode, )) diff --git a/astroid/helpers.py b/astroid/helpers.py index 00f4784..d4cd0dd 100644 --- a/astroid/helpers.py +++ b/astroid/helpers.py @@ -86,7 +86,7 @@ def object_type(node, context=None): This is used to implement the ``type`` builtin, which means that it's used for inferring type calls, as well as used in a couple of other places - in the inference. + in the inference. The node will be inferred first, so this function can support all sorts of objects, as long as they support inference. """ diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py index e6e3324..729f283 100644 --- a/astroid/scoped_nodes.py +++ b/astroid/scoped_nodes.py @@ -777,43 +777,45 @@ class FunctionDef(node_classes.Statement, Lambda): else: type_name = 'method' - if self.decorators: - for node in self.decorators.nodes: - if isinstance(node, node_classes.Name): - if node.name in builtin_descriptors: - return node.name - - if isinstance(node, node_classes.Call): - # Handle the following case: - # @some_decorator(arg1, arg2) - # def func(...) - # - try: - current = next(node.func.infer()) - except exceptions.InferenceError: - continue - _type = _infer_decorator_callchain(current) + if not self.decorators: + return type_name + + for node in self.decorators.nodes: + if isinstance(node, node_classes.Name): + if node.name in builtin_descriptors: + return node.name + + if isinstance(node, node_classes.Call): + # Handle the following case: + # @some_decorator(arg1, arg2) + # def func(...) + # + try: + current = next(node.func.infer()) + except exceptions.InferenceError: + continue + _type = _infer_decorator_callchain(current) + if _type is not None: + return _type + + try: + for inferred in node.infer(): + # Check to see if this returns a static or a class method. + _type = _infer_decorator_callchain(inferred) if _type is not None: return _type - try: - for inferred in node.infer(): - # Check to see if this returns a static or a class method. - _type = _infer_decorator_callchain(inferred) - if _type is not None: - return _type - - if not isinstance(inferred, ClassDef): + if not isinstance(inferred, ClassDef): + continue + for ancestor in inferred.ancestors(): + if not isinstance(ancestor, ClassDef): continue - for ancestor in inferred.ancestors(): - if not isinstance(ancestor, ClassDef): - continue - if ancestor.is_subtype_of('%s.classmethod' % BUILTINS): - return 'classmethod' - elif ancestor.is_subtype_of('%s.staticmethod' % BUILTINS): - return 'staticmethod' - except exceptions.InferenceError: - pass + if ancestor.is_subtype_of('%s.classmethod' % BUILTINS): + return 'classmethod' + elif ancestor.is_subtype_of('%s.staticmethod' % BUILTINS): + return 'staticmethod' + except exceptions.InferenceError: + pass return type_name @decorators_mod.cachedproperty -- cgit v1.2.1