diff options
author | Ceridwen <ceridwenv@gmail.com> | 2015-11-06 17:55:24 -0500 |
---|---|---|
committer | Ceridwen <ceridwenv@gmail.com> | 2015-11-06 17:55:24 -0500 |
commit | e28cf4e572d25d559c274acc81a7aff887d28efb (patch) | |
tree | 2437d1981dee3eb5d042ae478968f5f6e807125c /astroid/scoped_nodes.py | |
parent | f5c3e703ec3de5d6e4f50583475d7b18fb0d6beb (diff) | |
download | astroid-e28cf4e572d25d559c274acc81a7aff887d28efb.tar.gz |
Rename Uninferable and instantiate_class, fix broken tests, improve
testing.
* Rename YES to Uninferable
* Rename instanciate_class to instantiate_class.
* Use six in test_namedtuple_advanced_inference.
* Fix test_file_from_module failure on PyPy.
* Add enum34 to unittest_brain.
* Add unittest_brain dependencies tox.ini.
Diffstat (limited to 'astroid/scoped_nodes.py')
-rw-r--r-- | astroid/scoped_nodes.py | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py index e6e3324..c75cd7a 100644 --- a/astroid/scoped_nodes.py +++ b/astroid/scoped_nodes.py @@ -552,7 +552,7 @@ class DictComp(ComprehensionScope): self.generators = generators def bool_value(self): - return util.YES + return util.Uninferable class SetComp(ComprehensionScope): @@ -573,7 +573,7 @@ class SetComp(ComprehensionScope): self.generators = generators def bool_value(self): - return util.YES + return util.Uninferable class _ListComp(node_classes.NodeNG): @@ -587,7 +587,7 @@ class _ListComp(node_classes.NodeNG): self.generators = generators def bool_value(self): - return util.YES + return util.Uninferable if six.PY3: @@ -935,7 +935,7 @@ class FunctionDef(node_classes.Statement, Lambda): c.hide = True c.parent = self class_bases = [next(b.infer(context)) for b in caller.args[1:]] - c.bases = [base for base in class_bases if base != util.YES] + c.bases = [base for base in class_bases if base != util.Uninferable] c._metaclass = metaclass yield c return @@ -948,7 +948,7 @@ class FunctionDef(node_classes.Statement, Lambda): for inferred in returnnode.value.infer(context): yield inferred except exceptions.InferenceError: - yield util.YES + yield util.Uninferable def bool_value(self): return True @@ -989,7 +989,7 @@ def _is_metaclass(klass, seen=None): if isinstance(baseobj, bases.Instance): # not abstract return False - if baseobj is util.YES: + if baseobj is util.Uninferable: continue if baseobj is klass: continue @@ -1159,7 +1159,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, isinstance(name_node.value, six.string_types)): name = name_node.value else: - return util.YES + return util.Uninferable result = ClassDef(name, None) @@ -1169,9 +1169,9 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, result.bases = class_bases.itered() else: # There is currently no AST node that can represent an 'unknown' - # node (YES is not an AST node), therefore we simply return YES here + # node (Uninferable is not an AST node), therefore we simply return Uninferable here # although we know at least the name of the class. - return util.YES + return util.Uninferable # Get the members of the class try: @@ -1336,16 +1336,23 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, raise exceptions.NotFoundError(name) return values - def instanciate_class(self): + def instantiate_class(self): """return Instance of ClassDef node, else return self""" return bases.Instance(self) + def instanciate_class(self): + warnings.warn('%s.instanciate_class() is deprecated and slated for ' + ' removal in astroid 2.0, use %s.instantiate_class() ' + ' instead.' % (type(self).__name__, type(self).__name__), + PendingDeprecationWarning, stacklevel=2) + return self.instantiate_class() + def getattr(self, name, context=None, class_context=True): """Get an attribute from this class, using Python's attribute semantic This method doesn't look in the instance_attrs dictionary since it's done by an Instance proxy at inference time. It - may return a YES object if the attribute has not been actually + may return a Uninferable object if the attribute has not been actually found but a __getattr__ or __getattribute__ method is defined. If *class_context* is given, then it's considered that the attribute is accessed from a class context, @@ -1434,7 +1441,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, try: for inferred in bases._infer_stmts(self.getattr(name, context), context, frame=self): - # yield YES object instead of descriptors when necessary + # yield Uninferable object instead of descriptors when necessary if (not isinstance(inferred, node_classes.Const) and isinstance(inferred, bases.Instance)): try: @@ -1442,13 +1449,13 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, except exceptions.NotFoundError: yield inferred else: - yield util.YES + yield util.Uninferable else: yield function_to_method(inferred, self) except exceptions.NotFoundError: if not name.startswith('__') and self.has_dynamic_getattr(context): - # class handle some dynamic attributes, return a YES object - yield util.YES + # class handle some dynamic attributes, return a Uninferable object + yield util.Uninferable else: util.reraise(exceptions.InferenceError(name)) @@ -1529,7 +1536,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, # Expects this from Py3k TreeRebuilder try: return next(node for node in self._metaclass.infer() - if node is not util.YES) + if node is not util.Uninferable) except (exceptions.InferenceError, StopIteration): return None if six.PY3: @@ -1552,7 +1559,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, inferred = next(assignment.infer()) except exceptions.InferenceError: return - if inferred is util.YES: # don't expose this + if inferred is util.Uninferable: # don't expose this return None return inferred @@ -1611,7 +1618,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, values = [item[0] for item in slots.items] else: values = slots.itered() - if values is util.YES: + if values is util.Uninferable: continue if not values: # Stop the iteration, because the class @@ -1621,7 +1628,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, for elt in values: try: for inferred in elt.infer(): - if inferred is util.YES: + if inferred is util.Uninferable: continue if (not isinstance(inferred, node_classes.Const) or not isinstance(inferred.value, |