diff options
author | Obscuron <Abscuron@gmail.com> | 2015-09-04 16:17:03 -0400 |
---|---|---|
committer | Obscuron <Abscuron@gmail.com> | 2015-09-04 16:17:03 -0400 |
commit | 9a40cafa4ed476a98a144ee4a112f686e518908d (patch) | |
tree | cfb6dc93f0e9a6f25d0a5f967d7ad80598f0853e /pylint/checkers/typecheck.py | |
parent | 562770be06efd98e157f16cb838bce781be91775 (diff) | |
parent | a0e6e67af6f05b81fe7575d4a372b2ea4b20fe46 (diff) | |
download | pylint-9a40cafa4ed476a98a144ee4a112f686e518908d.tar.gz |
fixed merge conflict
Diffstat (limited to 'pylint/checkers/typecheck.py')
-rw-r--r-- | pylint/checkers/typecheck.py | 80 |
1 files changed, 38 insertions, 42 deletions
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 04b2c9d..bc29b9b 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -24,12 +24,8 @@ import sys import astroid import astroid.context -from astroid import ( - InferenceError, NotFoundError, - MroError, SuperError, YES, Instance -) -from astroid.bases import BUILTINS -from astroid.bases import NodeNG +from astroid import bases +from astroid import exceptions from astroid import objects from astroid import helpers import six @@ -45,15 +41,16 @@ from pylint import utils _ZOPE_DEPRECATED = ( "This option is deprecated. Use generated-members instead." ) +BUILTINS = six.moves.builtins.__name__ def _unflatten(iterable): for elem in iterable: if (isinstance(elem, collections.Sequence) and - not isinstance(elem, basestring)): + not isinstance(elem, six.stringtypes)): for subelem in _unflatten(elem): yield subelem - elif isinstance(elem, NodeNG): + elif isinstance(elem, bases.NodeNG): yield elem @@ -173,9 +170,9 @@ def _emit_no_member(node, owner, owner_name, ignored_mixins): return False if ignored_mixins and owner_name[-5:].lower() == 'mixin': return False - if isinstance(owner, astroid.Function) and owner.decorators: + if isinstance(owner, astroid.FunctionDef) and owner.decorators: return False - if isinstance(owner, Instance): + if isinstance(owner, astroid.Instance): if owner.has_dynamic_getattr() or not helpers.has_known_bases(owner): return False if isinstance(owner, objects.Super): @@ -185,7 +182,7 @@ def _emit_no_member(node, owner, owner_name, ignored_mixins): # MRO is invalid. try: owner.super_mro() - except (MroError, SuperError): + except (exceptions.MroError, exceptions.SuperError): return False if not all(map(helpers.has_known_bases, owner.type.mro())): return False @@ -200,11 +197,11 @@ def _determine_callable(callable_obj): return callable_obj, 1, callable_obj.type elif isinstance(callable_obj, astroid.UnboundMethod): return callable_obj, 0, 'unbound method' - elif isinstance(callable_obj, astroid.Function): + elif isinstance(callable_obj, astroid.FunctionDef): return callable_obj, 0, callable_obj.type elif isinstance(callable_obj, astroid.Lambda): return callable_obj, 0, 'lambda' - elif isinstance(callable_obj, astroid.Class): + elif isinstance(callable_obj, astroid.ClassDef): # Class instantiation, lookup __new__ instead. # If we only find object.__new__, we can safely check __init__ # instead. If __new__ belongs to builtins, then we look @@ -213,7 +210,7 @@ def _determine_callable(callable_obj): try: # Use the last definition of __new__. new = callable_obj.local_attr('__new__')[-1] - except astroid.NotFoundError: + except exceptions.NotFoundError: new = None from_object = new and new.parent.scope().name == 'object' @@ -223,13 +220,13 @@ def _determine_callable(callable_obj): try: # Use the last definition of __init__. callable_obj = callable_obj.local_attr('__init__')[-1] - except astroid.NotFoundError: + except exceptions.NotFoundError: # do nothing, covered by no-init. raise ValueError else: callable_obj = new - if not isinstance(callable_obj, astroid.Function): + if not isinstance(callable_obj, astroid.FunctionDef): raise ValueError # both have an extra implicit 'cls'/'self' argument. return callable_obj, 1, 'constructor' @@ -292,15 +289,15 @@ accessed. Python regular expressions are accepted.'} # do this in open since config not fully initialized in __init__ self.generated_members = list(self.config.generated_members) - def visit_assattr(self, node): - if isinstance(node.ass_type(), astroid.AugAssign): - self.visit_getattr(node) + def visit_assignattr(self, node): + if isinstance(node.assign_type(), astroid.AugAssign): + self.visit_attribute(node) def visit_delattr(self, node): - self.visit_getattr(node) + self.visit_attribute(node) @check_messages('no-member') - def visit_getattr(self, node): + def visit_attribute(self, node): """check that the accessed attribute exists to avoid too much false positives for now, we'll consider the code as @@ -323,14 +320,14 @@ accessed. Python regular expressions are accepted.'} return try: infered = list(node.expr.infer()) - except InferenceError: + except exceptions.InferenceError: return # list of (node, nodename) which are missing the attribute missingattr = set() inference_failure = False for owner in infered: # skip yes object - if owner is YES: + if owner is astroid.YES: inference_failure = True continue @@ -347,7 +344,7 @@ accessed. Python regular expressions are accepted.'} except AttributeError: # XXX method / function continue - except NotFoundError: + except exceptions.NotFoundError: # This can't be moved before the actual .getattr call, # because there can be more values inferred and we are # stopping after the first one which has the attribute in question. @@ -367,7 +364,7 @@ accessed. Python regular expressions are accepted.'} # message for infered nodes done = set() for owner, name in missingattr: - if isinstance(owner, Instance): + if isinstance(owner, astroid.Instance): actual = owner._proxied else: actual = owner @@ -385,18 +382,18 @@ accessed. Python regular expressions are accepted.'} """check that if assigning to a function call, the function is possibly returning something valuable """ - if not isinstance(node.value, astroid.CallFunc): + if not isinstance(node.value, astroid.Call): return function_node = helpers.safe_infer(node.value.func) # skip class, generator and incomplete function definition - if not (isinstance(function_node, astroid.Function) and + if not (isinstance(function_node, astroid.FunctionDef) and function_node.root().fully_defined()): return if function_node.is_generator() \ or function_node.is_abstract(pass_is_abstract=False): return returns = list(function_node.nodes_of_class(astroid.Return, - skip_klass=astroid.Function)) + skip_klass=astroid.FunctionDef)) if len(returns) == 0: self.add_message('assignment-from-no-return', node=node) else: @@ -413,7 +410,7 @@ accessed. Python regular expressions are accepted.'} Check that the given uninferable CallFunc node does not call an actual function. """ - if not isinstance(node.func, astroid.Getattr): + if not isinstance(node.func, astroid.Attribute): return # Look for properties. First, obtain @@ -432,13 +429,13 @@ accessed. Python regular expressions are accepted.'} try: attrs = klass._proxied.getattr(node.func.attrname) - except astroid.NotFoundError: + except exceptions.NotFoundError: return for attr in attrs: if attr is astroid.YES: continue - if not isinstance(attr, astroid.Function): + if not isinstance(attr, astroid.FunctionDef): continue # Decorated, see if it is decorated with a property. @@ -453,7 +450,7 @@ accessed. Python regular expressions are accepted.'} break @check_messages(*(list(MSGS.keys()))) - def visit_callfunc(self, node): + def visit_call(self, node): """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 @@ -497,7 +494,7 @@ accessed. Python regular expressions are accepted.'} # Don't store any parameter names within the tuple, since those # are not assignable from keyword arguments. else: - assert isinstance(arg, astroid.AssName) + assert isinstance(arg, astroid.AssignName) # This occurs with: # def f( (a), (b) ): pass name = arg.name @@ -513,7 +510,7 @@ accessed. Python regular expressions are accepted.'} if isinstance(arg, astroid.Keyword): name = arg.arg else: - assert isinstance(arg, astroid.AssName) + assert isinstance(arg, astroid.AssignName) name = arg.name kwparams[name] = [called.args.kw_defaults[i], False] @@ -618,7 +615,7 @@ accessed. Python regular expressions are accepted.'} # slice or instances with __index__. parent_type = helpers.safe_infer(node.parent.value) - if not isinstance(parent_type, (astroid.Class, astroid.Instance)): + if not isinstance(parent_type, (astroid.ClassDef, astroid.Instance)): return # Determine what method on the parent this index will use @@ -641,10 +638,10 @@ accessed. Python regular expressions are accepted.'} if methods is astroid.YES: return itemmethod = methods[0] - except (astroid.NotFoundError, IndexError): + except (exceptions.NotFoundError, IndexError): return - if not isinstance(itemmethod, astroid.Function): + if not isinstance(itemmethod, astroid.FunctionDef): return if itemmethod.root().name != BUILTINS: return @@ -674,7 +671,7 @@ accessed. Python regular expressions are accepted.'} try: index_type.getattr('__index__') return - except astroid.NotFoundError: + except exceptions.NotFoundError: pass # Anything else is an error @@ -705,13 +702,12 @@ accessed. Python regular expressions are accepted.'} try: index_type.getattr('__index__') return - except astroid.NotFoundError: + except exceptions.NotFoundError: pass # Anything else is an error self.add_message('invalid-slice-index', node=node) - @check_messages('not-context-manager') def visit_with(self, node): for ctx_mgr, _ in node.items: @@ -737,7 +733,7 @@ accessed. Python regular expressions are accepted.'} # of self explaining tests. for path in six.moves.filter(None, _unflatten(context.path)): scope = path.scope() - if not isinstance(scope, astroid.Function): + if not isinstance(scope, astroid.FunctionDef): continue if decorated_with(scope, ['contextlib.contextmanager']): break @@ -748,7 +744,7 @@ accessed. Python regular expressions are accepted.'} try: infered.getattr('__enter__') infered.getattr('__exit__') - except astroid.NotFoundError: + except exceptions.NotFoundError: if isinstance(infered, astroid.Instance): # If we do not know the bases of this class, # just skip it. |