summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--README40
-rw-r--r--__init__.py40
-rw-r--r--__pkginfo__.py17
-rw-r--r--as_string.py134
-rw-r--r--bases.py30
-rw-r--r--brain/py2mechanize.py6
-rw-r--r--brain/py2qt4.py8
-rw-r--r--brain/py2stdlib.py18
-rw-r--r--builder.py46
-rw-r--r--debian.sid/control31
-rwxr-xr-xdebian.sid/rules7
-rw-r--r--debian/control22
-rw-r--r--debian/copyright6
-rw-r--r--debian/python-astroid.dirs1
-rw-r--r--debian/python-logilab-astng.dirs1
-rwxr-xr-xdebian/rules26
-rw-r--r--debian/watch2
-rw-r--r--exceptions.py24
-rw-r--r--inference.py28
-rw-r--r--inspector.py50
-rw-r--r--manager.py136
-rw-r--r--mixins.py12
-rw-r--r--node_classes.py98
-rw-r--r--nodes.py14
-rw-r--r--protocols.py18
-rw-r--r--raw_building.py64
-rw-r--r--rebuilder.py24
-rw-r--r--scoped_nodes.py88
-rw-r--r--setup.py8
-rw-r--r--test/data/module.py4
-rw-r--r--test/regrtest_data/package/import_package_subpackage_module.py24
-rw-r--r--test/unittest_builder.py216
-rw-r--r--test/unittest_inference.py382
-rw-r--r--test/unittest_inspector.py12
-rw-r--r--test/unittest_lookup.py108
-rw-r--r--test/unittest_manager.py74
-rw-r--r--test/unittest_nodes.py106
-rw-r--r--test/unittest_python3.py24
-rw-r--r--test/unittest_regrtest.py44
-rw-r--r--test/unittest_scoped_nodes.py114
-rw-r--r--test/unittest_utils.py44
-rw-r--r--utils.py32
43 files changed, 1100 insertions, 1090 deletions
diff --git a/ChangeLog b/ChangeLog
index 3a08632..4d7951f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
-Change log for the astng package
-================================
+Change log for the astroid package (used to be astng)
+=====================================================
+
+--
+ * rename the project as astroid
2013-04-16 -- 0.24.3
* #124360 [py3.3]: Don't crash on 'yield from' nodes
diff --git a/README b/README
index db8dca1..426fbd7 100644
--- a/README
+++ b/README
@@ -1,47 +1,49 @@
-ASTNG
-=====
+Astroid
+=======
-What's this ?
--------------
+What's this?
+------------
The aim of this module is to provide a common base representation of
python source code for projects such as pychecker, pyreverse,
pylint... Well, actually the development of this library is essentially
-governed by pylint's needs.
+governed by pylint's needs. It used to be called logilab-astng.
-It provides a compatible representation which comes from the `_ast` module.
-It rebuilds the tree generated by the builtin _ast module by recursively
-walking down the AST and building an extended ast (let's call it astng ;). The
-new node classes have additional methods and attributes for different usages.
-They include some support for static inference and local name scopes.
-Furthermore, astng builds partial trees by inspecting living objects.
+It provides a compatible representation which comes from the `_ast`
+module. It rebuilds the tree generated by the builtin _ast module by
+recursively walking down the AST and building an extended ast. The new
+node classes have additional methods and attributes for different
+usages. They include some support for static inference and local name
+scopes. Furthermore, astroid builds partial trees by inspecting living
+objects.
Main modules are:
* `bases`, `node_classses` and `scoped_nodes` contain the classes for the
different type of nodes of the tree.
-* the `manager` contains a high level object to get astng trees from
+* the `manager` contains a high level object to get astroid trees from
source files and living objects. It maintains a cache of previously
- constructed tree for quick access
+ constructed tree for quick access.
Installation
------------
-Extract the tarball, jump into the created directory and run ::
+Extract the tarball, jump into the created directory and run::
python setup.py install
-For installation options, see ::
+For installation options, see::
python setup.py install --help
-If you have any questions, please mail the
-python-project@lists.logilab.org mailing list for support. See
-http://lists.logilab.org/mailman/listinfo/python-projects for
-subscription information and archives.
+If you have any questions, please mail the code-quality@python.org
+mailing list for support. See
+http://mail.python.org/mailman/listinfo/code-quality for subscription
+information and archives. You may find older archives at
+http://lists.logilab.org/mailman/listinfo/python-projects .
Test
----
diff --git a/__init__.py b/__init__.py
index c43e793..e3b6e3b 100644
--- a/__init__.py
+++ b/__init__.py
@@ -1,20 +1,20 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
"""Python Abstract Syntax Tree New Generation
The aim of this module is to provide a common base representation of
@@ -25,7 +25,7 @@ governed by pylint's needs.
It extends class defined in the python's _ast module with some
additional methods and attributes. Instance attributes are added by a
builder object, which can either generate extended ast (let's call
-them astng ;) by visiting an existent ast tree or by inspecting living
+them astroid ;) by visiting an existent ast tree or by inspecting living
object. Methods are added by monkey patching ast classes.
Main modules are:
@@ -33,11 +33,11 @@ Main modules are:
* nodes and scoped_nodes for more information about methods and
attributes added to different node classes
-* the manager contains a high level object to get astng trees from
+* the manager contains a high level object to get astroid trees from
source files and living objects. It maintains a cache of previously
constructed tree for quick access
-* builder contains the class responsible to build astng trees
+* builder contains the class responsible to build astroid trees
"""
__doctype__ = "restructuredtext en"
@@ -45,26 +45,26 @@ import sys
# WARNING: internal imports order matters !
-# make all exception classes accessible from astng package
-from logilab.astng.exceptions import *
+# make all exception classes accessible from astroid package
+from astroid.exceptions import *
-# make all node classes accessible from astng package
-from logilab.astng.nodes import *
+# make all node classes accessible from astroid package
+from astroid.nodes import *
# trigger extra monkey-patching
-from logilab.astng import inference
+from astroid import inference
# more stuff available
-from logilab.astng import raw_building
-from logilab.astng.bases import YES, Instance, BoundMethod, UnboundMethod
-from logilab.astng.node_classes import are_exclusive, unpack_infer
-from logilab.astng.scoped_nodes import builtin_lookup
+from astroid import raw_building
+from astroid.bases import YES, Instance, BoundMethod, UnboundMethod
+from astroid.node_classes import are_exclusive, unpack_infer
+from astroid.scoped_nodes import builtin_lookup
# make a manager instance (borg) as well as Project and Package classes
-# accessible from astng package
-from logilab.astng.manager import ASTNGManager, Project
-MANAGER = ASTNGManager()
-del ASTNGManager
+# accessible from astroid package
+from astroid.manager import AstroidManager, Project
+MANAGER = AstroidManager()
+del AstroidManager
# load brain plugins
from os import listdir
diff --git a/__pkginfo__.py b/__pkginfo__.py
index 65f0778..971de91 100644
--- a/__pkginfo__.py
+++ b/__pkginfo__.py
@@ -1,26 +1,25 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""logilab.astng packaging information"""
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""astroid packaging information"""
-distname = 'logilab-astng'
+distname = 'astroid'
-modname = 'astng'
-subpackage_of = 'logilab'
+modname = 'astroid'
numversion = (0, 24, 3)
version = '.'.join([str(num) for num in numversion])
@@ -32,7 +31,7 @@ license = 'LGPL'
author = 'Logilab'
author_email = 'python-projects@lists.logilab.org'
mailinglist = "mailto://%s" % author_email
-web = 'http://bitbucket.org/logilab/astng'
+web = 'http://bitbucket.org/logilab/astroid'
description = "rebuild a new abstract syntax tree from Python's ast"
diff --git a/as_string.py b/as_string.py
index c21144e..360e9bb 100644
--- a/as_string.py
+++ b/as_string.py
@@ -1,21 +1,21 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""This module renders ASTNG nodes as string:
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""This module renders Astroid nodes as string:
* :func:`to_code` function return equivalent (hopefuly valid) python string
@@ -29,7 +29,7 @@ INDENT = ' ' # 4 spaces ; keep indentation variable
def dump(node, ids=False):
- """print a nice astng tree representation.
+ """print a nice astroid tree representation.
:param ids: if true, we also print the ids (usefull for debugging)
"""
@@ -41,7 +41,7 @@ def _repr_tree(node, result, indent='', _done=None, ids=False):
"""built a tree representation of a node as a list of lines"""
if _done is None:
_done = set()
- if not hasattr(node, '_astng_fields'): # not a astng node
+ if not hasattr(node, '_astroid_fields'): # not a astroid node
return
if node in _done:
result.append( indent + 'loop in tree: %s' % node )
@@ -52,7 +52,7 @@ def _repr_tree(node, result, indent='', _done=None, ids=False):
node_str += ' . \t%x' % id(node)
result.append( indent + node_str )
indent += INDENT
- for field in node._astng_fields:
+ for field in node._astroid_fields:
value = getattr(node, field)
if isinstance(value, (list, tuple) ):
result.append( indent + field + " = [" )
@@ -71,7 +71,7 @@ def _repr_tree(node, result, indent='', _done=None, ids=False):
class AsStringVisitor(object):
- """Visitor to render an ASTNG node as a valid python code string"""
+ """Visitor to render an Astroid node as a valid python code string"""
def __call__(self, node):
"""Makes this visitor behave as a simple function"""
@@ -86,52 +86,52 @@ class AsStringVisitor(object):
## visit_<node> methods ###########################################
def visit_arguments(self, node):
- """return an astng.Function node as string"""
+ """return an astroid.Function node as string"""
return node.format_args()
def visit_assattr(self, node):
- """return an astng.AssAttr node as string"""
+ """return an astroid.AssAttr node as string"""
return self.visit_getattr(node)
def visit_assert(self, node):
- """return an astng.Assert node as string"""
+ """return an astroid.Assert node as string"""
if node.fail:
return 'assert %s, %s' % (node.test.accept(self),
node.fail.accept(self))
return 'assert %s' % node.test.accept(self)
def visit_assname(self, node):
- """return an astng.AssName node as string"""
+ """return an astroid.AssName node as string"""
return node.name
def visit_assign(self, node):
- """return an astng.Assign node as string"""
+ """return an astroid.Assign node as string"""
lhs = ' = '.join([n.accept(self) for n in node.targets])
return '%s = %s' % (lhs, node.value.accept(self))
def visit_augassign(self, node):
- """return an astng.AugAssign node as string"""
+ """return an astroid.AugAssign node as string"""
return '%s %s %s' % (node.target.accept(self), node.op, node.value.accept(self))
def visit_backquote(self, node):
- """return an astng.Backquote node as string"""
+ """return an astroid.Backquote node as string"""
return '`%s`' % node.value.accept(self)
def visit_binop(self, node):
- """return an astng.BinOp node as string"""
+ """return an astroid.BinOp node as string"""
return '(%s) %s (%s)' % (node.left.accept(self), node.op, node.right.accept(self))
def visit_boolop(self, node):
- """return an astng.BoolOp node as string"""
+ """return an astroid.BoolOp node as string"""
return (' %s ' % node.op).join(['(%s)' % n.accept(self)
for n in node.values])
def visit_break(self, node):
- """return an astng.Break node as string"""
+ """return an astroid.Break node as string"""
return 'break'
def visit_callfunc(self, node):
- """return an astng.CallFunc node as string"""
+ """return an astroid.CallFunc node as string"""
expr_str = node.func.accept(self)
args = [arg.accept(self) for arg in node.args]
if node.starargs:
@@ -141,7 +141,7 @@ class AsStringVisitor(object):
return '%s(%s)' % (expr_str, ', '.join(args))
def visit_class(self, node):
- """return an astng.Class node as string"""
+ """return an astroid.Class node as string"""
decorate = node.decorators and node.decorators.accept(self) or ''
bases = ', '.join([n.accept(self) for n in node.bases])
bases = bases and '(%s)' % bases or ''
@@ -150,54 +150,54 @@ class AsStringVisitor(object):
self._stmt_list( node.body))
def visit_compare(self, node):
- """return an astng.Compare node as string"""
+ """return an astroid.Compare node as string"""
rhs_str = ' '.join(['%s %s' % (op, expr.accept(self))
for op, expr in node.ops])
return '%s %s' % (node.left.accept(self), rhs_str)
def visit_comprehension(self, node):
- """return an astng.Comprehension node as string"""
+ """return an astroid.Comprehension node as string"""
ifs = ''.join([ ' if %s' % n.accept(self) for n in node.ifs])
return 'for %s in %s%s' % (node.target.accept(self),
node.iter.accept(self), ifs )
def visit_const(self, node):
- """return an astng.Const node as string"""
+ """return an astroid.Const node as string"""
return repr(node.value)
def visit_continue(self, node):
- """return an astng.Continue node as string"""
+ """return an astroid.Continue node as string"""
return 'continue'
def visit_delete(self, node): # XXX check if correct
- """return an astng.Delete node as string"""
+ """return an astroid.Delete node as string"""
return 'del %s' % ', '.join([child.accept(self)
for child in node.targets])
def visit_delattr(self, node):
- """return an astng.DelAttr node as string"""
+ """return an astroid.DelAttr node as string"""
return self.visit_getattr(node)
def visit_delname(self, node):
- """return an astng.DelName node as string"""
+ """return an astroid.DelName node as string"""
return node.name
def visit_decorators(self, node):
- """return an astng.Decorators node as string"""
+ """return an astroid.Decorators node as string"""
return '@%s\n' % '\n@'.join([item.accept(self) for item in node.nodes])
def visit_dict(self, node):
- """return an astng.Dict node as string"""
+ """return an astroid.Dict node as string"""
return '{%s}' % ', '.join(['%s: %s' % (key.accept(self),
value.accept(self)) for key, value in node.items])
def visit_dictcomp(self, node):
- """return an astng.DictComp node as string"""
+ """return an astroid.DictComp node as string"""
return '{%s: %s %s}' % (node.key.accept(self), node.value.accept(self),
' '.join([n.accept(self) for n in node.generators]))
def visit_discard(self, node):
- """return an astng.Discard node as string"""
+ """return an astroid.Discard node as string"""
return node.value.accept(self)
def visit_emptynode(self, node):
@@ -216,7 +216,7 @@ class AsStringVisitor(object):
return '%s:\n%s' % (excs, self._stmt_list(node.body))
def visit_ellipsis(self, node):
- """return an astng.Ellipsis node as string"""
+ """return an astroid.Ellipsis node as string"""
return '...'
def visit_empty(self, node):
@@ -224,7 +224,7 @@ class AsStringVisitor(object):
return ''
def visit_exec(self, node):
- """return an astng.Exec node as string"""
+ """return an astroid.Exec node as string"""
if node.locals:
return 'exec %s in %s, %s' % (node.expr.accept(self),
node.locals.accept(self),
@@ -235,11 +235,11 @@ class AsStringVisitor(object):
return 'exec %s' % node.expr.accept(self)
def visit_extslice(self, node):
- """return an astng.ExtSlice node as string"""
+ """return an astroid.ExtSlice node as string"""
return ','.join( [dim.accept(self) for dim in node.dims] )
def visit_for(self, node):
- """return an astng.For node as string"""
+ """return an astroid.For node as string"""
fors = 'for %s in %s:\n%s' % (node.target.accept(self),
node.iter.accept(self),
self._stmt_list( node.body))
@@ -248,78 +248,78 @@ class AsStringVisitor(object):
return fors
def visit_from(self, node):
- """return an astng.From node as string"""
+ """return an astroid.From node as string"""
return 'from %s import %s' % ('.' * (node.level or 0) + node.modname,
_import_string(node.names))
def visit_function(self, node):
- """return an astng.Function node as string"""
+ """return an astroid.Function node as string"""
decorate = node.decorators and node.decorators.accept(self) or ''
docs = node.doc and '\n%s"""%s"""' % (INDENT, node.doc) or ''
return '\n%sdef %s(%s):%s\n%s' % (decorate, node.name, node.args.accept(self),
docs, self._stmt_list(node.body))
def visit_genexpr(self, node):
- """return an astng.GenExpr node as string"""
+ """return an astroid.GenExpr node as string"""
return '(%s %s)' % (node.elt.accept(self), ' '.join([n.accept(self)
for n in node.generators]))
def visit_getattr(self, node):
- """return an astng.Getattr node as string"""
+ """return an astroid.Getattr node as string"""
return '%s.%s' % (node.expr.accept(self), node.attrname)
def visit_global(self, node):
- """return an astng.Global node as string"""
+ """return an astroid.Global node as string"""
return 'global %s' % ', '.join(node.names)
def visit_if(self, node):
- """return an astng.If node as string"""
+ """return an astroid.If node as string"""
ifs = ['if %s:\n%s' % (node.test.accept(self), self._stmt_list(node.body))]
if node.orelse:# XXX use elif ???
ifs.append('else:\n%s' % self._stmt_list(node.orelse))
return '\n'.join(ifs)
def visit_ifexp(self, node):
- """return an astng.IfExp node as string"""
+ """return an astroid.IfExp node as string"""
return '%s if %s else %s' % (node.body.accept(self),
node.test.accept(self), node.orelse.accept(self))
def visit_import(self, node):
- """return an astng.Import node as string"""
+ """return an astroid.Import node as string"""
return 'import %s' % _import_string(node.names)
def visit_keyword(self, node):
- """return an astng.Keyword node as string"""
+ """return an astroid.Keyword node as string"""
return '%s=%s' % (node.arg, node.value.accept(self))
def visit_lambda(self, node):
- """return an astng.Lambda node as string"""
+ """return an astroid.Lambda node as string"""
return 'lambda %s: %s' % (node.args.accept(self), node.body.accept(self))
def visit_list(self, node):
- """return an astng.List node as string"""
+ """return an astroid.List node as string"""
return '[%s]' % ', '.join([child.accept(self) for child in node.elts])
def visit_listcomp(self, node):
- """return an astng.ListComp node as string"""
+ """return an astroid.ListComp node as string"""
return '[%s %s]' % (node.elt.accept(self), ' '.join([n.accept(self)
for n in node.generators]))
def visit_module(self, node):
- """return an astng.Module node as string"""
+ """return an astroid.Module node as string"""
docs = node.doc and '"""%s"""\n\n' % node.doc or ''
return docs + '\n'.join([n.accept(self) for n in node.body]) + '\n\n'
def visit_name(self, node):
- """return an astng.Name node as string"""
+ """return an astroid.Name node as string"""
return node.name
def visit_pass(self, node):
- """return an astng.Pass node as string"""
+ """return an astroid.Pass node as string"""
return 'pass'
def visit_print(self, node):
- """return an astng.Print node as string"""
+ """return an astroid.Print node as string"""
nodes = ', '.join([n.accept(self) for n in node.values])
if not node.nl:
nodes = '%s,' % nodes
@@ -328,7 +328,7 @@ class AsStringVisitor(object):
return 'print %s' % nodes
def visit_raise(self, node):
- """return an astng.Raise node as string"""
+ """return an astroid.Raise node as string"""
if node.exc:
if node.inst:
if node.tback:
@@ -341,27 +341,27 @@ class AsStringVisitor(object):
return 'raise'
def visit_return(self, node):
- """return an astng.Return node as string"""
+ """return an astroid.Return node as string"""
if node.value:
return 'return %s' % node.value.accept(self)
else:
return 'return'
def visit_index(self, node):
- """return a astng.Index node as string"""
+ """return a astroid.Index node as string"""
return node.value.accept(self)
def visit_set(self, node):
- """return an astng.Set node as string"""
+ """return an astroid.Set node as string"""
return '{%s}' % ', '.join([child.accept(self) for child in node.elts])
def visit_setcomp(self, node):
- """return an astng.SetComp node as string"""
+ """return an astroid.SetComp node as string"""
return '{%s %s}' % (node.elt.accept(self), ' '.join([n.accept(self)
for n in node.generators]))
def visit_slice(self, node):
- """return a astng.Slice node as string"""
+ """return a astroid.Slice node as string"""
lower = node.lower and node.lower.accept(self) or ''
upper = node.upper and node.upper.accept(self) or ''
step = node.step and node.step.accept(self) or ''
@@ -370,11 +370,11 @@ class AsStringVisitor(object):
return '%s:%s' % (lower, upper)
def visit_subscript(self, node):
- """return an astng.Subscript node as string"""
+ """return an astroid.Subscript node as string"""
return '%s[%s]' % (node.value.accept(self), node.slice.accept(self))
def visit_tryexcept(self, node):
- """return an astng.TryExcept node as string"""
+ """return an astroid.TryExcept node as string"""
trys = ['try:\n%s' % self._stmt_list( node.body)]
for handler in node.handlers:
trys.append(handler.accept(self))
@@ -383,16 +383,16 @@ class AsStringVisitor(object):
return '\n'.join(trys)
def visit_tryfinally(self, node):
- """return an astng.TryFinally node as string"""
+ """return an astroid.TryFinally node as string"""
return 'try:\n%s\nfinally:\n%s' % (self._stmt_list( node.body),
self._stmt_list(node.finalbody))
def visit_tuple(self, node):
- """return an astng.Tuple node as string"""
+ """return an astroid.Tuple node as string"""
return '(%s)' % ', '.join([child.accept(self) for child in node.elts])
def visit_unaryop(self, node):
- """return an astng.UnaryOp node as string"""
+ """return an astroid.UnaryOp node as string"""
if node.op == 'not':
operator = 'not '
else:
@@ -400,7 +400,7 @@ class AsStringVisitor(object):
return '%s%s' % (operator, node.operand.accept(self))
def visit_while(self, node):
- """return an astng.While node as string"""
+ """return an astroid.While node as string"""
whiles = 'while %s:\n%s' % (node.test.accept(self),
self._stmt_list(node.body))
if node.orelse:
@@ -408,7 +408,7 @@ class AsStringVisitor(object):
return whiles
def visit_with(self, node): # 'with' without 'as' is possible
- """return an astng.With node as string"""
+ """return an astroid.With node as string"""
as_var = node.vars and " as (%s)" % (node.vars.accept(self)) or ""
withs = 'with (%s)%s:\n%s' % (node.expr.accept(self), as_var,
self._stmt_list( node.body))
@@ -439,11 +439,11 @@ class AsStringVisitor3k(AsStringVisitor):
return '%s:\n%s' % (excs, self._stmt_list(node.body))
def visit_nonlocal(self, node):
- """return an astng.Nonlocal node as string"""
+ """return an astroid.Nonlocal node as string"""
return 'nonlocal %s' % ', '.join(node.names)
def visit_raise(self, node):
- """return an astng.Raise node as string"""
+ """return an astroid.Raise node as string"""
if node.exc:
if node.cause:
return 'raise %s from %s' % (node.exc.accept(self),
diff --git a/bases.py b/bases.py
index 33fa0e8..c76e9bc 100644
--- a/bases.py
+++ b/bases.py
@@ -1,20 +1,20 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
"""This module contains base classes and functions for the nodes and some
inference utils.
"""
@@ -24,7 +24,7 @@ __docformat__ = "restructuredtext en"
import sys
from contextlib import contextmanager
-from logilab.astng.exceptions import (InferenceError, ASTNGError,
+from astroid.exceptions import (InferenceError, AstroidError,
NotFoundError, UnresolvableName)
@@ -339,7 +339,7 @@ def raise_if_nothing_infered(func):
# Node ######################################################################
class NodeNG(object):
- """Base Class for all ASTNG node classes.
+ """Base Class for all Astroid node classes.
It represents a node of the new abstract syntax tree.
"""
@@ -354,7 +354,7 @@ class NodeNG(object):
# parent node in the tree
parent = None
# attributes containing child node(s) redefined in most concrete classes:
- _astng_fields = ()
+ _astroid_fields = ()
def _repr_name(self):
"""return self.name or self.attrname or '' for nice representation"""
@@ -377,7 +377,7 @@ class NodeNG(object):
return func(self)
def get_children(self):
- for field in self._astng_fields:
+ for field in self._astroid_fields:
attr = getattr(self, field)
if attr is None:
continue
@@ -389,7 +389,7 @@ class NodeNG(object):
def last_child(self):
"""an optimized version of list(get_children())[-1]"""
- for field in self._astng_fields[::-1]:
+ for field in self._astroid_fields[::-1]:
attr = getattr(self, field)
if not attr: # None or empty listy / tuple
continue
@@ -433,7 +433,7 @@ class NodeNG(object):
def child_sequence(self, child):
"""search for the right sequence where the child lies in"""
- for field in self._astng_fields:
+ for field in self._astroid_fields:
node_or_sequence = getattr(self, field)
if node_or_sequence is child:
return [node_or_sequence]
@@ -442,11 +442,11 @@ class NodeNG(object):
return node_or_sequence
else:
msg = 'Could not found %s in %s\'s children'
- raise ASTNGError(msg % (repr(child), repr(self)))
+ raise AstroidError(msg % (repr(child), repr(self)))
def locate_child(self, child):
"""return a 2-uple (child attribute name, sequence or node)"""
- for field in self._astng_fields:
+ for field in self._astroid_fields:
node_or_sequence = getattr(self, field)
# /!\ compiler.ast Nodes have an __iter__ walking over child nodes
if child is node_or_sequence:
@@ -454,7 +454,7 @@ class NodeNG(object):
if isinstance(node_or_sequence, (tuple, list)) and child in node_or_sequence:
return field, node_or_sequence
msg = 'Could not found %s in %s\'s children'
- raise ASTNGError(msg % (repr(child), repr(self)))
+ raise AstroidError(msg % (repr(child), repr(self)))
# FIXME : should we merge child_sequence and locate_child ? locate_child
# is only used in are_exclusive, child_sequence one time in pylint.
@@ -566,11 +566,11 @@ class NodeNG(object):
return False
def as_string(self):
- from logilab.astng.as_string import to_code
+ from astroid.as_string import to_code
return to_code(self)
def repr_tree(self, ids=False):
- from logilab.astng.as_string import dump
+ from astroid.as_string import dump
return dump(self)
diff --git a/brain/py2mechanize.py b/brain/py2mechanize.py
index 50f718e..1e0b102 100644
--- a/brain/py2mechanize.py
+++ b/brain/py2mechanize.py
@@ -1,8 +1,8 @@
-from logilab.astng import MANAGER
-from logilab.astng.builder import ASTNGBuilder
+from astroid import MANAGER
+from astroid.builder import AstroidBuilder
def mechanize_transform(module):
- fake = ASTNGBuilder(MANAGER).string_build('''
+ fake = AstroidBuilder(MANAGER).string_build('''
class Browser(object):
def open(self, url, data=None, timeout=None):
diff --git a/brain/py2qt4.py b/brain/py2qt4.py
index f3d8c3b..0ee0410 100644
--- a/brain/py2qt4.py
+++ b/brain/py2qt4.py
@@ -1,16 +1,16 @@
-"""ASTNG hooks for the Python 2 qt4 module.
+"""Astroid hooks for the Python 2 qt4 module.
Currently help understanding of :
* PyQT4.QtCore
"""
-from logilab.astng import MANAGER
-from logilab.astng.builder import ASTNGBuilder
+from astroid import MANAGER
+from astroid.builder import AstroidBuilder
def pyqt4_qtcore_transform(module):
- fake = ASTNGBuilder(MANAGER).string_build('''
+ fake = AstroidBuilder(MANAGER).string_build('''
def SIGNAL(signal_name): pass
diff --git a/brain/py2stdlib.py b/brain/py2stdlib.py
index 50ba557..25c7122 100644
--- a/brain/py2stdlib.py
+++ b/brain/py2stdlib.py
@@ -1,17 +1,17 @@
-"""ASTNG hooks for the Python 2 standard library.
+"""Astroid hooks for the Python 2 standard library.
Currently help understanding of :
* hashlib.md5 and hashlib.sha1
"""
-from logilab.astng import MANAGER
-from logilab.astng.builder import ASTNGBuilder
+from astroid import MANAGER
+from astroid.builder import AstroidBuilder
MODULE_TRANSFORMS = {}
def hashlib_transform(module):
- fake = ASTNGBuilder(MANAGER).string_build('''
+ fake = AstroidBuilder(MANAGER).string_build('''
class md5(object):
def __init__(self, value): pass
@@ -34,7 +34,7 @@ class sha1(object):
module.locals[hashfunc] = fake.locals[hashfunc]
def collections_transform(module):
- fake = ASTNGBuilder(MANAGER).string_build('''
+ fake = AstroidBuilder(MANAGER).string_build('''
class defaultdict(dict):
default_factory = None
@@ -61,7 +61,7 @@ class deque(object):
module.locals[klass] = fake.locals[klass]
def pkg_resources_transform(module):
- fake = ASTNGBuilder(MANAGER).string_build('''
+ fake = AstroidBuilder(MANAGER).string_build('''
def resource_exists(package_or_requirement, resource_name):
pass
@@ -103,7 +103,7 @@ def cleanup_resources(force=False):
def urlparse_transform(module):
- fake = ASTNGBuilder(MANAGER).string_build('''
+ fake = AstroidBuilder(MANAGER).string_build('''
def urlparse(url, scheme='', allow_fragments=True):
return ParseResult()
@@ -129,7 +129,7 @@ class ParseResult(object):
module.locals[func_name] = func
def subprocess_transform(module):
- fake = ASTNGBuilder(MANAGER).string_build('''
+ fake = AstroidBuilder(MANAGER).string_build('''
class Popen(object):
returncode = pid = 0
@@ -176,7 +176,7 @@ def transform(module):
else:
tr(module)
-from logilab.astng import MANAGER
+from astroid import MANAGER
MANAGER.register_transformer(transform)
diff --git a/builder.py b/builder.py
index 1c76434..566bdd5 100644
--- a/builder.py
+++ b/builder.py
@@ -1,21 +1,21 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""The ASTNGBuilder makes astng from living object and / or from _ast
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""The AstroidBuilder makes astroid from living object and / or from _ast
The builder is not thread safe and can't be used to parse different sources
at the same time.
@@ -28,11 +28,11 @@ from os.path import splitext, basename, exists, abspath
from logilab.common.modutils import modpath_from_file
-from logilab.astng.exceptions import ASTNGBuildingException, InferenceError
-from logilab.astng.raw_building import InspectBuilder
-from logilab.astng.rebuilder import TreeRebuilder
-from logilab.astng.manager import ASTNGManager
-from logilab.astng.bases import YES, Instance
+from astroid.exceptions import AstroidBuildingException, InferenceError
+from astroid.raw_building import InspectBuilder
+from astroid.rebuilder import TreeRebuilder
+from astroid.manager import AstroidManager
+from astroid.bases import YES, Instance
from _ast import PyCF_ONLY_AST
def parse(string):
@@ -50,7 +50,7 @@ if sys.version_info >= (3, 0):
except UnicodeError, uex: # wrong encodingg
# detect_encoding returns utf-8 if no encoding specified
msg = 'Wrong (%s) or no encoding specified' % encoding
- raise ASTNGBuildingException(msg)
+ raise AstroidBuildingException(msg)
return stream, encoding, data
else:
@@ -79,10 +79,10 @@ else:
# ast NG builder ##############################################################
-MANAGER = ASTNGManager()
+MANAGER = AstroidManager()
-class ASTNGBuilder(InspectBuilder):
- """provide astng building methods"""
+class AstroidBuilder(InspectBuilder):
+ """provide astroid building methods"""
rebuilder = TreeRebuilder()
def __init__(self, manager=None):
@@ -90,7 +90,7 @@ class ASTNGBuilder(InspectBuilder):
self._manager = manager or MANAGER
def module_build(self, module, modname=None):
- """build an astng from a living module instance
+ """build an astroid from a living module instance
"""
node = None
path = getattr(module, '__file__', None)
@@ -105,7 +105,7 @@ class ASTNGBuilder(InspectBuilder):
return node
def file_build(self, path, modname=None):
- """build astng from a source code file (i.e. from an ast)
+ """build astroid from a source code file (i.e. from an ast)
path is expected to be a python source file
"""
@@ -113,26 +113,26 @@ class ASTNGBuilder(InspectBuilder):
stream, encoding, data = open_source_file(path)
except IOError, exc:
msg = 'Unable to load file %r (%s)' % (path, exc)
- raise ASTNGBuildingException(msg)
+ raise AstroidBuildingException(msg)
except SyntaxError, exc: # py3k encoding specification error
- raise ASTNGBuildingException(exc)
+ raise AstroidBuildingException(exc)
except LookupError, exc: # unknown encoding
- raise ASTNGBuildingException(exc)
+ raise AstroidBuildingException(exc)
# get module name if necessary
if modname is None:
try:
modname = '.'.join(modpath_from_file(path))
except ImportError:
modname = splitext(basename(path))[0]
- # build astng representation
+ # build astroid representation
node = self.string_build(data, modname, path)
node.file_encoding = encoding
return node
def string_build(self, data, modname='', path=None):
- """build astng from source code string and return rebuilded astng"""
+ """build astroid from source code string and return rebuilded astroid"""
module = self._data_build(data, modname, path)
- self._manager.astng_cache[module.name] = module
+ self._manager.astroid_cache[module.name] = module
# post tree building steps after we stored the module in the cache:
for from_node in module._from_nodes:
self.add_from_names_to_locals(from_node)
@@ -176,7 +176,7 @@ class ASTNGBuilder(InspectBuilder):
if name == '*':
try:
imported = node.root().import_module(node.modname)
- except ASTNGBuildingException:
+ except AstroidBuildingException:
continue
for name in imported.wildcard_import_names():
node.parent.set_local(name, node)
diff --git a/debian.sid/control b/debian.sid/control
index c73a764..581455e 100644
--- a/debian.sid/control
+++ b/debian.sid/control
@@ -1,39 +1,42 @@
-Source: logilab-astng
+Source: astroid
Section: python
Priority: optional
Maintainer: Logilab S.A. <contact@logilab.fr>
Uploaders: Sylvain Thénault <sylvain.thenault@logilab.fr>,
Alexandre Fayolle <afayolle@debian.org>,
- Sandro Tosi <morph@debian.org>,
- Julien Jehannet <julien.jehannet@logilab.fr>
+ Sandro Tosi <morph@debian.org>
Build-Depends: debhelper (>= 7.0.50~), python-all, python3-all
Standards-Version: 3.9.2
-Homepage: http://www.logilab.org/project/logilab-astng
-Vcs-Hg: http://hg.logilab.org/logilab/astng
-Vcs-Browser: http://hg.logilab.org/logilab/astng
+Homepage: http://bitbucket/logilab/astroid
+Vcs-Hg: https://bitbucket.org/logilab/astroid
+Vcs-Browser: https://bitbucket.org/logilab/astroid/src
-Package: python-logilab-astng
+Package: python-astroid
Architecture: all
-Depends: ${python:Depends}, ${misc:Depends}, python-logilab-common
+Depends: ${python:Depends},
+ ${misc:Depends},
+ python-logilab-common,
Description: rebuild a new abstract syntax tree from Python's ast
The aim of this module is to provide a common base representation of
Python source code for projects such as pyreverse or pylint.
.
It rebuilds the tree generated by the _ast module by recursively walking down
- the AST and building an extended ast (let's call it astng ;). The new node
+ the AST and building an extended ast. The new node
classes have additional methods and attributes for different usages.
- Furthermore, astng builds partial trees by inspecting living objects.
+ Furthermore, astroid builds partial trees by inspecting living objects.
-Package: python3-logilab-astng
+Package: python3-astroid
Architecture: all
-Depends: ${python3:Depends}, ${misc:Depends}, python3-logilab-common
+Depends: ${python3:Depends},
+ ${misc:Depends},
+ python3-logilab-common,
Description: rebuild a new abstract syntax tree from Python's ast
The aim of this module is to provide a common base representation of
Python source code for projects such as pyreverse or pylint.
.
It rebuilds the tree generated by the _ast module by recursively walking down
- the AST and building an extended ast (let's call it astng ;). The new node
+ the AST and building an extended ast. The new node
classes have additional methods and attributes for different usages.
- Furthermore, astng builds partial trees by inspecting living objects.
+ Furthermore, astroid builds partial trees by inspecting living objects.
diff --git a/debian.sid/rules b/debian.sid/rules
index 1a9c55b..a29f82c 100755
--- a/debian.sid/rules
+++ b/debian.sid/rules
@@ -13,8 +13,8 @@
include /usr/share/python/python.mk
-PACKAGE:=$(call py_pkgname,python-logilab-astng,python)
-PACKAGE3:=$(call py_pkgname,python-logilab-astng,python3.)
+PACKAGE:=$(call py_pkgname,python-astroid,python)
+PACKAGE3:=$(call py_pkgname,python-astroid,python3.)
%:
dh $@ --with python2,python3
@@ -26,8 +26,7 @@ override_dh_install:
NO_SETUPTOOLS=1 python3 setup.py -q install --no-compile \
--root=$(CURDIR)/debian/$(PACKAGE3)/ \
${py_setup_install_args}
- rm -rf debian/*/usr/lib/python*/*-packages/logilab/astng/test
- rm -rf debian/*/usr/lib/python*/*-packages/logilab/__init__.py
+ rm -rf debian/*/usr/lib/python*/*-packages/astroid/test
override_dh_installdocs:
dh_installdocs -i README*
diff --git a/debian/control b/debian/control
index c33e3e9..267da11 100644
--- a/debian/control
+++ b/debian/control
@@ -1,27 +1,31 @@
-Source: logilab-astng
+Source: astroid
Section: python
Priority: optional
Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
-Uploaders: Sylvain Thénault <sylvain.thenault@logilab.fr>, Alexandre Fayolle <afayolle@debian.org>, Sandro Tosi <morph@debian.org>
+Uploaders: Sylvain Thénault <sylvain.thenault@logilab.fr>,
+ Alexandre Fayolle <afayolle@debian.org>,
+ Sandro Tosi <morph@debian.org>
Build-Depends: debhelper (>= 5.0.37.2), python (>= 2.5)
Build-Depends-Indep: python-support
XS-Python-Version: >= 2.5
Standards-Version: 3.8.2
-Homepage: http://www.logilab.org/project/logilab-astng
-Vcs-Svn: svn://svn.debian.org/svn/python-modules/packages/logilab-astng/trunk/
-Vcs-Browser: http://svn.debian.org/viewsvn/python-modules/packages/logilab-astng/trunk/
+Homepage: http://bitbucket/logilab/astroid
+Vcs-Hg: https://bitbucket.org/logilab/astroid
+Vcs-Browser: https://bitbucket.org/logilab/astroid/src
-Package: python-logilab-astng
+Package: python-astroid
Architecture: all
-Depends: ${python:Depends}, ${misc:Depends}, python-logilab-common (>= 0.53.0-1)
+Depends: ${python:Depends},
+ ${misc:Depends},
+ python-logilab-common (>= 0.53.0-1),
XB-Python-Version: ${python:Versions}
Description: rebuild a new abstract syntax tree from Python's ast
The aim of this module is to provide a common base representation of
Python source code for projects such as pyreverse or pylint.
.
It rebuilds the tree generated by the _ast module by recursively walking down the
- AST and building an extended ast (let's call it astng ;). The new node classes
+ AST and building an extended ast. The new node classes
have additional methods and attributes for different usages.
- Furthermore, astng builds partial trees by inspecting living objects.
+ Furthermore, astroid builds partial trees by inspecting living objects.
diff --git a/debian/copyright b/debian/copyright
index ccc8860..fa24ec9 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,6 +1,6 @@
This package was debianized by Sylvain Thenault <sylvain.thenault@logilab.fr> Sat, 13 Apr 2002 19:05:23 +0200.
-It was downloaded from ftp://ftp.logilab.org/pub/astng
+It was downloaded from http://bitbucket.org/logilab/astroid
Upstream Author:
@@ -9,9 +9,9 @@ Upstream Author:
Copyright:
- Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE).
+ Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE).
http://www.logilab.fr/ -- mailto:contact@logilab.fr
- Copyright (C) 2003-2010 Sylvain Thenault
+ Copyright (C) 2003-2013 Sylvain Thenault
License:
diff --git a/debian/python-astroid.dirs b/debian/python-astroid.dirs
new file mode 100644
index 0000000..64b5569
--- /dev/null
+++ b/debian/python-astroid.dirs
@@ -0,0 +1 @@
+usr/share/doc/python-astroid/test
diff --git a/debian/python-logilab-astng.dirs b/debian/python-logilab-astng.dirs
deleted file mode 100644
index f3feac6..0000000
--- a/debian/python-logilab-astng.dirs
+++ /dev/null
@@ -1 +0,0 @@
-usr/share/doc/python-logilab-astng/test
diff --git a/debian/rules b/debian/rules
index 9734c9b..5dca929 100755
--- a/debian/rules
+++ b/debian/rules
@@ -12,21 +12,21 @@
#export DH_VERBOSE=1
build: build-stamp
-build-stamp:
+build-stamp:
dh_testdir
-
+
NO_SETUPTOOLS=1 python setup.py -q build
touch build-stamp
-clean:
+clean:
dh_testdir
dh_testroot
NO_SETUPTOOLS=1 python setup.py clean
- find . -name "*.pyc" -delete
-
+ find . -name "*.pyc" -delete
+
rm -rf build
dh_clean build-stamp
@@ -37,30 +37,30 @@ install: build
dh_installdirs
NO_SETUPTOOLS=1 python setup.py -q install --no-compile \
- --root=$(CURDIR)/debian/python-logilab-astng/ \
+ --root=$(CURDIR)/debian/python-astroid/ \
--install-layout=deb
# remove sub-package __init__ file (created in postinst)
- rm debian/python-logilab-astng/usr/lib/python*/*-packages/logilab/__init__.py
+ rm debian/python-astroid/usr/lib/python*/*-packages/logilab/__init__.py
# remove test directory (installed in a separated package)
- rm -rf debian/python-logilab-astng/usr/lib/python*/*-packages/logilab/astng/test
+ rm -rf debian/python-astroid/usr/lib/python*/*-packages/logilab/astroid/test
# install tests
- (cd test && find . -type f -not \( -path '*/CVS/*' -or -name '*.pyc' \) -exec install -D --mode=644 {} ../debian/python-logilab-astng/usr/share/doc/python-logilab-astng/test/{} \;)
+ (cd test && find . -type f -not \( -path '*/CVS/*' -or -name '*.pyc' \) -exec install -D --mode=644 {} ../debian/python-astroid/usr/share/doc/python-astroid/test/{} \;)
# Build architecture-independent files here.
binary-indep: build install
- dh_testdir
- dh_testroot
+ dh_testdir
+ dh_testroot
dh_install -i
- dh_pysupport -i
+ dh_pysupport -i
dh_installchangelogs -i ChangeLog
dh_installexamples -i
dh_installdocs -i README
dh_compress -i -X.py -X.ini -X.xml -Xtest
dh_fixperms -i
dh_installdeb -i
- dh_gencontrol -i
+ dh_gencontrol -i
dh_md5sums -i
dh_builddeb -i
diff --git a/debian/watch b/debian/watch
index 2476862..85bc900 100644
--- a/debian/watch
+++ b/debian/watch
@@ -1,2 +1,2 @@
version=3
-opts=pasv ftp://ftp.logilab.org/pub/astng/logilab-astng-(.*)\.tar\.gz
+https://bitbucket.org/logilab/astroid/downloads /logilab/astroid/get/astroid-version-(.*).tar.gz
diff --git a/exceptions.py b/exceptions.py
index db33f8b..07fb945 100644
--- a/exceptions.py
+++ b/exceptions.py
@@ -1,34 +1,34 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""this module contains exceptions used in the astng library
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""this module contains exceptions used in the astroid library
"""
__doctype__ = "restructuredtext en"
-class ASTNGError(Exception):
- """base exception class for all astng related exceptions"""
+class AstroidError(Exception):
+ """base exception class for all astroid related exceptions"""
-class ASTNGBuildingException(ASTNGError):
- """exception class when we are unable to build an astng representation"""
+class AstroidBuildingException(AstroidError):
+ """exception class when we are unable to build an astroid representation"""
-class ResolveError(ASTNGError):
- """base class of astng resolution/inference error"""
+class ResolveError(AstroidError):
+ """base class of astroid resolution/inference error"""
class NotFoundError(ResolveError):
"""raised when we are unable to resolve a name"""
@@ -39,7 +39,7 @@ class InferenceError(ResolveError):
class UnresolvableName(InferenceError):
"""raised when we are unable to resolve a name"""
-class NoDefault(ASTNGError):
+class NoDefault(AstroidError):
"""raised by function's `default_value` method when an argument has
no default value
"""
diff --git a/inference.py b/inference.py
index 3b15834..055b98d 100644
--- a/inference.py
+++ b/inference.py
@@ -1,37 +1,37 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""this module contains a set of functions to handle inference on astng trees
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""this module contains a set of functions to handle inference on astroid trees
"""
__doctype__ = "restructuredtext en"
from itertools import chain
-from logilab.astng import nodes
+from astroid import nodes
-from logilab.astng.manager import ASTNGManager
-from logilab.astng.exceptions import (ASTNGError,
+from astroid.manager import AstroidManager
+from astroid.exceptions import (AstroidError,
InferenceError, NoDefault, NotFoundError, UnresolvableName)
-from logilab.astng.bases import YES, Instance, InferenceContext, \
+from astroid.bases import YES, Instance, InferenceContext, \
_infer_stmts, copy_context, path_wrapper, raise_if_nothing_infered
-from logilab.astng.protocols import _arguments_infer_argname
+from astroid.protocols import _arguments_infer_argname
-MANAGER = ASTNGManager()
+MANAGER = AstroidManager()
class CallContext:
@@ -55,7 +55,7 @@ class CallContext:
try:
return self.nargs[name].infer(context)
except KeyError:
- # Function.args.args can be None in astng (means that we don't have
+ # Function.args.args can be None in astroid (means that we don't have
# information on argnames)
argindex = funcnode.args.find_argname(name)[0]
if argindex is not None:
@@ -375,10 +375,10 @@ def infer_empty_node(self, context=None):
yield YES
else:
try:
- for infered in MANAGER.infer_astng_from_something(self.object,
+ for infered in MANAGER.infer_astroid_from_something(self.object,
context=context):
yield infered
- except ASTNGError:
+ except AstroidError:
yield YES
nodes.EmptyNode.infer = path_wrapper(infer_empty_node)
diff --git a/inspector.py b/inspector.py
index a78634a..db93a60 100644
--- a/inspector.py
+++ b/inspector.py
@@ -1,21 +1,21 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""visitor doing some postprocessing on the astng tree.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""visitor doing some postprocessing on the astroid tree.
Try to resolve definitions (namespace) dictionary, relationship...
This module has been imported from pyreverse
@@ -28,9 +28,9 @@ from os.path import dirname
from logilab.common.modutils import get_module_part, is_relative, \
is_standard_module
-from logilab import astng
-from logilab.astng.exceptions import InferenceError
-from logilab.astng.utils import LocalsVisitor
+import astroid
+from astroid.exceptions import InferenceError
+from astroid.utils import LocalsVisitor
class IdGeneratorMixIn:
"""
@@ -58,20 +58,20 @@ class Linker(IdGeneratorMixIn, LocalsVisitor):
According to options the following attributes may be added to visited nodes:
* uid,
- a unique identifier for the node (on astng.Project, astng.Module,
- astng.Class and astng.locals_type). Only if the linker has been instantiated
+ a unique identifier for the node (on astroid.Project, astroid.Module,
+ astroid.Class and astroid.locals_type). Only if the linker has been instantiated
with tag=True parameter (False by default).
* Function
a mapping from locals names to their bounded value, which may be a
- constant like a string or an integer, or an astng node (on astng.Module,
- astng.Class and astng.Function).
+ constant like a string or an integer, or an astroid node (on astroid.Module,
+ astroid.Class and astroid.Function).
* instance_attrs_type
- as locals_type but for klass member attributes (only on astng.Class)
+ as locals_type but for klass member attributes (only on astroid.Class)
* implements,
- list of implemented interface _objects_ (only on astng.Class nodes)
+ list of implemented interface _objects_ (only on astroid.Class nodes)
"""
def __init__(self, project, inherited_interfaces=0, tag=False):
@@ -86,7 +86,7 @@ class Linker(IdGeneratorMixIn, LocalsVisitor):
def visit_project(self, node):
- """visit an astng.Project node
+ """visit an astroid.Project node
* optionally tag the node with a unique id
"""
@@ -96,7 +96,7 @@ class Linker(IdGeneratorMixIn, LocalsVisitor):
self.visit(module)
def visit_package(self, node):
- """visit an astng.Package node
+ """visit an astroid.Package node
* optionally tag the node with a unique id
"""
@@ -106,7 +106,7 @@ class Linker(IdGeneratorMixIn, LocalsVisitor):
self.visit(subelmt)
def visit_module(self, node):
- """visit an astng.Module node
+ """visit an astroid.Module node
* set the locals_type mapping
* set the depends mapping
@@ -120,7 +120,7 @@ class Linker(IdGeneratorMixIn, LocalsVisitor):
node.uid = self.generate_id()
def visit_class(self, node):
- """visit an astng.Class node
+ """visit an astroid.Class node
* set the locals_type and instance_attrs_type mappings
* set the implements list and build it
@@ -148,7 +148,7 @@ class Linker(IdGeneratorMixIn, LocalsVisitor):
node.implements = ()
def visit_function(self, node):
- """visit an astng.Function node
+ """visit an astroid.Function node
* set the locals_type mapping
* optionally tag the node with a unique id
@@ -165,7 +165,7 @@ class Linker(IdGeneratorMixIn, LocalsVisitor):
link_function = visit_function
def visit_assname(self, node):
- """visit an astng.AssName node
+ """visit an astroid.AssName node
handle locals_type
"""
@@ -190,11 +190,11 @@ class Linker(IdGeneratorMixIn, LocalsVisitor):
already_infered.append(valnode)
except KeyError:
frame.locals_type[node.name] = values
- except astng.InferenceError:
+ except astroid.InferenceError:
pass
def handle_assattr_type(self, node, parent):
- """handle an astng.AssAttr node
+ """handle an astroid.AssAttr node
handle instance_attrs_type
"""
@@ -207,11 +207,11 @@ class Linker(IdGeneratorMixIn, LocalsVisitor):
already_infered.append(valnode)
except KeyError:
parent.instance_attrs_type[node.attrname] = values
- except astng.InferenceError:
+ except astroid.InferenceError:
pass
def visit_import(self, node):
- """visit an astng.Import node
+ """visit an astroid.Import node
resolve module dependencies
"""
@@ -222,7 +222,7 @@ class Linker(IdGeneratorMixIn, LocalsVisitor):
def visit_from(self, node):
- """visit an astng.From node
+ """visit an astroid.From node
resolve module dependencies
"""
diff --git a/manager.py b/manager.py
index 2ca24f6..18b48d8 100644
--- a/manager.py
+++ b/manager.py
@@ -1,22 +1,22 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""astng manager: avoid multiple astng build of a same module when
-possible by providing a class responsible to get astng representation
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""astroid manager: avoid multiple astroid build of a same module when
+possible by providing a class responsible to get astroid representation
from various source and using a cache of built modules)
"""
@@ -30,14 +30,14 @@ from logilab.common.modutils import NoSourceFile, is_python_source, \
get_module_files, get_source_file, zipimport
from logilab.common.configuration import OptionsProviderMixIn
-from logilab.astng.exceptions import ASTNGBuildingException
+from astroid.exceptions import AstroidBuildingException
-def astng_wrapper(func, modname):
- """wrapper to give to ASTNGManager.project_from_files"""
+def astroid_wrapper(func, modname):
+ """wrapper to give to AstroidManager.project_from_files"""
print 'parsing %s...' % modname
try:
return func(modname)
- except ASTNGBuildingException, exc:
+ except AstroidBuildingException, exc:
print exc
except Exception, exc:
import traceback
@@ -55,14 +55,14 @@ def safe_repr(obj):
-class ASTNGManager(OptionsProviderMixIn):
- """the astng manager, responsible to build astng from files
+class AstroidManager(OptionsProviderMixIn):
+ """the astroid manager, responsible to build astroid from files
or modules.
Use the Borg pattern.
"""
- name = 'astng loader'
+ name = 'astroid loader'
options = (("ignore",
{'type' : "csv", 'metavar' : "<file>",
'dest' : "black_list", "default" : ('CVS',),
@@ -76,17 +76,17 @@ class ASTNGManager(OptionsProviderMixIn):
)
brain = {}
def __init__(self):
- self.__dict__ = ASTNGManager.brain
+ self.__dict__ = AstroidManager.brain
if not self.__dict__:
OptionsProviderMixIn.__init__(self)
self.load_defaults()
# NOTE: cache entries are added by the [re]builder
- self.astng_cache = {}
+ self.astroid_cache = {}
self._mod_file_cache = {}
self.transformers = []
- def astng_from_file(self, filepath, modname=None, fallback=True, source=False):
- """given a module name, return the astng object"""
+ def astroid_from_file(self, filepath, modname=None, fallback=True, source=False):
+ """given a module name, return the astroid object"""
try:
filepath = get_source_file(filepath, include_no_ext=True)
source = True
@@ -97,23 +97,23 @@ class ASTNGManager(OptionsProviderMixIn):
modname = '.'.join(modpath_from_file(filepath))
except ImportError:
modname = filepath
- if modname in self.astng_cache:
- return self.astng_cache[modname]
+ if modname in self.astroid_cache:
+ return self.astroid_cache[modname]
if source:
- from logilab.astng.builder import ASTNGBuilder
- return ASTNGBuilder(self).file_build(filepath, modname)
+ from astroid.builder import AstroidBuilder
+ return AstroidBuilder(self).file_build(filepath, modname)
elif fallback and modname:
- return self.astng_from_module_name(modname)
- raise ASTNGBuildingException('unable to get astng for file %s' %
+ return self.astroid_from_module_name(modname)
+ raise AstroidBuildingException('unable to get astroid for file %s' %
filepath)
- def astng_from_module_name(self, modname, context_file=None):
- """given a module name, return the astng object"""
- if modname in self.astng_cache:
- return self.astng_cache[modname]
+ def astroid_from_module_name(self, modname, context_file=None):
+ """given a module name, return the astroid object"""
+ if modname in self.astroid_cache:
+ return self.astroid_cache[modname]
if modname == '__main__':
- from logilab.astng.builder import ASTNGBuilder
- return ASTNGBuilder(self).string_build('', modname)
+ from astroid.builder import AstroidBuilder
+ return AstroidBuilder(self).string_build('', modname)
old_cwd = os.getcwd()
if context_file:
os.chdir(dirname(context_file))
@@ -128,17 +128,17 @@ class ASTNGManager(OptionsProviderMixIn):
module = load_module_from_name(modname)
except Exception, ex:
msg = 'Unable to load module %s (%s)' % (modname, ex)
- raise ASTNGBuildingException(msg)
- return self.astng_from_module(module, modname)
- return self.astng_from_file(filepath, modname, fallback=False)
+ raise AstroidBuildingException(msg)
+ return self.astroid_from_module(module, modname)
+ return self.astroid_from_file(filepath, modname, fallback=False)
finally:
os.chdir(old_cwd)
def zip_import_data(self, filepath):
if zipimport is None:
return None
- from logilab.astng.builder import ASTNGBuilder
- builder = ASTNGBuilder(self)
+ from astroid.builder import AstroidBuilder
+ builder = AstroidBuilder(self)
for ext in ('.zip', '.egg'):
try:
eggpath, resource = filepath.rsplit(ext + '/', 1)
@@ -165,41 +165,41 @@ class ASTNGManager(OptionsProviderMixIn):
context_file=contextfile)
except ImportError, ex:
msg = 'Unable to load module %s (%s)' % (modname, ex)
- value = ASTNGBuildingException(msg)
+ value = AstroidBuildingException(msg)
self._mod_file_cache[(modname, contextfile)] = value
- if isinstance(value, ASTNGBuildingException):
+ if isinstance(value, AstroidBuildingException):
raise value
return value
- def astng_from_module(self, module, modname=None):
- """given an imported module, return the astng object"""
+ def astroid_from_module(self, module, modname=None):
+ """given an imported module, return the astroid object"""
modname = modname or module.__name__
- if modname in self.astng_cache:
- return self.astng_cache[modname]
+ if modname in self.astroid_cache:
+ return self.astroid_cache[modname]
try:
# some builtin modules don't have __file__ attribute
filepath = module.__file__
if is_python_source(filepath):
- return self.astng_from_file(filepath, modname)
+ return self.astroid_from_file(filepath, modname)
except AttributeError:
pass
- from logilab.astng.builder import ASTNGBuilder
- return ASTNGBuilder(self).module_build(module, modname)
+ from astroid.builder import AstroidBuilder
+ return AstroidBuilder(self).module_build(module, modname)
- def astng_from_class(self, klass, modname=None):
- """get astng for the given class"""
+ def astroid_from_class(self, klass, modname=None):
+ """get astroid for the given class"""
if modname is None:
try:
modname = klass.__module__
except AttributeError:
- raise ASTNGBuildingException(
+ raise AstroidBuildingException(
'Unable to get module for class %s' % safe_repr(klass))
- modastng = self.astng_from_module_name(modname)
- return modastng.getattr(klass.__name__)[0] # XXX
+ modastroid = self.astroid_from_module_name(modname)
+ return modastroid.getattr(klass.__name__)[0] # XXX
- def infer_astng_from_something(self, obj, context=None):
- """infer astng for the given class"""
+ def infer_astroid_from_something(self, obj, context=None):
+ """infer astroid for the given class"""
if hasattr(obj, '__class__') and not isinstance(obj, type):
klass = obj.__class__
else:
@@ -207,31 +207,31 @@ class ASTNGManager(OptionsProviderMixIn):
try:
modname = klass.__module__
except AttributeError:
- raise ASTNGBuildingException(
+ raise AstroidBuildingException(
'Unable to get module for %s' % safe_repr(klass))
except Exception, ex:
- raise ASTNGBuildingException(
+ raise AstroidBuildingException(
'Unexpected error while retrieving module for %s: %s'
% (safe_repr(klass), ex))
try:
name = klass.__name__
except AttributeError:
- raise ASTNGBuildingException(
+ raise AstroidBuildingException(
'Unable to get name for %s' % safe_repr(klass))
except Exception, ex:
- raise ASTNGBuildingException(
+ raise AstroidBuildingException(
'Unexpected error while retrieving name for %s: %s'
% (safe_repr(klass), ex))
# take care, on living object __module__ is regularly wrong :(
- modastng = self.astng_from_module_name(modname)
+ modastroid = self.astroid_from_module_name(modname)
if klass is obj:
- for infered in modastng.igetattr(name, context):
+ for infered in modastroid.igetattr(name, context):
yield infered
else:
- for infered in modastng.igetattr(name, context):
+ for infered in modastroid.igetattr(name, context):
yield infered.instanciate_class()
- def project_from_files(self, files, func_wrapper=astng_wrapper,
+ def project_from_files(self, files, func_wrapper=astroid_wrapper,
project_name=None, black_list=None):
"""return a Project from a list of files or modules"""
# build the project representation
@@ -245,22 +245,22 @@ class ASTNGManager(OptionsProviderMixIn):
fpath = join(something, '__init__.py')
else:
fpath = something
- astng = func_wrapper(self.astng_from_file, fpath)
- if astng is None:
+ astroid = func_wrapper(self.astroid_from_file, fpath)
+ if astroid is None:
continue
# XXX why is first file defining the project.path ?
- project.path = project.path or astng.file
- project.add_module(astng)
- base_name = astng.name
+ project.path = project.path or astroid.file
+ project.add_module(astroid)
+ base_name = astroid.name
# recurse in package except if __init__ was explicitly given
- if astng.package and something.find('__init__') == -1:
+ if astroid.package and something.find('__init__') == -1:
# recurse on others packages / modules if this is a package
- for fpath in get_module_files(dirname(astng.file),
+ for fpath in get_module_files(dirname(astroid.file),
black_list):
- astng = func_wrapper(self.astng_from_file, fpath)
- if astng is None or astng.name == base_name:
+ astroid = func_wrapper(self.astroid_from_file, fpath)
+ if astroid is None or astroid.name == base_name:
continue
- project.add_module(astng)
+ project.add_module(astroid)
return project
def register_transformer(self, transformer):
diff --git a/mixins.py b/mixins.py
index 97cc606..5e7b787 100644
--- a/mixins.py
+++ b/mixins.py
@@ -1,24 +1,24 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
"""This module contains some mixins for the different nodes.
"""
-from logilab.astng.exceptions import (ASTNGBuildingException, InferenceError,
+from astroid.exceptions import (AstroidBuildingException, InferenceError,
NotFoundError)
@@ -101,7 +101,7 @@ class FromImportMixIn(FilterStmtsMixin):
return mymodule
try:
return mymodule.import_module(modname, level=level)
- except ASTNGBuildingException:
+ except AstroidBuildingException:
raise InferenceError(modname)
except SyntaxError, ex:
raise InferenceError(str(ex))
diff --git a/node_classes.py b/node_classes.py
index 4d9cb18..23bf15f 100644
--- a/node_classes.py
+++ b/node_classes.py
@@ -1,29 +1,29 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
"""Module for some node classes. More nodes in scoped_nodes.py
"""
import sys
-from logilab.astng.exceptions import NoDefault
-from logilab.astng.bases import (NodeNG, Statement, Instance, InferenceContext,
+from astroid.exceptions import NoDefault
+from astroid.bases import (NodeNG, Statement, Instance, InferenceContext,
_infer_stmts, YES, BUILTINS)
-from logilab.astng.mixins import BlockRangeMixIn, AssignTypeMixin, \
+from astroid.mixins import BlockRangeMixIn, AssignTypeMixin, \
ParentAssignTypeMixin, FromImportMixIn
@@ -253,7 +253,7 @@ class Name(LookupMixIn, NodeNG):
class Arguments(NodeNG, AssignTypeMixin):
"""class representing an Arguments node"""
- _astng_fields = ('args', 'defaults')
+ _astroid_fields = ('args', 'defaults')
args = None
defaults = None
@@ -332,41 +332,41 @@ def _format_args(args, defaults=None):
class AssAttr(NodeNG, ParentAssignTypeMixin):
"""class representing an AssAttr node"""
- _astng_fields = ('expr',)
+ _astroid_fields = ('expr',)
expr = None
class Assert(Statement):
"""class representing an Assert node"""
- _astng_fields = ('test', 'fail',)
+ _astroid_fields = ('test', 'fail',)
test = None
fail = None
class Assign(Statement, AssignTypeMixin):
"""class representing an Assign node"""
- _astng_fields = ('targets', 'value',)
+ _astroid_fields = ('targets', 'value',)
targets = None
value = None
class AugAssign(Statement, AssignTypeMixin):
"""class representing an AugAssign node"""
- _astng_fields = ('target', 'value',)
+ _astroid_fields = ('target', 'value',)
target = None
value = None
class Backquote(NodeNG):
"""class representing a Backquote node"""
- _astng_fields = ('value',)
+ _astroid_fields = ('value',)
value = None
class BinOp(NodeNG):
"""class representing a BinOp node"""
- _astng_fields = ('left', 'right',)
+ _astroid_fields = ('left', 'right',)
left = None
right = None
class BoolOp(NodeNG):
"""class representing a BoolOp node"""
- _astng_fields = ('values',)
+ _astroid_fields = ('values',)
values = None
class Break(Statement):
@@ -375,7 +375,7 @@ class Break(Statement):
class CallFunc(NodeNG):
"""class representing a CallFunc node"""
- _astng_fields = ('func', 'args', 'starargs', 'kwargs')
+ _astroid_fields = ('func', 'args', 'starargs', 'kwargs')
func = None
args = None
starargs = None
@@ -387,7 +387,7 @@ class CallFunc(NodeNG):
class Compare(NodeNG):
"""class representing a Compare node"""
- _astng_fields = ('left', 'ops',)
+ _astroid_fields = ('left', 'ops',)
left = None
ops = None
@@ -405,7 +405,7 @@ class Compare(NodeNG):
class Comprehension(NodeNG):
"""class representing a Comprehension node"""
- _astng_fields = ('target', 'iter' ,'ifs')
+ _astroid_fields = ('target', 'iter' ,'ifs')
target = None
iter = None
ifs = None
@@ -458,7 +458,7 @@ class Continue(Statement):
class Decorators(NodeNG):
"""class representing a Decorators node"""
- _astng_fields = ('nodes',)
+ _astroid_fields = ('nodes',)
nodes = None
def __init__(self, nodes=None):
@@ -470,19 +470,19 @@ class Decorators(NodeNG):
class DelAttr(NodeNG, ParentAssignTypeMixin):
"""class representing a DelAttr node"""
- _astng_fields = ('expr',)
+ _astroid_fields = ('expr',)
expr = None
class Delete(Statement, AssignTypeMixin):
"""class representing a Delete node"""
- _astng_fields = ('targets',)
+ _astroid_fields = ('targets',)
targets = None
class Dict(NodeNG, Instance):
"""class representing a Dict node"""
- _astng_fields = ('items',)
+ _astroid_fields = ('items',)
def __init__(self, items=None):
if items is None:
@@ -524,7 +524,7 @@ class Dict(NodeNG, Instance):
class Discard(Statement):
"""class representing a Discard node"""
- _astng_fields = ('value',)
+ _astroid_fields = ('value',)
value = None
@@ -538,7 +538,7 @@ class EmptyNode(NodeNG):
class ExceptHandler(Statement, AssignTypeMixin):
"""class representing an ExceptHandler node"""
- _astng_fields = ('type', 'name', 'body',)
+ _astroid_fields = ('type', 'name', 'body',)
type = None
name = None
body = None
@@ -566,7 +566,7 @@ class ExceptHandler(Statement, AssignTypeMixin):
class Exec(Statement):
"""class representing an Exec node"""
- _astng_fields = ('expr', 'globals', 'locals',)
+ _astroid_fields = ('expr', 'globals', 'locals',)
expr = None
globals = None
locals = None
@@ -574,12 +574,12 @@ class Exec(Statement):
class ExtSlice(NodeNG):
"""class representing an ExtSlice node"""
- _astng_fields = ('dims',)
+ _astroid_fields = ('dims',)
dims = None
class For(BlockRangeMixIn, AssignTypeMixin, Statement):
"""class representing a For node"""
- _astng_fields = ('target', 'iter', 'body', 'orelse',)
+ _astroid_fields = ('target', 'iter', 'body', 'orelse',)
target = None
iter = None
body = None
@@ -600,7 +600,7 @@ class From(FromImportMixIn, Statement):
class Getattr(NodeNG):
"""class representing a Getattr node"""
- _astng_fields = ('expr',)
+ _astroid_fields = ('expr',)
expr = None
@@ -616,7 +616,7 @@ class Global(Statement):
class If(BlockRangeMixIn, Statement):
"""class representing an If node"""
- _astng_fields = ('test', 'body', 'orelse')
+ _astroid_fields = ('test', 'body', 'orelse')
test = None
body = None
orelse = None
@@ -636,7 +636,7 @@ class If(BlockRangeMixIn, Statement):
class IfExp(NodeNG):
"""class representing an IfExp node"""
- _astng_fields = ('test', 'body', 'orelse')
+ _astroid_fields = ('test', 'body', 'orelse')
test = None
body = None
orelse = None
@@ -648,19 +648,19 @@ class Import(FromImportMixIn, Statement):
class Index(NodeNG):
"""class representing an Index node"""
- _astng_fields = ('value',)
+ _astroid_fields = ('value',)
value = None
class Keyword(NodeNG):
"""class representing a Keyword node"""
- _astng_fields = ('value',)
+ _astroid_fields = ('value',)
value = None
class List(NodeNG, Instance, ParentAssignTypeMixin):
"""class representing a List node"""
- _astng_fields = ('elts',)
+ _astroid_fields = ('elts',)
def __init__(self, elts=None):
if elts is None:
@@ -694,7 +694,7 @@ class Pass(Statement):
class Print(Statement):
"""class representing a Print node"""
- _astng_fields = ('dest', 'values',)
+ _astroid_fields = ('dest', 'values',)
dest = None
values = None
@@ -703,11 +703,11 @@ class Raise(Statement):
"""class representing a Raise node"""
exc = None
if sys.version_info < (3, 0):
- _astng_fields = ('exc', 'inst', 'tback')
+ _astroid_fields = ('exc', 'inst', 'tback')
inst = None
tback = None
else:
- _astng_fields = ('exc', 'cause')
+ _astroid_fields = ('exc', 'cause')
exc = None
cause = None
@@ -721,13 +721,13 @@ class Raise(Statement):
class Return(Statement):
"""class representing a Return node"""
- _astng_fields = ('value',)
+ _astroid_fields = ('value',)
value = None
class Set(NodeNG, Instance, ParentAssignTypeMixin):
"""class representing a Set node"""
- _astng_fields = ('elts',)
+ _astroid_fields = ('elts',)
def __init__(self, elts=None):
if elts is None:
@@ -744,27 +744,27 @@ class Set(NodeNG, Instance, ParentAssignTypeMixin):
class Slice(NodeNG):
"""class representing a Slice node"""
- _astng_fields = ('lower', 'upper', 'step')
+ _astroid_fields = ('lower', 'upper', 'step')
lower = None
upper = None
step = None
class Starred(NodeNG, ParentAssignTypeMixin):
"""class representing a Starred node"""
- _astng_fields = ('value',)
+ _astroid_fields = ('value',)
value = None
class Subscript(NodeNG):
"""class representing a Subscript node"""
- _astng_fields = ('value', 'slice')
+ _astroid_fields = ('value', 'slice')
value = None
slice = None
class TryExcept(BlockRangeMixIn, Statement):
"""class representing a TryExcept node"""
- _astng_fields = ('body', 'handlers', 'orelse',)
+ _astroid_fields = ('body', 'handlers', 'orelse',)
body = None
handlers = None
orelse = None
@@ -790,7 +790,7 @@ class TryExcept(BlockRangeMixIn, Statement):
class TryFinally(BlockRangeMixIn, Statement):
"""class representing a TryFinally node"""
- _astng_fields = ('body', 'finalbody',)
+ _astroid_fields = ('body', 'finalbody',)
body = None
finalbody = None
@@ -809,7 +809,7 @@ class TryFinally(BlockRangeMixIn, Statement):
class Tuple(NodeNG, Instance, ParentAssignTypeMixin):
"""class representing a Tuple node"""
- _astng_fields = ('elts',)
+ _astroid_fields = ('elts',)
def __init__(self, elts=None):
if elts is None:
@@ -829,13 +829,13 @@ class Tuple(NodeNG, Instance, ParentAssignTypeMixin):
class UnaryOp(NodeNG):
"""class representing an UnaryOp node"""
- _astng_fields = ('operand',)
+ _astroid_fields = ('operand',)
operand = None
class While(BlockRangeMixIn, Statement):
"""class representing a While node"""
- _astng_fields = ('test', 'body', 'orelse',)
+ _astroid_fields = ('test', 'body', 'orelse',)
test = None
body = None
orelse = None
@@ -850,7 +850,7 @@ class While(BlockRangeMixIn, Statement):
class With(BlockRangeMixIn, AssignTypeMixin, Statement):
"""class representing a With node"""
- _astng_fields = ('expr', 'vars', 'body')
+ _astroid_fields = ('expr', 'vars', 'body')
expr = None
vars = None
body = None
@@ -864,7 +864,7 @@ class With(BlockRangeMixIn, AssignTypeMixin, Statement):
class Yield(NodeNG):
"""class representing a Yield node"""
- _astng_fields = ('value',)
+ _astroid_fields = ('value',)
value = None
# constants ##############################################################
@@ -889,7 +889,7 @@ def _update_const_classes():
_update_const_classes()
def const_factory(value):
- """return an astng node for a python value"""
+ """return an astroid node for a python value"""
# XXX we should probably be stricter here and only consider stuff in
# CONST_CLS or do better treatment: in case where value is not in CONST_CLS,
# we should rather recall the builder on this value than returning an empty
diff --git a/nodes.py b/nodes.py
index 2e9bf1b..9fdc67e 100644
--- a/nodes.py
+++ b/nodes.py
@@ -1,20 +1,20 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
"""
on all nodes :
.is_statement, returning true if the node should be considered as a
@@ -26,7 +26,7 @@ on all nodes :
.frame(), returning the first node defining a new local scope (i.e.
Module, Function or Class)
.set_local(name, node), define an identifier <name> on the first parent frame,
- with the node defining it. This is used by the astng builder and should not
+ with the node defining it. This is used by the astroid builder and should not
be used from out there.
on From and Import :
@@ -37,7 +37,7 @@ on From and Import :
__docformat__ = "restructuredtext en"
-from logilab.astng.node_classes import Arguments, AssAttr, Assert, Assign, \
+from astroid.node_classes import Arguments, AssAttr, Assert, Assign, \
AssName, AugAssign, Backquote, BinOp, BoolOp, Break, CallFunc, Compare, \
Comprehension, Const, Continue, Decorators, DelAttr, DelName, Delete, \
Dict, Discard, Ellipsis, EmptyNode, ExceptHandler, Exec, ExtSlice, For, \
@@ -45,7 +45,7 @@ from logilab.astng.node_classes import Arguments, AssAttr, Assert, Assign, \
List, Name, Nonlocal, Pass, Print, Raise, Return, Set, Slice, Starred, Subscript, \
TryExcept, TryFinally, Tuple, UnaryOp, While, With, Yield, \
const_factory
-from logilab.astng.scoped_nodes import Module, GenExpr, Lambda, DictComp, \
+from astroid.scoped_nodes import Module, GenExpr, Lambda, DictComp, \
ListComp, SetComp, Function, Class
ALL_NODE_CLASSES = (
diff --git a/protocols.py b/protocols.py
index 4498460..1f4f15a 100644
--- a/protocols.py
+++ b/protocols.py
@@ -1,32 +1,32 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
"""this module contains a set of functions to handle python protocols for nodes
where it makes sense.
"""
__doctype__ = "restructuredtext en"
-from logilab.astng.exceptions import InferenceError, NoDefault
-from logilab.astng.node_classes import unpack_infer
-from logilab.astng.bases import copy_context, \
+from astroid.exceptions import InferenceError, NoDefault
+from astroid.node_classes import unpack_infer
+from astroid.bases import copy_context, \
raise_if_nothing_infered, yes_if_nothing_infered, Instance, YES
-from logilab.astng.nodes import const_factory
-from logilab.astng import nodes
+from astroid.nodes import const_factory
+from astroid import nodes
# unary operations ############################################################
diff --git a/raw_building.py b/raw_building.py
index 5a9340b..756bec1 100644
--- a/raw_building.py
+++ b/raw_building.py
@@ -1,21 +1,21 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""this module contains a set of functions to create astng trees from scratch
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""this module contains a set of functions to create astroid trees from scratch
(build_* functions) or from living object (object_build_* functions)
"""
@@ -26,12 +26,12 @@ from os.path import abspath
from inspect import (getargspec, isdatadescriptor, isfunction, ismethod,
ismethoddescriptor, isclass, isbuiltin)
-from logilab.astng.node_classes import CONST_CLS
-from logilab.astng.nodes import (Module, Class, Const, const_factory, From,
+from astroid.node_classes import CONST_CLS
+from astroid.nodes import (Module, Class, Const, const_factory, From,
Function, EmptyNode, Name, Arguments)
-from logilab.astng.bases import BUILTINS, Generator
-from logilab.astng.manager import ASTNGManager
-MANAGER = ASTNGManager()
+from astroid.bases import BUILTINS, Generator
+from astroid.manager import AstroidManager
+MANAGER = AstroidManager()
_CONSTANTS = tuple(CONST_CLS) # the keys of CONST_CLS eg python builtin types
@@ -67,14 +67,14 @@ def attach_import_node(node, modname, membername):
def build_module(name, doc=None):
- """create and initialize a astng Module node"""
+ """create and initialize a astroid Module node"""
node = Module(name, doc, pure_python=False)
node.package = False
node.parent = None
return node
def build_class(name, basenames=(), doc=None):
- """create and initialize a astng Class node"""
+ """create and initialize a astroid Class node"""
node = Class(name, doc)
for base in basenames:
basenode = Name()
@@ -84,7 +84,7 @@ def build_class(name, basenames=(), doc=None):
return node
def build_function(name, args=None, defaults=None, flag=0, doc=None):
- """create and initialize a astng Function node"""
+ """create and initialize a astroid Function node"""
args, defaults = args or [], defaults or []
# first argument is now a list of decorators
func = Function(name, doc)
@@ -107,7 +107,7 @@ def build_function(name, args=None, defaults=None, flag=0, doc=None):
def build_from_import(fromname, names):
- """create and initialize an astng From import statement"""
+ """create and initialize an astroid From import statement"""
return From(fromname, [(name, None) for name in names])
def register_arguments(func, args=None):
@@ -129,13 +129,13 @@ def register_arguments(func, args=None):
register_arguments(func, arg.elts)
def object_build_class(node, member, localname):
- """create astng for a living class object"""
+ """create astroid for a living class object"""
basenames = [base.__name__ for base in member.__bases__]
return _base_class_object_build(node, member, basenames,
localname=localname)
def object_build_function(node, member, localname):
- """create astng for a living function object"""
+ """create astroid for a living function object"""
args, varargs, varkw, defaults = getargspec(member)
if varargs is not None:
args.append(varargs)
@@ -146,11 +146,11 @@ def object_build_function(node, member, localname):
node.add_local_node(func, localname)
def object_build_datadescriptor(node, member, name):
- """create astng for a living data descriptor object"""
+ """create astroid for a living data descriptor object"""
return _base_class_object_build(node, member, [], name)
def object_build_methoddescriptor(node, member, localname):
- """create astng for a living method descriptor object"""
+ """create astroid for a living method descriptor object"""
# FIXME get arguments ?
func = build_function(getattr(member, '__name__', None) or localname,
doc=member.__doc__)
@@ -160,7 +160,7 @@ def object_build_methoddescriptor(node, member, localname):
node.add_local_node(func, localname)
def _base_class_object_build(node, member, basenames, name=None, localname=None):
- """create astng for a living class object, with a given set of base names
+ """create astroid for a living class object, with a given set of base names
(e.g. ancestors)
"""
klass = build_class(name or getattr(member, '__name__', None) or localname,
@@ -197,14 +197,14 @@ class InspectBuilder(object):
Function and Class nodes and some others as guessed.
"""
- # astng from living objects ###############################################
+ # astroid from living objects ###############################################
def __init__(self):
self._done = {}
self._module = None
def inspect_build(self, module, modname=None, path=None):
- """build astng from a living module (i.e. using inspect)
+ """build astroid from a living module (i.e. using inspect)
this is used when there is no python source code available (either
because it's a built-in module or because the .py is not available)
"""
@@ -217,7 +217,7 @@ class InspectBuilder(object):
# in jython, java modules have no __doc__ (see #109562)
node = build_module(modname)
node.file = node.path = path and abspath(path) or path
- MANAGER.astng_cache[modname] = node
+ MANAGER.astroid_cache[modname] = node
node.package = hasattr(module, '__path__')
self._done = {}
self.object_build(node, module)
@@ -289,7 +289,7 @@ class InspectBuilder(object):
modname = getattr(member, '__module__', None)
except:
# XXX use logging
- print 'unexpected error while building astng from living object'
+ print 'unexpected error while building astroid from living object'
import traceback
traceback.print_exc()
modname = None
@@ -315,28 +315,28 @@ class InspectBuilder(object):
return False
-### astng boot strapping ################################################### ###
-ASTNG_BUILDER = InspectBuilder()
+### astroid boot strapping ################################################### ###
+Astroid_BUILDER = InspectBuilder()
_CONST_PROXY = {}
-def astng_boot_strapping():
- """astng boot strapping the builtins module"""
+def astroid_boot_strapping():
+ """astroid boot strapping the builtins module"""
# this boot strapping is necessary since we need the Const nodes to
# inspect_build builtins, and then we can proxy Const
from logilab.common.compat import builtins
- astng_builtin = ASTNG_BUILDER.inspect_build(builtins)
+ astroid_builtin = Astroid_BUILDER.inspect_build(builtins)
for cls, node_cls in CONST_CLS.items():
if cls is type(None):
proxy = build_class('NoneType')
- proxy.parent = astng_builtin
+ proxy.parent = astroid_builtin
else:
- proxy = astng_builtin.getattr(cls.__name__)[0]
+ proxy = astroid_builtin.getattr(cls.__name__)[0]
if cls in (dict, list, set, tuple):
node_cls._proxied = proxy
else:
_CONST_PROXY[cls] = proxy
-astng_boot_strapping()
+astroid_boot_strapping()
# TODO : find a nicer way to handle this situation;
# However __proxied introduced an
@@ -347,5 +347,5 @@ Const._proxied = property(_set_proxied)
from types import GeneratorType
Generator._proxied = Class(GeneratorType.__name__, GeneratorType.__doc__)
-ASTNG_BUILDER.object_build(Generator._proxied, GeneratorType)
+Astroid_BUILDER.object_build(Generator._proxied, GeneratorType)
diff --git a/rebuilder.py b/rebuilder.py
index 0f5c764..16f0db7 100644
--- a/rebuilder.py
+++ b/rebuilder.py
@@ -1,22 +1,22 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
"""this module contains utilities for rebuilding a _ast tree in
-order to get a single ASTNG representation
+order to get a single Astroid representation
"""
import sys
@@ -32,7 +32,7 @@ from _ast import (Expr as Discard, Str,
Eq, Gt, GtE, In, Is, IsNot, Lt, LtE, NotEq, NotIn,
)
-from logilab.astng import nodes as new
+from astroid import nodes as new
_BIN_OP_CLASSES = {Add: '+',
@@ -117,7 +117,7 @@ def _set_infos(oldnode, newnode, parent):
class TreeRebuilder(object):
- """Rebuilds the _ast tree to become an ASTNG tree"""
+ """Rebuilds the _ast tree to become an Astroid tree"""
_visit_meths = {}
def __init__(self):
@@ -287,7 +287,7 @@ class TreeRebuilder(object):
return newnode
def visit_class(self, node, parent):
- """visit a Class node to become astng"""
+ """visit a Class node to become astroid"""
self._metaclass.append(self._metaclass[-1])
newnode = new.Class(node.name, None)
_lineno_parent(node, newnode, parent)
@@ -342,7 +342,7 @@ class TreeRebuilder(object):
def visit_decorators(self, node, parent):
"""visit a Decorators node by returning a fresh instance of it"""
# /!\ node is actually a _ast.Function node while
- # parent is a astng.nodes.Function node
+ # parent is a astroid.nodes.Function node
newnode = new.Decorators()
_lineno_parent(node, newnode, parent)
if 'decorators' in node._fields: # py < 2.6, i.e. 2.5
@@ -461,7 +461,7 @@ class TreeRebuilder(object):
return newnode
def visit_function(self, node, parent):
- """visit an Function node to become astng"""
+ """visit an Function node to become astroid"""
self._global_names.append({})
newnode = new.Function(node.name, None)
_lineno_parent(node, newnode, parent)
@@ -523,7 +523,7 @@ class TreeRebuilder(object):
return newnode
def visit_global(self, node, parent):
- """visit an Global node to become astng"""
+ """visit an Global node to become astroid"""
newnode = new.Global(node.names)
_set_infos(node, newnode, parent)
if self._global_names: # global at the module level, no effect
@@ -813,7 +813,7 @@ class TreeRebuilder3k(TreeRebuilder):
def visit_arg(self, node, parent):
"""visit a arg node by returning a fresh AssName instance"""
# the <arg> node is coming from py>=3.0, but we use AssName in py2.x
- # XXX or we should instead introduce a Arg node in astng ?
+ # XXX or we should instead introduce a Arg node in astroid ?
return self.visit_assname(node, parent, node.arg)
def visit_excepthandler(self, node, parent):
diff --git a/scoped_nodes.py b/scoped_nodes.py
index b53cf0c..ba50b64 100644
--- a/scoped_nodes.py
+++ b/scoped_nodes.py
@@ -1,20 +1,20 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
"""This module contains the classes for "scoped" node, i.e. which are opening a
new local scope in the language definition : Module, Class, Function (and
Lambda, GenExpr, DictComp and SetComp to some extent).
@@ -29,17 +29,17 @@ from itertools import chain
from logilab.common.compat import builtins
from logilab.common.decorators import cached
-from logilab.astng.exceptions import NotFoundError, \
- ASTNGBuildingException, InferenceError
-from logilab.astng.node_classes import Const, DelName, DelAttr, \
+from astroid.exceptions import NotFoundError, \
+ AstroidBuildingException, InferenceError
+from astroid.node_classes import Const, DelName, DelAttr, \
Dict, From, List, Pass, Raise, Return, Tuple, Yield, \
LookupMixIn, const_factory as cf, unpack_infer
-from logilab.astng.bases import NodeNG, InferenceContext, Instance,\
+from astroid.bases import NodeNG, InferenceContext, Instance,\
YES, Generator, UnboundMethod, BoundMethod, _infer_stmts, copy_context, \
BUILTINS
-from logilab.astng.mixins import FilterStmtsMixin
-from logilab.astng.bases import Statement
-from logilab.astng.manager import ASTNGManager
+from astroid.mixins import FilterStmtsMixin
+from astroid.bases import Statement
+from astroid.manager import AstroidManager
def remove_nodes(func, cls):
@@ -72,20 +72,20 @@ def std_special_attributes(self, name, add_locals=True):
return [Dict()] + locals.get(name, [])
raise NotFoundError(name)
-MANAGER = ASTNGManager()
+MANAGER = AstroidManager()
def builtin_lookup(name):
"""lookup a name into the builtin module
- return the list of matching statements and the astng for the builtin
+ return the list of matching statements and the astroid for the builtin
module
"""
- builtin_astng = MANAGER.astng_from_module(builtins)
+ builtin_astroid = MANAGER.astroid_from_module(builtins)
if name == '__dict__':
- return builtin_astng, ()
+ return builtin_astroid, ()
try:
- stmts = builtin_astng.locals[name]
+ stmts = builtin_astroid.locals[name]
except KeyError:
stmts = ()
- return builtin_astng, stmts
+ return builtin_astroid, stmts
# TODO move this Mixin to mixins.py; problem: 'Function' in _scope_lookup
@@ -207,14 +207,14 @@ class LocalsDictNodeNG(LookupMixIn, NodeNG):
# Module #####################################################################
class Module(LocalsDictNodeNG):
- _astng_fields = ('body',)
+ _astroid_fields = ('body',)
fromlineno = 0
lineno = 0
# attributes below are set by the builder module or by raw factories
- # the file from which as been extracted the astng representation. It may
+ # the file from which as been extracted the astroid representation. It may
# be None if the representation has been built from a built-in module
file = None
# encoding of python source file, so we can get unicode out of it (python2
@@ -222,7 +222,7 @@ class Module(LocalsDictNodeNG):
file_encoding = None
# the module name
name = None
- # boolean for astng built from source (i.e. ast)
+ # boolean for astroid built from source (i.e. ast)
pure_python = None
# boolean for package module
package = None
@@ -282,7 +282,7 @@ class Module(LocalsDictNodeNG):
if self.package:
try:
return [self.import_module(name, relative_only=True)]
- except ASTNGBuildingException:
+ except AstroidBuildingException:
raise NotFoundError(name)
except Exception:# XXX pylint tests never pass here; do we need it?
import traceback
@@ -336,13 +336,13 @@ class Module(LocalsDictNodeNG):
level = 0
absmodname = self.relative_to_absolute_name(modname, level)
try:
- return MANAGER.astng_from_module_name(absmodname)
- except ASTNGBuildingException:
+ return MANAGER.astroid_from_module_name(absmodname)
+ except AstroidBuildingException:
# we only want to import a sub module or package of this module,
# skip here
if relative_only:
raise
- return MANAGER.astng_from_module_name(modname)
+ return MANAGER.astroid_from_module_name(modname)
def relative_to_absolute_name(self, modname, level):
"""return the absolute module name for a relative import.
@@ -350,7 +350,7 @@ class Module(LocalsDictNodeNG):
The relative import can be implicit or explicit.
"""
# XXX this returns non sens when called on an absolute import
- # like 'pylint.checkers.logilab.astng.utils'
+ # like 'pylint.checkers.astroid.utils'
# XXX doesn't return absolute name if self.name isn't absolute name
if self.absolute_import_activated() and level is None:
return modname
@@ -387,7 +387,7 @@ class Module(LocalsDictNodeNG):
except AttributeError:
return [name for name in living.__dict__.keys()
if not name.startswith('_')]
- # else lookup the astng
+ # else lookup the astroid
#
# We separate the different steps of lookup in try/excepts
# to avoid catching too many Exceptions
@@ -419,7 +419,7 @@ class ComprehensionScope(LocalsDictNodeNG):
class GenExpr(ComprehensionScope):
- _astng_fields = ('elt', 'generators')
+ _astroid_fields = ('elt', 'generators')
def __init__(self):
self.locals = {}
@@ -428,7 +428,7 @@ class GenExpr(ComprehensionScope):
class DictComp(ComprehensionScope):
- _astng_fields = ('key', 'value', 'generators')
+ _astroid_fields = ('key', 'value', 'generators')
def __init__(self):
self.locals = {}
@@ -438,7 +438,7 @@ class DictComp(ComprehensionScope):
class SetComp(ComprehensionScope):
- _astng_fields = ('elt', 'generators')
+ _astroid_fields = ('elt', 'generators')
def __init__(self):
self.locals = {}
@@ -448,7 +448,7 @@ class SetComp(ComprehensionScope):
class _ListComp(NodeNG):
"""class representing a ListComp node"""
- _astng_fields = ('elt', 'generators')
+ _astroid_fields = ('elt', 'generators')
elt = None
generators = None
@@ -465,7 +465,7 @@ else:
class Lambda(LocalsDictNodeNG, FilterStmtsMixin):
- _astng_fields = ('args', 'body',)
+ _astroid_fields = ('args', 'body',)
name = '<lambda>'
# function's type, 'function' | 'method' | 'staticmethod' | 'classmethod'
@@ -518,7 +518,7 @@ class Lambda(LocalsDictNodeNG, FilterStmtsMixin):
class Function(Statement, Lambda):
- _astng_fields = ('decorators', 'args', 'body')
+ _astroid_fields = ('decorators', 'args', 'body')
special_attributes = set(('__name__', '__doc__', '__dict__'))
is_function = True
@@ -683,7 +683,7 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
# by a raw factories
# a dictionary of class instances attributes
- _astng_fields = ('decorators', 'bases', 'body') # name
+ _astroid_fields = ('decorators', 'bases', 'body') # name
decorators = None
special_attributes = set(('__name__', '__doc__', '__dict__', '__module__',
@@ -802,20 +802,20 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
continue
def local_attr_ancestors(self, name, context=None):
- """return an iterator on astng representation of parent classes
+ """return an iterator on astroid representation of parent classes
which have <name> defined in their locals
"""
- for astng in self.ancestors(context=context):
- if name in astng:
- yield astng
+ for astroid in self.ancestors(context=context):
+ if name in astroid:
+ yield astroid
def instance_attr_ancestors(self, name, context=None):
- """return an iterator on astng representation of parent classes
+ """return an iterator on astroid representation of parent classes
which have <name> defined in their instance attribute dictionary
"""
- for astng in self.ancestors(context=context):
- if name in astng.instance_attrs:
- yield astng
+ for astroid in self.ancestors(context=context):
+ if name in astroid.instance_attrs:
+ yield astroid
def has_base(self, node):
return node in self.bases
@@ -838,7 +838,7 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
local_attr = remove_nodes(local_attr, DelAttr)
def instance_attr(self, name, context=None):
- """return the astng nodes associated to name in this class instance
+ """return the astroid nodes associated to name in this class instance
attributes dictionary and in its parents
:raises `NotFoundError`:
@@ -940,8 +940,8 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
its ancestors
"""
done = {}
- for astng in chain(iter((self,)), self.ancestors()):
- for meth in astng.mymethods():
+ for astroid in chain(iter((self,)), self.ancestors()):
+ for meth in astroid.mymethods():
if meth.name in done:
continue
done[meth.name] = None
diff --git a/setup.py b/setup.py
index b0cdeac..b5c8a2c 100644
--- a/setup.py
+++ b/setup.py
@@ -3,20 +3,20 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it under
+# astroid is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option) any
# later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but WITHOUT
+# astroid is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
"""Generic Setup script, takes package info from __pkginfo__.py file.
"""
__docformat__ = "restructuredtext en"
diff --git a/test/data/module.py b/test/data/module.py
index 811d13f..8b3264b 100644
--- a/test/data/module.py
+++ b/test/data/module.py
@@ -1,10 +1,10 @@
-"""test module for astng
+"""test module for astroid
"""
__revision__ = '$Id: module.py,v 1.2 2005-11-02 11:56:54 syt Exp $'
from logilab.common import modutils
from logilab.common.shellutils import Execute as spawn
-from logilab.astng.utils import *
+from astroid.utils import *
import os.path
MY_DICT = {}
diff --git a/test/regrtest_data/package/import_package_subpackage_module.py b/test/regrtest_data/package/import_package_subpackage_module.py
index 8b354c6..ad442c1 100644
--- a/test/regrtest_data/package/import_package_subpackage_module.py
+++ b/test/regrtest_data/package/import_package_subpackage_module.py
@@ -1,6 +1,6 @@
# pylint: disable-msg=I0011,C0301,W0611
"""I found some of my scripts trigger off an AttributeError in pylint
-0.8.1 (with common 0.12.0 and astng 0.13.1).
+0.8.1 (with common 0.12.0 and astroid 0.13.1).
Traceback (most recent call last):
File "/usr/bin/pylint", line 4, in ?
@@ -10,18 +10,18 @@ Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 412, in check
self.check_file(filepath, modname, checkers)
File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 426, in check_file
- astng = self._check_file(filepath, modname, checkers)
+ astroid = self._check_file(filepath, modname, checkers)
File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 450, in _check_file
- self.check_astng_module(astng, checkers)
- File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 494, in check_astng_module
- self.astng_events(astng, [checker for checker in checkers
- File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 511, in astng_events
- self.astng_events(child, checkers, _reversed_checkers)
- File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 511, in astng_events
- self.astng_events(child, checkers, _reversed_checkers)
- File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 508, in astng_events
- checker.visit(astng)
- File "/usr/lib/python2.4/site-packages/logilab/astng/utils.py", line 84, in visit
+ self.check_astroid_module(astroid, checkers)
+ File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 494, in check_astroid_module
+ self.astroid_events(astroid, [checker for checker in checkers
+ File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 511, in astroid_events
+ self.astroid_events(child, checkers, _reversed_checkers)
+ File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 511, in astroid_events
+ self.astroid_events(child, checkers, _reversed_checkers)
+ File "/usr/lib/python2.4/site-packages/pylint/lint.py", line 508, in astroid_events
+ checker.visit(astroid)
+ File "/usr/lib/python2.4/site-packages/logilab/astroid/utils.py", line 84, in visit
method(node)
File "/usr/lib/python2.4/site-packages/pylint/checkers/variables.py", line 295, in visit_import
self._check_module_attrs(node, module, name_parts[1:])
diff --git a/test/unittest_builder.py b/test/unittest_builder.py
index e88376b..9932caf 100644
--- a/test/unittest_builder.py
+++ b/test/unittest_builder.py
@@ -1,21 +1,21 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""tests for the astng builder and rebuilder module"""
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""tests for the astroid builder and rebuilder module"""
import unittest
import sys
@@ -24,12 +24,12 @@ from os.path import join, abspath, dirname
from logilab.common.testlib import TestCase, unittest_main
from pprint import pprint
-from logilab.astng import builder, nodes, InferenceError, NotFoundError
-from logilab.astng.nodes import Module
-from logilab.astng.bases import YES, BUILTINS
-from logilab.astng.manager import ASTNGManager
+from astroid import builder, nodes, InferenceError, NotFoundError
+from astroid.nodes import Module
+from astroid.bases import YES, BUILTINS
+from astroid.manager import AstroidManager
-MANAGER = ASTNGManager()
+MANAGER = AstroidManager()
from unittest_inference import get_name_node
@@ -41,10 +41,10 @@ DATA = join(dirname(abspath(__file__)), 'data')
class FromToLineNoTC(TestCase):
- astng = builder.ASTNGBuilder().file_build(join(DATA, 'format.py'))
+ astroid = builder.AstroidBuilder().file_build(join(DATA, 'format.py'))
def test_callfunc_lineno(self):
- stmts = self.astng.body
+ stmts = self.astroid.body
# on line 4:
# function('aeozrijz\
# earzer', hop)
@@ -91,7 +91,7 @@ class FromToLineNoTC(TestCase):
self.assertEqual(arg.tolineno, 10+i)
def test_function_lineno(self):
- stmts = self.astng.body
+ stmts = self.astroid.body
# on line 15:
# def definition(a,
# b,
@@ -112,13 +112,13 @@ class FromToLineNoTC(TestCase):
'(no line number on function args)')
def test_decorated_function_lineno(self):
- astng = builder.ASTNGBuilder().string_build('''
+ astroid = builder.AstroidBuilder().string_build('''
@decorator
def function(
arg):
print (arg)
''', __name__, __file__)
- function = astng['function']
+ function = astroid['function']
self.assertEqual(function.fromlineno, 3) # XXX discussable, but that's what is expected by pylint right now
self.assertEqual(function.tolineno, 5)
self.assertEqual(function.decorators.fromlineno, 2)
@@ -131,7 +131,7 @@ def function(
def test_class_lineno(self):
- stmts = self.astng.body
+ stmts = self.astroid.body
# on line 20:
# class debile(dict,
# object):
@@ -147,7 +147,7 @@ def function(
self.assertEqual(pass_.tolineno, 22)
def test_if_lineno(self):
- stmts = self.astng.body
+ stmts = self.astroid.body
# on line 20:
# if aaaa: pass
# else:
@@ -176,8 +176,8 @@ else:
print ("bouh")
''',
):
- astng = builder.ASTNGBuilder().string_build(code, __name__, __file__)
- stmt = astng.body[0]
+ astroid = builder.AstroidBuilder().string_build(code, __name__, __file__)
+ stmt = astroid.body[0]
self.assertEqual(stmt.fromlineno, 2)
self.assertEqual(stmt.tolineno, 6)
self.assertEqual(stmt.blockstart_tolineno, 2)
@@ -186,7 +186,7 @@ else:
def test_try_except_lineno(self):
- astng = builder.ASTNGBuilder().string_build('''
+ astroid = builder.AstroidBuilder().string_build('''
try:
print (a)
except:
@@ -194,7 +194,7 @@ except:
else:
print ("bouh")
''', __name__, __file__)
- try_ = astng.body[0]
+ try_ = astroid.body[0]
self.assertEqual(try_.fromlineno, 2)
self.assertEqual(try_.tolineno, 7)
self.assertEqual(try_.blockstart_tolineno, 2)
@@ -207,13 +207,13 @@ else:
def test_try_finally_lineno(self):
- astng = builder.ASTNGBuilder().string_build('''
+ astroid = builder.AstroidBuilder().string_build('''
try:
print (a)
finally:
print ("bouh")
''', __name__, __file__)
- try_ = astng.body[0]
+ try_ = astroid.body[0]
self.assertEqual(try_.fromlineno, 2)
self.assertEqual(try_.tolineno, 5)
self.assertEqual(try_.blockstart_tolineno, 2)
@@ -222,7 +222,7 @@ finally:
def test_try_finally_25_lineno(self):
- astng = builder.ASTNGBuilder().string_build('''
+ astroid = builder.AstroidBuilder().string_build('''
try:
print (a)
except:
@@ -230,7 +230,7 @@ except:
finally:
print ("bouh")
''', __name__, __file__)
- try_ = astng.body[0]
+ try_ = astroid.body[0]
self.assertEqual(try_.fromlineno, 2)
self.assertEqual(try_.tolineno, 7)
self.assertEqual(try_.blockstart_tolineno, 2)
@@ -239,12 +239,12 @@ finally:
def test_with_lineno(self):
- astng = builder.ASTNGBuilder().string_build('''
+ astroid = builder.AstroidBuilder().string_build('''
from __future__ import with_statement
with file("/tmp/pouet") as f:
print (f)
''', __name__, __file__)
- with_ = astng.body[1]
+ with_ = astroid.body[1]
self.assertEqual(with_.fromlineno, 3)
self.assertEqual(with_.tolineno, 4)
self.assertEqual(with_.blockstart_tolineno, 3)
@@ -254,19 +254,19 @@ with file("/tmp/pouet") as f:
class BuilderTC(TestCase):
def setUp(self):
- self.builder = builder.ASTNGBuilder()
+ self.builder = builder.AstroidBuilder()
def test_border_cases(self):
"""check that a file with no trailing new line is parseable"""
self.builder.file_build(join(DATA, 'noendingnewline.py'), 'data.noendingnewline')
- self.assertRaises(builder.ASTNGBuildingException,
+ self.assertRaises(builder.AstroidBuildingException,
self.builder.file_build, join(DATA, 'inexistant.py'), 'whatever')
def test_inspect_build0(self):
- """test astng tree build from a living object"""
- builtin_astng = MANAGER.astng_from_module_name(BUILTINS)
+ """test astroid tree build from a living object"""
+ builtin_astroid = MANAGER.astroid_from_module_name(BUILTINS)
if sys.version_info < (3, 0):
- fclass = builtin_astng['file']
+ fclass = builtin_astroid['file']
self.assertIn('name', fclass)
self.assertIn('mode', fclass)
self.assertIn('read', fclass)
@@ -274,56 +274,56 @@ class BuilderTC(TestCase):
self.assertTrue(fclass.pytype(), '%s.type' % BUILTINS)
self.assertIsInstance(fclass['read'], nodes.Function)
# check builtin function has args.args == None
- dclass = builtin_astng['dict']
+ dclass = builtin_astroid['dict']
self.assertIsNone(dclass['has_key'].args.args)
# just check type and object are there
- builtin_astng.getattr('type')
- objectastng = builtin_astng.getattr('object')[0]
- self.assertIsInstance(objectastng.getattr('__new__')[0], nodes.Function)
+ builtin_astroid.getattr('type')
+ objectastroid = builtin_astroid.getattr('object')[0]
+ self.assertIsInstance(objectastroid.getattr('__new__')[0], nodes.Function)
# check open file alias
- builtin_astng.getattr('open')
+ builtin_astroid.getattr('open')
# check 'help' is there (defined dynamically by site.py)
- builtin_astng.getattr('help')
+ builtin_astroid.getattr('help')
# check property has __init__
- pclass = builtin_astng['property']
+ pclass = builtin_astroid['property']
self.assertIn('__init__', pclass)
- self.assertIsInstance(builtin_astng['None'], nodes.Const)
- self.assertIsInstance(builtin_astng['True'], nodes.Const)
- self.assertIsInstance(builtin_astng['False'], nodes.Const)
+ self.assertIsInstance(builtin_astroid['None'], nodes.Const)
+ self.assertIsInstance(builtin_astroid['True'], nodes.Const)
+ self.assertIsInstance(builtin_astroid['False'], nodes.Const)
if sys.version_info < (3, 0):
- self.assertIsInstance(builtin_astng['Exception'], nodes.From)
- self.assertIsInstance(builtin_astng['NotImplementedError'], nodes.From)
+ self.assertIsInstance(builtin_astroid['Exception'], nodes.From)
+ self.assertIsInstance(builtin_astroid['NotImplementedError'], nodes.From)
else:
- self.assertIsInstance(builtin_astng['Exception'], nodes.Class)
- self.assertIsInstance(builtin_astng['NotImplementedError'], nodes.Class)
+ self.assertIsInstance(builtin_astroid['Exception'], nodes.Class)
+ self.assertIsInstance(builtin_astroid['NotImplementedError'], nodes.Class)
def test_inspect_build1(self):
- time_astng = MANAGER.astng_from_module_name('time')
- self.assertTrue(time_astng)
- self.assertEqual(time_astng['time'].args.defaults, [])
+ time_astroid = MANAGER.astroid_from_module_name('time')
+ self.assertTrue(time_astroid)
+ self.assertEqual(time_astroid['time'].args.defaults, [])
def test_inspect_build2(self):
- """test astng tree build from a living object"""
+ """test astroid tree build from a living object"""
try:
from mx import DateTime
except ImportError:
self.skipTest('test skipped: mxDateTime is not available')
else:
- dt_astng = self.builder.inspect_build(DateTime)
- dt_astng.getattr('DateTime')
+ dt_astroid = self.builder.inspect_build(DateTime)
+ dt_astroid.getattr('DateTime')
# this one is failing since DateTimeType.__module__ = 'builtins' !
- #dt_astng.getattr('DateTimeType')
+ #dt_astroid.getattr('DateTimeType')
def test_inspect_build3(self):
self.builder.inspect_build(unittest)
def test_inspect_build_instance(self):
- """test astng tree build from a living object"""
+ """test astroid tree build from a living object"""
if sys.version_info >= (3, 0):
self.skipTest('The module "exceptions" is gone in py3.x')
import exceptions
- builtin_astng = self.builder.inspect_build(exceptions)
- fclass = builtin_astng['OSError']
+ builtin_astroid = self.builder.inspect_build(exceptions)
+ fclass = builtin_astroid['OSError']
# things like OSError.strerror are now (2.5) data descriptors on the
# class instead of entries in the __dict__ of an instance
container = fclass
@@ -332,22 +332,22 @@ class BuilderTC(TestCase):
self.assertIn('filename', container)
def test_inspect_build_type_object(self):
- builtin_astng = MANAGER.astng_from_module_name(BUILTINS)
+ builtin_astroid = MANAGER.astroid_from_module_name(BUILTINS)
- infered = list(builtin_astng.igetattr('object'))
+ infered = list(builtin_astroid.igetattr('object'))
self.assertEqual(len(infered), 1)
infered = infered[0]
self.assertEqual(infered.name, 'object')
infered.as_string() # no crash test
- infered = list(builtin_astng.igetattr('type'))
+ infered = list(builtin_astroid.igetattr('type'))
self.assertEqual(len(infered), 1)
infered = infered[0]
self.assertEqual(infered.name, 'type')
infered.as_string() # no crash test
def test_package_name(self):
- """test base properties and method of a astng module"""
+ """test base properties and method of a astroid module"""
datap = self.builder.file_build(join(DATA, '__init__.py'), 'data')
self.assertEqual(datap.name, 'data')
self.assertEqual(datap.package, 1)
@@ -372,8 +372,8 @@ def yiell():
self.assertIsInstance(func.body[1].body[0].value, nodes.Yield)
def test_object(self):
- obj_astng = self.builder.inspect_build(object)
- self.assertIn('__setattr__', obj_astng)
+ obj_astroid = self.builder.inspect_build(object)
+ self.assertIn('__setattr__', obj_astroid)
def test_newstyle_detection(self):
data = '''
@@ -397,13 +397,13 @@ class E(A):
class F:
"new style"
'''
- mod_astng = self.builder.string_build(data, __name__, __file__)
- self.assertFalse(mod_astng['A'].newstyle)
- self.assertFalse(mod_astng['B'].newstyle)
- self.assertTrue(mod_astng['C'].newstyle)
- self.assertTrue(mod_astng['D'].newstyle)
- self.assertFalse(mod_astng['E'].newstyle)
- self.assertTrue(mod_astng['F'].newstyle)
+ mod_astroid = self.builder.string_build(data, __name__, __file__)
+ self.assertFalse(mod_astroid['A'].newstyle)
+ self.assertFalse(mod_astroid['B'].newstyle)
+ self.assertTrue(mod_astroid['C'].newstyle)
+ self.assertTrue(mod_astroid['D'].newstyle)
+ self.assertFalse(mod_astroid['E'].newstyle)
+ self.assertTrue(mod_astroid['F'].newstyle)
def test_globals(self):
data = '''
@@ -417,23 +417,23 @@ def global_no_effect():
global CSTE2
print (CSTE)
'''
- astng = self.builder.string_build(data, __name__, __file__)
- self.assertEqual(len(astng.getattr('CSTE')), 2)
- self.assertIsInstance(astng.getattr('CSTE')[0], nodes.AssName)
- self.assertEqual(astng.getattr('CSTE')[0].fromlineno, 2)
- self.assertEqual(astng.getattr('CSTE')[1].fromlineno, 6)
+ astroid = self.builder.string_build(data, __name__, __file__)
+ self.assertEqual(len(astroid.getattr('CSTE')), 2)
+ self.assertIsInstance(astroid.getattr('CSTE')[0], nodes.AssName)
+ self.assertEqual(astroid.getattr('CSTE')[0].fromlineno, 2)
+ self.assertEqual(astroid.getattr('CSTE')[1].fromlineno, 6)
self.assertRaises(NotFoundError,
- astng.getattr, 'CSTE2')
+ astroid.getattr, 'CSTE2')
self.assertRaises(InferenceError,
- astng['global_no_effect'].ilookup('CSTE2').next)
+ astroid['global_no_effect'].ilookup('CSTE2').next)
def test_socket_build(self):
import socket
- astng = self.builder.module_build(socket)
+ astroid = self.builder.module_build(socket)
# XXX just check the first one. Actually 3 objects are inferred (look at
# the socket module) but the last one as those attributes dynamically
- # set and astng is missing this.
- for fclass in astng.igetattr('socket'):
+ # set and astroid is missing this.
+ for fclass in astroid.igetattr('socket'):
#print fclass.root().name, fclass.name, fclass.lineno
self.assertIn('connect', fclass)
self.assertIn('send', fclass)
@@ -442,24 +442,24 @@ def global_no_effect():
def test_gen_expr_var_scope(self):
data = 'l = list(n for n in range(10))\n'
- astng = self.builder.string_build(data, __name__, __file__)
+ astroid = self.builder.string_build(data, __name__, __file__)
# n unavailable outside gen expr scope
- self.assertNotIn('n', astng)
+ self.assertNotIn('n', astroid)
# test n is inferable anyway
- n = get_name_node(astng, 'n')
- self.assertIsNot(n.scope(), astng)
+ n = get_name_node(astroid, 'n')
+ self.assertIsNot(n.scope(), astroid)
self.assertEqual([i.__class__ for i in n.infer()],
[YES.__class__])
class FileBuildTC(TestCase):
- module = builder.ASTNGBuilder().file_build(join(DATA, 'module.py'), 'data.module')
+ module = builder.AstroidBuilder().file_build(join(DATA, 'module.py'), 'data.module')
def test_module_base_props(self):
- """test base properties and method of a astng module"""
+ """test base properties and method of a astroid module"""
module = self.module
self.assertEqual(module.name, 'data.module')
- self.assertEqual(module.doc, "test module for astng\n")
+ self.assertEqual(module.doc, "test module for astroid\n")
self.assertEqual(module.fromlineno, 0)
self.assertIsNone(module.parent)
self.assertEqual(module.frame(), module)
@@ -472,7 +472,7 @@ class FileBuildTC(TestCase):
self.assertEqual(module.statement(), module)
def test_module_locals(self):
- """test the 'locals' dictionary of a astng module"""
+ """test the 'locals' dictionary of a astroid module"""
module = self.module
_locals = module.locals
self.assertIs(_locals, module.globals)
@@ -484,7 +484,7 @@ class FileBuildTC(TestCase):
self.assertEqual(keys, should)
def test_function_base_props(self):
- """test base properties and method of a astng function"""
+ """test base properties and method of a astroid function"""
module = self.module
function = module['global_access']
self.assertEqual(function.name, 'global_access')
@@ -498,14 +498,14 @@ class FileBuildTC(TestCase):
self.assertEqual(function.type, 'function')
def test_function_locals(self):
- """test the 'locals' dictionary of a astng function"""
+ """test the 'locals' dictionary of a astroid function"""
_locals = self.module['global_access'].locals
self.assertEqual(len(_locals), 4)
keys = sorted(_locals.keys())
self.assertEqual(keys, ['i', 'key', 'local', 'val'])
def test_class_base_props(self):
- """test base properties and method of a astng class"""
+ """test base properties and method of a astroid class"""
module = self.module
klass = module['YO']
self.assertEqual(klass.name, 'YO')
@@ -519,7 +519,7 @@ class FileBuildTC(TestCase):
self.assertEqual(klass.newstyle, False)
def test_class_locals(self):
- """test the 'locals' dictionary of a astng class"""
+ """test the 'locals' dictionary of a astroid class"""
module = self.module
klass1 = module['YO']
locals1 = klass1.locals
@@ -547,7 +547,7 @@ class FileBuildTC(TestCase):
self.assertEqual(klass2.basenames, ['YO'])
def test_method_base_props(self):
- """test base properties and method of a astng method"""
+ """test base properties and method of a astroid method"""
klass2 = self.module['YOUPI']
# "normal" method
method = klass2['method']
@@ -566,7 +566,7 @@ class FileBuildTC(TestCase):
self.assertEqual(method.type, 'staticmethod')
def test_method_locals(self):
- """test the 'locals' dictionary of a astng method"""
+ """test the 'locals' dictionary of a astroid method"""
method = self.module['YOUPI']['method']
_locals = method.locals
keys = sorted(_locals)
@@ -581,14 +581,14 @@ class FileBuildTC(TestCase):
class ModuleBuildTC(FileBuildTC):
def setUp(self):
- abuilder = builder.ASTNGBuilder()
+ abuilder = builder.AstroidBuilder()
self.module = abuilder.module_build(test_module)
class MoreTC(TestCase):
def setUp(self):
- self.builder = builder.ASTNGBuilder()
+ self.builder = builder.AstroidBuilder()
def test_infered_build(self):
code = '''class A: pass
@@ -598,15 +598,15 @@ def A_ass_type(self):
print (self)
A.ass_type = A_ass_type
'''
- astng = self.builder.string_build(code)
- lclass = list(astng.igetattr('A'))
+ astroid = self.builder.string_build(code)
+ lclass = list(astroid.igetattr('A'))
self.assertEqual(len(lclass), 1)
lclass = lclass[0]
self.assertIn('ass_type', lclass.locals)
self.assertIn('type', lclass.locals)
def test_augassign_attr(self):
- astng = self.builder.string_build("""class Counter:
+ astroid = self.builder.string_build("""class Counter:
v = 0
def inc(self):
self.v += 1
@@ -614,7 +614,7 @@ A.ass_type = A_ass_type
# Check self.v += 1 generate AugAssign(AssAttr(...)), not AugAssign(GetAttr(AssName...))
def test_dumb_module(self):
- astng = self.builder.string_build("pouet")
+ astroid = self.builder.string_build("pouet")
def test_infered_dont_pollute(self):
code = '''
@@ -623,7 +623,7 @@ def func(a=None):
def func2(a={}):
a.custom_attr = 0
'''
- astng = self.builder.string_build(code)
+ astroid = self.builder.string_build(code)
nonetype = nodes.const_factory(None)
self.assertNotIn('custom_attr', nonetype.locals)
self.assertNotIn('custom_attr', nonetype.instance_attrs)
@@ -634,14 +634,14 @@ def func2(a={}):
def test_asstuple(self):
code = 'a, b = range(2)'
- astng = self.builder.string_build(code)
- self.assertIn('b', astng.locals)
+ astroid = self.builder.string_build(code)
+ self.assertIn('b', astroid.locals)
code = '''
def visit_if(self, node):
node.test, body = node.tests[0]
'''
- astng = self.builder.string_build(code)
- self.assertIn('body', astng['visit_if'].locals)
+ astroid = self.builder.string_build(code)
+ self.assertIn('body', astroid['visit_if'].locals)
def test_build_constants(self):
'''test expected values of constants after rebuilding'''
@@ -651,8 +651,8 @@ def func():
return
return 'None'
'''
- astng = self.builder.string_build(code)
- none, nothing, chain = [ret.value for ret in astng.body[0].body]
+ astroid = self.builder.string_build(code)
+ none, nothing, chain = [ret.value for ret in astroid.body[0].body]
self.assertIsInstance(none, nodes.Const)
self.assertIsNone(none.value)
self.assertIsNone(nothing)
@@ -670,8 +670,8 @@ class A(object):
def hop(cls):
return None
'''
- astng = self.builder.string_build(code)
- self.assertEqual(astng['A']['hop'].type, 'classmethod')
+ astroid = self.builder.string_build(code)
+ self.assertEqual(astroid['A']['hop'].type, 'classmethod')
if sys.version_info < (3, 0):
diff --git a/test/unittest_inference.py b/test/unittest_inference.py
index 8ef038f..7636428 100644
--- a/test/unittest_inference.py
+++ b/test/unittest_inference.py
@@ -1,21 +1,21 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""tests for the astng inference capabilities
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""tests for the astroid inference capabilities
"""
from os.path import join, dirname, abspath
import sys
@@ -23,9 +23,9 @@ from StringIO import StringIO
from logilab.common.testlib import TestCase, unittest_main, require_version
-from logilab.astng import InferenceError, builder, nodes
-from logilab.astng.inference import infer_end as inference_infer_end
-from logilab.astng.bases import YES, Instance, BoundMethod, UnboundMethod,\
+from astroid import InferenceError, builder, nodes
+from astroid.inference import infer_end as inference_infer_end
+from astroid.bases import YES, Instance, BoundMethod, UnboundMethod,\
path_wrapper, BUILTINS
def get_name_node(start_from, name, index=0):
@@ -34,7 +34,7 @@ def get_name_node(start_from, name, index=0):
def get_node_of_class(start_from, klass):
return start_from.nodes_of_class(klass).next()
-builder = builder.ASTNGBuilder()
+builder = builder.AstroidBuilder()
class InferenceUtilsTC(TestCase):
@@ -86,107 +86,107 @@ i, (j, k) = "glup", f
a, b= b, a # Gasp !
'''
- astng = builder.string_build(CODE, __name__, __file__)
+ astroid = builder.string_build(CODE, __name__, __file__)
def test_module_inference(self):
- infered = self.astng.infer()
+ infered = self.astroid.infer()
obj = infered.next()
self.assertEqual(obj.name, __name__)
self.assertEqual(obj.root().name, __name__)
self.assertRaises(StopIteration, infered.next)
def test_class_inference(self):
- infered = self.astng['C'].infer()
+ infered = self.astroid['C'].infer()
obj = infered.next()
self.assertEqual(obj.name, 'C')
self.assertEqual(obj.root().name, __name__)
self.assertRaises(StopIteration, infered.next)
def test_function_inference(self):
- infered = self.astng['C']['meth1'].infer()
+ infered = self.astroid['C']['meth1'].infer()
obj = infered.next()
self.assertEqual(obj.name, 'meth1')
self.assertEqual(obj.root().name, __name__)
self.assertRaises(StopIteration, infered.next)
def test_builtin_name_inference(self):
- infered = self.astng['C']['meth1']['var'].infer()
+ infered = self.astroid['C']['meth1']['var'].infer()
var = infered.next()
self.assertEqual(var.name, 'object')
self.assertEqual(var.root().name, BUILTINS)
self.assertRaises(StopIteration, infered.next)
def test_tupleassign_name_inference(self):
- infered = self.astng['a'].infer()
+ infered = self.astroid['a'].infer()
exc = infered.next()
self.assertIsInstance(exc, Instance)
self.assertEqual(exc.name, 'Exception')
self.assertEqual(exc.root().name, EXC_MODULE)
self.assertRaises(StopIteration, infered.next)
- infered = self.astng['b'].infer()
+ infered = self.astroid['b'].infer()
const = infered.next()
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, 1)
self.assertRaises(StopIteration, infered.next)
- infered = self.astng['c'].infer()
+ infered = self.astroid['c'].infer()
const = infered.next()
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, "bonjour")
self.assertRaises(StopIteration, infered.next)
def test_listassign_name_inference(self):
- infered = self.astng['d'].infer()
+ infered = self.astroid['d'].infer()
exc = infered.next()
self.assertIsInstance(exc, Instance)
self.assertEqual(exc.name, 'Exception')
self.assertEqual(exc.root().name, EXC_MODULE)
self.assertRaises(StopIteration, infered.next)
- infered = self.astng['e'].infer()
+ infered = self.astroid['e'].infer()
const = infered.next()
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, 1.0)
self.assertRaises(StopIteration, infered.next)
- infered = self.astng['f'].infer()
+ infered = self.astroid['f'].infer()
const = infered.next()
self.assertIsInstance(const, nodes.Tuple)
self.assertRaises(StopIteration, infered.next)
def test_advanced_tupleassign_name_inference1(self):
- infered = self.astng['g'].infer()
+ infered = self.astroid['g'].infer()
const = infered.next()
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, "bonjour")
self.assertRaises(StopIteration, infered.next)
- infered = self.astng['h'].infer()
+ infered = self.astroid['h'].infer()
var = infered.next()
self.assertEqual(var.name, 'object')
self.assertEqual(var.root().name, BUILTINS)
self.assertRaises(StopIteration, infered.next)
def test_advanced_tupleassign_name_inference2(self):
- infered = self.astng['i'].infer()
+ infered = self.astroid['i'].infer()
const = infered.next()
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, u"glup")
self.assertRaises(StopIteration, infered.next)
- infered = self.astng['j'].infer()
+ infered = self.astroid['j'].infer()
const = infered.next()
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, "bonjour")
self.assertRaises(StopIteration, infered.next)
- infered = self.astng['k'].infer()
+ infered = self.astroid['k'].infer()
var = infered.next()
self.assertEqual(var.name, 'object')
self.assertEqual(var.root().name, BUILTINS)
self.assertRaises(StopIteration, infered.next)
def test_swap_assign_inference(self):
- infered = self.astng.locals['a'][1].infer()
+ infered = self.astroid.locals['a'][1].infer()
const = infered.next()
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, 1)
self.assertRaises(StopIteration, infered.next)
- infered = self.astng.locals['b'][1].infer()
+ infered = self.astroid.locals['b'][1].infer()
exc = infered.next()
self.assertIsInstance(exc, Instance)
self.assertEqual(exc.name, 'Exception')
@@ -194,7 +194,7 @@ a, b= b, a # Gasp !
self.assertRaises(StopIteration, infered.next)
def test_getattr_inference1(self):
- infered = self.astng['ex'].infer()
+ infered = self.astroid['ex'].infer()
exc = infered.next()
self.assertIsInstance(exc, Instance)
self.assertEqual(exc.name, 'Exception')
@@ -202,28 +202,28 @@ a, b= b, a # Gasp !
self.assertRaises(StopIteration, infered.next)
def test_getattr_inference2(self):
- infered = get_node_of_class(self.astng['C']['meth2'], nodes.Getattr).infer()
+ infered = get_node_of_class(self.astroid['C']['meth2'], nodes.Getattr).infer()
meth1 = infered.next()
self.assertEqual(meth1.name, 'meth1')
self.assertEqual(meth1.root().name, __name__)
self.assertRaises(StopIteration, infered.next)
def test_getattr_inference3(self):
- infered = self.astng['C']['meth3']['b'].infer()
+ infered = self.astroid['C']['meth3']['b'].infer()
const = infered.next()
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, 4)
self.assertRaises(StopIteration, infered.next)
def test_getattr_inference4(self):
- infered = self.astng['C']['meth3']['c'].infer()
+ infered = self.astroid['C']['meth3']['c'].infer()
const = infered.next()
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, "hop")
self.assertRaises(StopIteration, infered.next)
def test_callfunc_inference(self):
- infered = self.astng['v'].infer()
+ infered = self.astroid['v'].infer()
meth1 = infered.next()
self.assertIsInstance(meth1, Instance)
self.assertEqual(meth1.name, 'object')
@@ -231,7 +231,7 @@ a, b= b, a # Gasp !
self.assertRaises(StopIteration, infered.next)
def test_unbound_method_inference(self):
- infered = self.astng['m_unbound'].infer()
+ infered = self.astroid['m_unbound'].infer()
meth1 = infered.next()
self.assertIsInstance(meth1, UnboundMethod)
self.assertEqual(meth1.name, 'meth1')
@@ -239,7 +239,7 @@ a, b= b, a # Gasp !
self.assertRaises(StopIteration, infered.next)
def test_bound_method_inference(self):
- infered = self.astng['m_bound'].infer()
+ infered = self.astroid['m_bound'].infer()
meth1 = infered.next()
self.assertIsInstance(meth1, BoundMethod)
self.assertEqual(meth1.name, 'meth1')
@@ -247,7 +247,7 @@ a, b= b, a # Gasp !
self.assertRaises(StopIteration, infered.next)
def test_args_default_inference1(self):
- optarg = get_name_node(self.astng['C']['meth1'], 'optarg')
+ optarg = get_name_node(self.astroid['C']['meth1'], 'optarg')
infered = optarg.infer()
obj1 = infered.next()
self.assertIsInstance(obj1, nodes.Const)
@@ -257,7 +257,7 @@ a, b= b, a # Gasp !
self.assertRaises(StopIteration, infered.next)
def test_args_default_inference2(self):
- infered = self.astng['C']['meth3'].ilookup('d')
+ infered = self.astroid['C']['meth3'].ilookup('d')
obj1 = infered.next()
self.assertIsInstance(obj1, nodes.Const)
self.assertEqual(obj1.value, 4)
@@ -266,7 +266,7 @@ a, b= b, a # Gasp !
self.assertRaises(StopIteration, infered.next)
def test_inference_restrictions(self):
- infered = get_name_node(self.astng['C']['meth1'], 'arg1').infer()
+ infered = get_name_node(self.astroid['C']['meth1'], 'arg1').infer()
obj1 = infered.next()
self.assertIs(obj1, YES, obj1)
self.assertRaises(StopIteration, infered.next)
@@ -279,9 +279,9 @@ class A:
class A(A):
pass
'''
- astng = builder.string_build(code, __name__, __file__)
- a1 = astng.locals['A'][0]
- a2 = astng.locals['A'][1]
+ astroid = builder.string_build(code, __name__, __file__)
+ a1 = astroid.locals['A'][0]
+ a2 = astroid.locals['A'][1]
a2_ancestors = list(a2.ancestors())
self.assertEqual(len(a2_ancestors), 1)
self.assertIs(a2_ancestors[0], a1)
@@ -296,12 +296,12 @@ class B(A): pass
class A(B):
pass
'''
- astng = builder.string_build(code, __name__, __file__)
- a1 = astng.locals['A'][0]
- a2 = astng.locals['A'][1]
+ astroid = builder.string_build(code, __name__, __file__)
+ a1 = astroid.locals['A'][0]
+ a2 = astroid.locals['A'][1]
a2_ancestors = list(a2.ancestors())
self.assertEqual(len(a2_ancestors), 2)
- self.assertIs(a2_ancestors[0], astng.locals['B'][0])
+ self.assertIs(a2_ancestors[0], astroid.locals['B'][0])
self.assertIs(a2_ancestors[1], a1)
@@ -312,8 +312,8 @@ def f(f=1):
a = f()
'''
- astng = builder.string_build(code, __name__, __file__)
- a = astng['a']
+ astroid = builder.string_build(code, __name__, __file__)
+ a = astroid['a']
a_infered = a.infered()
self.assertEqual(a_infered[0].value, 1)
self.assertEqual(len(a_infered), 1)
@@ -323,8 +323,8 @@ a = f()
def f():
raise NotImplementedError
'''
- astng = builder.string_build(code, __name__, __file__)
- error = astng.nodes_of_class(nodes.Name).next()
+ astroid = builder.string_build(code, __name__, __file__)
+ error = astroid.nodes_of_class(nodes.Name).next()
nie = error.infered()[0]
self.assertIsInstance(nie, nodes.Class)
nie_ancestors = [c.name for c in nie.ancestors()]
@@ -345,14 +345,14 @@ except Exception, ex:
'''
if sys.version_info >= (3, 0):
code = code.replace(', ex:', ' as ex:')
- astng = builder.string_build(code, __name__, __file__)
- ex1 = astng['ex1']
+ astroid = builder.string_build(code, __name__, __file__)
+ ex1 = astroid['ex1']
ex1_infer = ex1.infer()
ex1 = ex1_infer.next()
self.assertIsInstance(ex1, Instance)
self.assertEqual(ex1.name, 'NameError')
self.assertRaises(StopIteration, ex1_infer.next)
- ex2 = astng['ex2']
+ ex2 = astroid['ex2']
ex2_infer = ex2.infer()
ex2 = ex2_infer.next()
self.assertIsInstance(ex2, Instance)
@@ -375,17 +375,17 @@ c = a
a = 2
d = a
'''
- astng = builder.string_build(code, __name__, __file__)
- n = astng['b']
+ astroid = builder.string_build(code, __name__, __file__)
+ n = astroid['b']
n_infer = n.infer()
infered = n_infer.next()
self.assertIsInstance(infered, nodes.Const)
self.assertEqual(infered.value, 1)
self.assertRaises(StopIteration, n_infer.next)
- n = astng['c']
+ n = astroid['c']
n_infer = n.infer()
self.assertRaises(InferenceError, n_infer.next)
- n = astng['d']
+ n = astroid['d']
n_infer = n.infer()
infered = n_infer.next()
self.assertIsInstance(infered, nodes.Const)
@@ -400,8 +400,8 @@ d = {}
s = ''
s2 = '_'
'''
- astng = builder.string_build(code, __name__, __file__)
- n = astng['l']
+ astroid = builder.string_build(code, __name__, __file__)
+ n = astroid['l']
infered = n.infer().next()
self.assertIsInstance(infered, nodes.List)
self.assertIsInstance(infered, Instance)
@@ -409,35 +409,35 @@ s2 = '_'
self.assertIsInstance(infered._proxied, nodes.Class)
self.assertEqual(infered._proxied.name, 'list')
self.assertIn('append', infered._proxied.locals)
- n = astng['t']
+ n = astroid['t']
infered = n.infer().next()
self.assertIsInstance(infered, nodes.Tuple)
self.assertIsInstance(infered, Instance)
self.assertEqual(infered.getitem(0).value, 2)
self.assertIsInstance(infered._proxied, nodes.Class)
self.assertEqual(infered._proxied.name, 'tuple')
- n = astng['d']
+ n = astroid['d']
infered = n.infer().next()
self.assertIsInstance(infered, nodes.Dict)
self.assertIsInstance(infered, Instance)
self.assertIsInstance(infered._proxied, nodes.Class)
self.assertEqual(infered._proxied.name, 'dict')
self.assertIn('get', infered._proxied.locals)
- n = astng['s']
+ n = astroid['s']
infered = n.infer().next()
self.assertIsInstance(infered, nodes.Const)
self.assertIsInstance(infered, Instance)
self.assertEqual(infered.name, 'str')
self.assertIn('lower', infered._proxied.locals)
- n = astng['s2']
+ n = astroid['s2']
infered = n.infer().next()
self.assertEqual(infered.getitem(0).value, '_')
@require_version('2.7')
def test_builtin_types_py27(self):
code = 's = {1}'
- astng = builder.string_build(code, __name__, __file__)
- n = astng['s']
+ astroid = builder.string_build(code, __name__, __file__)
+ n = astroid['s']
infered = n.infer().next()
self.assertIsInstance(infered, nodes.Set)
self.assertIsInstance(infered, Instance)
@@ -448,8 +448,8 @@ s2 = '_'
if sys.version_info >= (3, 0):
self.skipTest('unicode removed on py >= 3.0')
code = '''u = u""'''
- astng = builder.string_build(code, __name__, __file__)
- n = astng['u']
+ astroid = builder.string_build(code, __name__, __file__)
+ n = astroid['u']
infered = n.infer().next()
self.assertIsInstance(infered, nodes.Const)
self.assertIsInstance(infered, Instance)
@@ -462,10 +462,10 @@ class A:
statm = staticmethod(open)
clsm = classmethod('whatever')
'''
- astng = builder.string_build(code, __name__, __file__)
- statm = astng['A'].igetattr('statm').next()
+ astroid = builder.string_build(code, __name__, __file__)
+ statm = astroid['A'].igetattr('statm').next()
self.assertTrue(statm.callable())
- clsm = astng['A'].igetattr('clsm').next()
+ clsm = astroid['A'].igetattr('clsm').next()
self.assertTrue(clsm.callable())
def test_bt_ancestor_crash(self):
@@ -473,8 +473,8 @@ class A:
class Warning(Warning):
pass
'''
- astng = builder.string_build(code, __name__, __file__)
- w = astng['Warning']
+ astroid = builder.string_build(code, __name__, __file__)
+ w = astroid['Warning']
ancestors = w.ancestors()
ancestor = ancestors.next()
self.assertEqual(ancestor.name, 'Warning')
@@ -495,8 +495,8 @@ class Warning(Warning):
from logilab.common.modutils import load_module_from_name
xxx = load_module_from_name('__pkginfo__')
'''
- astng = builder.string_build(code, __name__, __file__)
- xxx = astng['xxx']
+ astroid = builder.string_build(code, __name__, __file__)
+ xxx = astroid['xxx']
self.assertSetEqual(set(n.__class__ for n in xxx.infered()),
set([nodes.Const, YES.__class__]))
@@ -511,20 +511,20 @@ class ErudiEntitySchema:
kwargs['e_type'] = e_type.capitalize().encode()
print(args)
'''
- astng = builder.string_build(code, __name__, __file__)
- arg = get_name_node(astng['ErudiEntitySchema']['__init__'], 'e_type')
+ astroid = builder.string_build(code, __name__, __file__)
+ arg = get_name_node(astroid['ErudiEntitySchema']['__init__'], 'e_type')
self.assertEqual([n.__class__ for n in arg.infer()],
[YES.__class__])
- arg = get_name_node(astng['ErudiEntitySchema']['__init__'], 'kwargs')
+ arg = get_name_node(astroid['ErudiEntitySchema']['__init__'], 'kwargs')
self.assertEqual([n.__class__ for n in arg.infer()],
[nodes.Dict])
- arg = get_name_node(astng['ErudiEntitySchema']['meth'], 'e_type')
+ arg = get_name_node(astroid['ErudiEntitySchema']['meth'], 'e_type')
self.assertEqual([n.__class__ for n in arg.infer()],
[YES.__class__])
- arg = get_name_node(astng['ErudiEntitySchema']['meth'], 'args')
+ arg = get_name_node(astroid['ErudiEntitySchema']['meth'], 'args')
self.assertEqual([n.__class__ for n in arg.infer()],
[nodes.Tuple])
- arg = get_name_node(astng['ErudiEntitySchema']['meth'], 'kwargs')
+ arg = get_name_node(astroid['ErudiEntitySchema']['meth'], 'kwargs')
self.assertEqual([n.__class__ for n in arg.infer()],
[nodes.Dict])
@@ -535,8 +535,8 @@ def test_view(rql, vid, tags=()):
tags = list(tags)
tags.append(vid)
'''
- astng = builder.string_build(code, __name__, __file__)
- name = get_name_node(astng['test_view'], 'tags', -1)
+ astroid = builder.string_build(code, __name__, __file__)
+ name = get_name_node(astroid['test_view'], 'tags', -1)
it = name.infer()
tags = it.next()
self.assertEqual(tags.__class__, Instance)
@@ -580,13 +580,13 @@ if __name__ == '__main__':
if ok:
fct(a_line)
'''
- astng = builder.string_build(code, __name__, __file__)
- self.assertEqual(len(list(astng['process_line'].infer_call_result(
+ astroid = builder.string_build(code, __name__, __file__)
+ self.assertEqual(len(list(astroid['process_line'].infer_call_result(
None))), 3)
- self.assertEqual(len(list(astng['tupletest'].infer())), 3)
+ self.assertEqual(len(list(astroid['tupletest'].infer())), 3)
values = ['Function(first_word)', 'Function(last_word)', 'Const(NoneType)']
self.assertEqual([str(infered)
- for infered in astng['fct'].infer()], values)
+ for infered in astroid['fct'].infer()], values)
def test_float_complex_ambiguity(self):
code = '''
@@ -600,11 +600,11 @@ def no_conjugate_member(magic_flag):
return something
return something.conjugate()
'''
- astng = builder.string_build(code, __name__, __file__)
+ astroid = builder.string_build(code, __name__, __file__)
self.assertEqual([i.value for i in
- astng['no_conjugate_member'].ilookup('something')], [1.0, 1.0j])
+ astroid['no_conjugate_member'].ilookup('something')], [1.0, 1.0j])
self.assertEqual([i.value for i in
- get_name_node(astng, 'something', -1).infer()], [1.0, 1.0j])
+ get_name_node(astroid, 'something', -1).infer()], [1.0, 1.0j])
def test_lookup_cond_branches(self):
code = '''
@@ -615,9 +615,9 @@ def no_conjugate_member(magic_flag):
something = 1.0j
return something.conjugate()
'''
- astng = builder.string_build(code, __name__, __file__)
+ astroid = builder.string_build(code, __name__, __file__)
self.assertEqual([i.value for i in
- get_name_node(astng, 'something', -1).infer()], [1.0, 1.0j])
+ get_name_node(astroid, 'something', -1).infer()], [1.0, 1.0j])
def test_simple_subscript(self):
@@ -631,17 +631,17 @@ e = {'key': 'value'}
f = e['key']
print (f)
'''
- astng = builder.string_build(code, __name__, __file__)
+ astroid = builder.string_build(code, __name__, __file__)
self.assertEqual([i.value for i in
- get_name_node(astng, 'a', -1).infer()], [1])
+ get_name_node(astroid, 'a', -1).infer()], [1])
self.assertEqual([i.value for i in
- get_name_node(astng, 'b', -1).infer()], [2])
+ get_name_node(astroid, 'b', -1).infer()], [2])
self.assertEqual([i.value for i in
- get_name_node(astng, 'c', -1).infer()], [3])
+ get_name_node(astroid, 'c', -1).infer()], [3])
self.assertEqual([i.value for i in
- get_name_node(astng, 'd', -1).infer()], [6])
+ get_name_node(astroid, 'd', -1).infer()], [6])
self.assertEqual([i.value for i in
- get_name_node(astng, 'f', -1).infer()], ['value'])
+ get_name_node(astroid, 'f', -1).infer()], ['value'])
#def test_simple_tuple(self):
#"""test case for a simple tuple value"""
@@ -651,8 +651,8 @@ print (f)
#b = (22,)
#some = a + b
#"""
- #astng = builder.string_build(code, __name__, __file__)
- #self.assertEqual(astng['some'].infer.next().as_string(), "(1, 22)")
+ #astroid = builder.string_build(code, __name__, __file__)
+ #self.assertEqual(astroid['some'].infer.next().as_string(), "(1, 22)")
def test_simple_for(self):
code = '''
@@ -664,28 +664,28 @@ for b,c in [(1,2), (3,4)]:
print ([(d,e) for e,d in ([1,2], [3,4])])
'''
- astng = builder.string_build(code, __name__, __file__)
+ astroid = builder.string_build(code, __name__, __file__)
self.assertEqual([i.value for i in
- get_name_node(astng, 'a', -1).infer()], [1, 2, 3])
+ get_name_node(astroid, 'a', -1).infer()], [1, 2, 3])
self.assertEqual([i.value for i in
- get_name_node(astng, 'b', -1).infer()], [1, 3])
+ get_name_node(astroid, 'b', -1).infer()], [1, 3])
self.assertEqual([i.value for i in
- get_name_node(astng, 'c', -1).infer()], [2, 4])
+ get_name_node(astroid, 'c', -1).infer()], [2, 4])
self.assertEqual([i.value for i in
- get_name_node(astng, 'd', -1).infer()], [2, 4])
+ get_name_node(astroid, 'd', -1).infer()], [2, 4])
self.assertEqual([i.value for i in
- get_name_node(astng, 'e', -1).infer()], [1, 3])
+ get_name_node(astroid, 'e', -1).infer()], [1, 3])
def test_simple_for_genexpr(self):
code = '''
print ((d,e) for e,d in ([1,2], [3,4]))
'''
- astng = builder.string_build(code, __name__, __file__)
+ astroid = builder.string_build(code, __name__, __file__)
self.assertEqual([i.value for i in
- get_name_node(astng, 'd', -1).infer()], [2, 4])
+ get_name_node(astroid, 'd', -1).infer()], [2, 4])
self.assertEqual([i.value for i in
- get_name_node(astng, 'e', -1).infer()], [1, 3])
+ get_name_node(astroid, 'e', -1).infer()], [1, 3])
def test_builtin_help(self):
@@ -694,8 +694,8 @@ help()
'''
# XXX failing since __builtin__.help assignment has
# been moved into a function...
- astng = builder.string_build(code, __name__, __file__)
- node = get_name_node(astng, 'help', -1)
+ astroid = builder.string_build(code, __name__, __file__)
+ node = get_name_node(astroid, 'help', -1)
infered = list(node.infer())
self.assertEqual(len(infered), 1, infered)
self.assertIsInstance(infered[0], Instance)
@@ -706,8 +706,8 @@ help()
code = '''
open("toto.txt")
'''
- astng = builder.string_build(code, __name__, __file__)
- node = get_name_node(astng, 'open', -1)
+ astroid = builder.string_build(code, __name__, __file__)
+ node = get_name_node(astroid, 'open', -1)
infered = list(node.infer())
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], nodes.Function)
@@ -720,8 +720,8 @@ def mirror(arg=None):
un = mirror(1)
'''
- astng = builder.string_build(code, __name__, __file__)
- infered = list(astng.igetattr('un'))
+ astroid = builder.string_build(code, __name__, __file__)
+ infered = list(astroid.igetattr('un'))
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], nodes.Const)
self.assertEqual(infered[0].value, 1)
@@ -732,11 +732,11 @@ mirror = lambda x=None: x
un = mirror(1)
'''
- astng = builder.string_build(code, __name__, __file__)
- infered = list(astng.igetattr('mirror'))
+ astroid = builder.string_build(code, __name__, __file__)
+ infered = list(astroid.igetattr('mirror'))
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], nodes.Lambda)
- infered = list(astng.igetattr('un'))
+ infered = list(astroid.igetattr('un'))
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], nodes.Const)
self.assertEqual(infered[0].value, 1)
@@ -754,8 +754,8 @@ class Sub(Super):
sub = Sub.instance()
'''
- astng = builder.string_build(code, __name__, __file__)
- infered = list(astng.igetattr('sub'))
+ astroid = builder.string_build(code, __name__, __file__)
+ infered = list(astroid.igetattr('sub'))
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], Instance)
self.assertEqual(infered[0]._proxied.name, 'Sub')
@@ -772,18 +772,18 @@ assert e(__file__)
from new import code as make_code
print (make_code)
'''
- astng = builder.string_build(code, __name__, __file__)
- infered = list(astng.igetattr('osp'))
+ astroid = builder.string_build(code, __name__, __file__)
+ infered = list(astroid.igetattr('osp'))
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], nodes.Module)
self.assertEqual(infered[0].name, 'os.path')
- infered = list(astng.igetattr('e'))
+ infered = list(astroid.igetattr('e'))
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], nodes.Function)
self.assertEqual(infered[0].name, 'exists')
if sys.version_info >= (3, 0):
self.skipTest('<new> module has been removed')
- infered = list(astng.igetattr('make_code'))
+ infered = list(astroid.igetattr('make_code'))
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], Instance)
self.assertEqual(str(infered[0]),
@@ -798,51 +798,51 @@ print (make_code)
def test_unary_not(self):
for code in ('a = not (1,); b = not ()',
'a = not {1:2}; b = not {}'):
- astng = builder.string_build(code, __name__, __file__)
- self._test_const_infered(astng['a'], False)
- self._test_const_infered(astng['b'], True)
+ astroid = builder.string_build(code, __name__, __file__)
+ self._test_const_infered(astroid['a'], False)
+ self._test_const_infered(astroid['b'], True)
def test_binary_op_int_add(self):
- astng = builder.string_build('a = 1 + 2', __name__, __file__)
- self._test_const_infered(astng['a'], 3)
+ astroid = builder.string_build('a = 1 + 2', __name__, __file__)
+ self._test_const_infered(astroid['a'], 3)
def test_binary_op_int_sub(self):
- astng = builder.string_build('a = 1 - 2', __name__, __file__)
- self._test_const_infered(astng['a'], -1)
+ astroid = builder.string_build('a = 1 - 2', __name__, __file__)
+ self._test_const_infered(astroid['a'], -1)
def test_binary_op_float_div(self):
- astng = builder.string_build('a = 1 / 2.', __name__, __file__)
- self._test_const_infered(astng['a'], 1 / 2.)
+ astroid = builder.string_build('a = 1 / 2.', __name__, __file__)
+ self._test_const_infered(astroid['a'], 1 / 2.)
def test_binary_op_str_mul(self):
- astng = builder.string_build('a = "*" * 40', __name__, __file__)
- self._test_const_infered(astng['a'], "*" * 40)
+ astroid = builder.string_build('a = "*" * 40', __name__, __file__)
+ self._test_const_infered(astroid['a'], "*" * 40)
def test_binary_op_bitand(self):
- astng = builder.string_build('a = 23&20', __name__, __file__)
- self._test_const_infered(astng['a'], 23&20)
+ astroid = builder.string_build('a = 23&20', __name__, __file__)
+ self._test_const_infered(astroid['a'], 23&20)
def test_binary_op_bitor(self):
- astng = builder.string_build('a = 23|8', __name__, __file__)
- self._test_const_infered(astng['a'], 23|8)
+ astroid = builder.string_build('a = 23|8', __name__, __file__)
+ self._test_const_infered(astroid['a'], 23|8)
def test_binary_op_bitxor(self):
- astng = builder.string_build('a = 23^9', __name__, __file__)
- self._test_const_infered(astng['a'], 23^9)
+ astroid = builder.string_build('a = 23^9', __name__, __file__)
+ self._test_const_infered(astroid['a'], 23^9)
def test_binary_op_shiftright(self):
- astng = builder.string_build('a = 23 >>1', __name__, __file__)
- self._test_const_infered(astng['a'], 23>>1)
+ astroid = builder.string_build('a = 23 >>1', __name__, __file__)
+ self._test_const_infered(astroid['a'], 23>>1)
def test_binary_op_shiftleft(self):
- astng = builder.string_build('a = 23 <<1', __name__, __file__)
- self._test_const_infered(astng['a'], 23<<1)
+ astroid = builder.string_build('a = 23 <<1', __name__, __file__)
+ self._test_const_infered(astroid['a'], 23<<1)
def test_binary_op_list_mul(self):
for code in ('a = [[]] * 2', 'a = 2 * [[]]'):
- astng = builder.string_build(code, __name__, __file__)
- infered = list(astng['a'].infer())
+ astroid = builder.string_build(code, __name__, __file__)
+ infered = list(astroid['a'].infer())
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], nodes.List)
self.assertEqual(len(infered[0].elts), 2)
@@ -851,18 +851,18 @@ print (make_code)
def test_binary_op_list_mul_none(self):
'test correct handling on list multiplied by None'
- astng = builder.string_build( 'a = [1] * None\nb = [1] * "r"')
- infered = astng['a'].infered()
+ astroid = builder.string_build( 'a = [1] * None\nb = [1] * "r"')
+ infered = astroid['a'].infered()
self.assertEqual(len(infered), 1)
self.assertEqual(infered[0], YES)
- infered = astng['b'].infered()
+ infered = astroid['b'].infered()
self.assertEqual(len(infered), 1)
self.assertEqual(infered[0], YES)
def test_binary_op_tuple_add(self):
- astng = builder.string_build('a = (1,) + (2,)', __name__, __file__)
- infered = list(astng['a'].infer())
+ astroid = builder.string_build('a = (1,) + (2,)', __name__, __file__)
+ infered = list(astroid['a'].infer())
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], nodes.Tuple)
self.assertEqual(len(infered[0].elts), 2)
@@ -887,8 +887,8 @@ def randint(maximum):
x = randint(1)
'''
- astng = builder.string_build(code, __name__, __file__)
- infered = list(astng.igetattr('x'))
+ astroid = builder.string_build(code, __name__, __file__)
+ infered = list(astroid.igetattr('x'))
self.assertEqual(len(infered), 2)
value = [str(v) for v in infered]
# The __name__ trick here makes it work when invoked directly
@@ -902,8 +902,8 @@ x = randint(1)
def f(g = lambda: None):
g().x
'''
- astng = builder.string_build(code, __name__, __file__)
- callfuncnode = astng['f'].body[0].value.expr
+ astroid = builder.string_build(code, __name__, __file__)
+ callfuncnode = astroid['f'].body[0].value.expr
infered = list(callfuncnode.infer())
self.assertEqual(len(infered), 2, infered)
infered.remove(YES)
@@ -915,43 +915,43 @@ def f(g = lambda: None):
def f(x):
a = ()[x]
'''
- astng = builder.string_build(code, __name__, __file__)
- infered = list(astng['f'].ilookup('a'))
+ astroid = builder.string_build(code, __name__, __file__)
+ infered = list(astroid['f'].ilookup('a'))
self.assertEqual(len(infered), 1)
self.assertEqual(infered[0], YES)
def test_python25_generator_exit(self):
sys.stderr = StringIO()
data = "b = {}[str(0)+''].a"
- astng = builder.string_build(data, __name__, __file__)
- list(astng['b'].infer())
+ astroid = builder.string_build(data, __name__, __file__)
+ list(astroid['b'].infer())
output = sys.stderr.getvalue()
# I have no idea how to test for this in another way...
self.assertNotIn("RuntimeError", output, "Exception exceptions.RuntimeError: 'generator ignored GeneratorExit' in <generator object> ignored")
sys.stderr = sys.__stderr__
def test_python25_relative_import(self):
- data = "from ...common import date; print (date)"
+ data = "from ...logilab.common import date; print (date)"
# !! FIXME also this relative import would not work 'in real' (no __init__.py in test/)
# the test works since we pretend we have a package by passing the full modname
- astng = builder.string_build(data, 'logilab.astng.test.unittest_inference', __file__)
- infered = get_name_node(astng, 'date').infer().next()
+ astroid = builder.string_build(data, 'astroid.test.unittest_inference', __file__)
+ infered = get_name_node(astroid, 'date').infer().next()
self.assertIsInstance(infered, nodes.Module)
self.assertEqual(infered.name, 'logilab.common.date')
def test_python25_no_relative_import(self):
fname = join(abspath(dirname(__file__)), 'regrtest_data', 'package', 'absimport.py')
- astng = builder.file_build(fname, 'absimport')
- self.assertTrue(astng.absolute_import_activated(), True)
- infered = get_name_node(astng, 'import_package_subpackage_module').infer().next()
+ astroid = builder.file_build(fname, 'absimport')
+ self.assertTrue(astroid.absolute_import_activated(), True)
+ infered = get_name_node(astroid, 'import_package_subpackage_module').infer().next()
# failed to import since absolute_import is activated
self.assertIs(infered, YES)
def test_nonregr_absolute_import(self):
fname = join(abspath(dirname(__file__)), 'regrtest_data', 'absimp', 'string.py')
- astng = builder.file_build(fname, 'absimp.string')
- self.assertTrue(astng.absolute_import_activated(), True)
- infered = get_name_node(astng, 'string').infer().next()
+ astroid = builder.file_build(fname, 'absimp.string')
+ self.assertTrue(astroid.absolute_import_activated(), True)
+ infered = get_name_node(astroid, 'string').infer().next()
self.assertIsInstance(infered, nodes.Module)
self.assertEqual(infered.name, 'string')
self.assertIn('ascii_letters', infered.locals)
@@ -965,15 +965,15 @@ def f(x):
print (Browser)
b = Browser()
'''
- astng = builder.string_build(data, __name__, __file__)
- browser = get_name_node(astng, 'Browser').infer().next()
+ astroid = builder.string_build(data, __name__, __file__)
+ browser = get_name_node(astroid, 'Browser').infer().next()
self.assertIsInstance(browser, nodes.Class)
bopen = list(browser.igetattr('open'))
self.skipTest('the commit said: "huum, see that later"')
self.assertEqual(len(bopen), 1)
self.assertIsInstance(bopen[0], nodes.Function)
self.assertTrue(bopen[0].callable())
- b = get_name_node(astng, 'b').infer().next()
+ b = get_name_node(astroid, 'b').infer().next()
self.assertIsInstance(b, Instance)
bopen = list(b.igetattr('open'))
self.assertEqual(len(bopen), 1)
@@ -997,18 +997,18 @@ my_smtp = SendMailController().smtp
my_me = SendMailController().me
'''
decorators = set(['%s.property' % BUILTINS])
- astng = builder.string_build(code, __name__, __file__)
- self.assertEqual(astng['SendMailController']['smtp'].decoratornames(),
+ astroid = builder.string_build(code, __name__, __file__)
+ self.assertEqual(astroid['SendMailController']['smtp'].decoratornames(),
decorators)
- propinfered = list(astng.body[2].value.infer())
+ propinfered = list(astroid.body[2].value.infer())
self.assertEqual(len(propinfered), 1)
propinfered = propinfered[0]
self.assertIsInstance(propinfered, Instance)
self.assertEqual(propinfered.name, 'SMTP')
self.assertEqual(propinfered.root().name, 'smtplib')
- self.assertEqual(astng['SendMailController']['me'].decoratornames(),
+ self.assertEqual(astroid['SendMailController']['me'].decoratornames(),
decorators)
- propinfered = list(astng.body[3].value.infer())
+ propinfered = list(astroid.body[3].value.infer())
self.assertEqual(len(propinfered), 1)
propinfered = propinfered[0]
self.assertIsInstance(propinfered, Instance)
@@ -1029,12 +1029,12 @@ class EnvBasedTC2:
print (pactions)
'''
- astng = builder.string_build(code, __name__, __file__)
- pactions = get_name_node(astng, 'pactions')
+ astroid = builder.string_build(code, __name__, __file__)
+ pactions = get_name_node(astroid, 'pactions')
infered = list(pactions.infer())
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], nodes.Function)
- pactions = get_name_node(astng['EnvBasedTC2'], 'pactions')
+ pactions = get_name_node(astroid['EnvBasedTC2'], 'pactions')
infered = list(pactions.infer())
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], nodes.Function)
@@ -1045,8 +1045,8 @@ a = 1
a += 2
print (a)
'''
- astng = builder.string_build(code, __name__, __file__)
- infered = list(get_name_node(astng, 'a').infer())
+ astroid = builder.string_build(code, __name__, __file__)
+ infered = list(get_name_node(astroid, 'a').infer())
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], nodes.Const)
@@ -1062,8 +1062,8 @@ def foo(self, bar):
spam = bar(None, qux)
print (spam)
'''
- astng = builder.string_build(code, __name__, __file__)
- infered = list(get_name_node(astng['foo'], 'spam').infer())
+ astroid = builder.string_build(code, __name__, __file__)
+ infered = list(get_name_node(astroid['foo'], 'spam').infer())
self.assertEqual(len(infered), 1)
self.assertIs(infered[0], YES)
@@ -1087,10 +1087,10 @@ class DataManager(object):
p = self.app
print (p)
'''
- astng = builder.string_build(code, __name__, __file__)
- infered = list(Instance(astng['DataManager']).igetattr('app'))
+ astroid = builder.string_build(code, __name__, __file__)
+ infered = list(Instance(astroid['DataManager']).igetattr('app'))
self.assertEqual(len(infered), 2, infered) # None / Instance(Application)
- infered = list(get_name_node(astng['DataManager']['test'], 'p').infer())
+ infered = list(get_name_node(astroid['DataManager']['test'], 'p').infer())
self.assertEqual(len(infered), 2, infered)
for node in infered:
if isinstance(node, Instance) and node.name == 'Application':
@@ -1123,8 +1123,8 @@ def main():
Z = test()
'''
- astng = builder.string_build(code, __name__, __file__)
- infered = list(astng['Z'].infer())
+ astroid = builder.string_build(code, __name__, __file__)
+ infered = list(astroid['Z'].infer())
self.assertEqual(len(infered), 1, infered)
self.assertIsInstance(infered[0], Instance)
self.assertIsInstance(infered[0]._proxied, nodes.Class)
@@ -1141,9 +1141,9 @@ class NewTest(object):
n = NewTest()
'''
- astng = builder.string_build(code, __name__, __file__)
- self.assertRaises(InferenceError, list, astng['NewTest'].igetattr('arg'))
- n = astng['n'].infer().next()
+ astroid = builder.string_build(code, __name__, __file__)
+ self.assertRaises(InferenceError, list, astroid['NewTest'].igetattr('arg'))
+ n = astroid['n'].infer().next()
infered = list(n.igetattr('arg'))
self.assertEqual(len(infered), 1, infered)
@@ -1154,8 +1154,8 @@ from data import nonregr
class Xxx(nonregr.Aaa, nonregr.Ccc):
"doc"
'''
- astng = builder.string_build(code, __name__, __file__)
- parents = list(astng['Xxx'].ancestors())
+ astroid = builder.string_build(code, __name__, __file__)
+ parents = list(astroid['Xxx'].ancestors())
self.assertEqual(len(parents), 3, parents) # Aaa, Ccc, object
if __name__ == '__main__':
diff --git a/test/unittest_inspector.py b/test/unittest_inspector.py
index dcbc0de..358dd96 100644
--- a/test/unittest_inspector.py
+++ b/test/unittest_inspector.py
@@ -22,14 +22,14 @@ from os.path import join, abspath, dirname
from logilab.common.testlib import TestCase, unittest_main
-from logilab.astng import nodes, inspector
-from logilab.astng.bases import Instance, YES
+from astroid import nodes, inspector
+from astroid.bases import Instance, YES
-from logilab.astng.manager import ASTNGManager, _silent_no_wrap
+from astroid.manager import AstroidManager, _silent_no_wrap
-MANAGER = ASTNGManager()
+MANAGER = AstroidManager()
-def astng_wrapper(func, modname):
+def astroid_wrapper(func, modname):
return func(modname)
@@ -39,7 +39,7 @@ DATA2 = join(dirname(abspath(__file__)), 'data2')
class LinkerTC(TestCase):
def setUp(self):
- self.project = MANAGER.project_from_files([DATA2], astng_wrapper)
+ self.project = MANAGER.project_from_files([DATA2], astroid_wrapper)
self.linker = inspector.Linker(self.project)
self.linker.visit(self.project)
diff --git a/test/unittest_lookup.py b/test/unittest_lookup.py
index c82c2d3..f25c07f 100644
--- a/test/unittest_lookup.py
+++ b/test/unittest_lookup.py
@@ -1,34 +1,34 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""tests for the astng variable lookup capabilities
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""tests for the astroid variable lookup capabilities
"""
import sys
from os.path import join, abspath, dirname
from logilab.common.testlib import TestCase, unittest_main, require_version
-from logilab.astng import builder, nodes, scoped_nodes, \
+from astroid import builder, nodes, scoped_nodes, \
InferenceError, NotFoundError, UnresolvableName
-from logilab.astng.scoped_nodes import builtin_lookup, Function
-from logilab.astng.bases import YES
+from astroid.scoped_nodes import builtin_lookup, Function
+from astroid.bases import YES
from unittest_inference import get_name_node
-builder = builder.ASTNGBuilder()
+builder = builder.AstroidBuilder()
DATA = join(dirname(abspath(__file__)), 'data')
MODULE = builder.file_build(join(DATA, 'module.py'), 'data.module')
MODULE2 = builder.file_build(join(DATA, 'module2.py'), 'data.module2')
@@ -48,18 +48,18 @@ a = None
def func():
c = 1
'''
- astng = builder.string_build(code, __name__, __file__)
+ astroid = builder.string_build(code, __name__, __file__)
# a & b
- a = astng.nodes_of_class(nodes.Name).next()
+ a = astroid.nodes_of_class(nodes.Name).next()
self.assertEqual(a.lineno, 2)
if sys.version_info < (3, 0):
- self.assertEqual(len(astng.lookup('b')[1]), 2)
- self.assertEqual(len(astng.lookup('a')[1]), 3)
- b = astng.locals['b'][1]
+ self.assertEqual(len(astroid.lookup('b')[1]), 2)
+ self.assertEqual(len(astroid.lookup('a')[1]), 3)
+ b = astroid.locals['b'][1]
else:
- self.assertEqual(len(astng.lookup('b')[1]), 1)
- self.assertEqual(len(astng.lookup('a')[1]), 2)
- b = astng.locals['b'][0]
+ self.assertEqual(len(astroid.lookup('b')[1]), 1)
+ self.assertEqual(len(astroid.lookup('a')[1]), 2)
+ b = astroid.locals['b'][0]
stmts = a.lookup('a')[1]
self.assertEqual(len(stmts), 1)
self.assertEqual(b.lineno, 6)
@@ -68,18 +68,18 @@ def func():
self.assertEqual(b_value.value, 1)
# c
self.assertRaises(StopIteration, b_infer.next)
- func = astng.locals['func'][0]
+ func = astroid.locals['func'][0]
self.assertEqual(len(func.lookup('c')[1]), 1)
def test_module(self):
- astng = builder.string_build('pass', __name__, __file__)
+ astroid = builder.string_build('pass', __name__, __file__)
# built-in objects
- none = astng.ilookup('None').next()
+ none = astroid.ilookup('None').next()
self.assertIsNone(none.value)
- obj = astng.ilookup('object').next()
+ obj = astroid.ilookup('object').next()
self.assertIsInstance(obj, nodes.Class)
self.assertEqual(obj.name, 'object')
- self.assertRaises(InferenceError, astng.ilookup('YOAA').next)
+ self.assertRaises(InferenceError, astroid.ilookup('YOAA').next)
# XXX
self.assertEqual(len(list(NONREGR.ilookup('enumerate'))), 2)
@@ -92,9 +92,9 @@ class A:
class A(A):
pass
'''
- astng = builder.string_build(code, __name__, __file__)
- cls1 = astng.locals['A'][0]
- cls2 = astng.locals['A'][1]
+ astroid = builder.string_build(code, __name__, __file__)
+ cls1 = astroid.locals['A'][0]
+ cls2 = astroid.locals['A'][1]
name = cls2.nodes_of_class(nodes.Name).next()
self.assertEqual(name.infer().next(), cls1)
@@ -134,7 +134,7 @@ class A(A):
def test_loopvar_hiding(self):
- astng = builder.string_build("""
+ astroid = builder.string_build("""
x = 10
for x in range(5):
print (x)
@@ -142,7 +142,7 @@ for x in range(5):
if x > 0:
print ('#' * x)
""", __name__, __file__)
- xnames = [n for n in astng.nodes_of_class(nodes.Name) if n.name == 'x']
+ xnames = [n for n in astroid.nodes_of_class(nodes.Name) if n.name == 'x']
# inside the loop, only one possible assignment
self.assertEqual(len(xnames[0].lookup('x')[1]), 1)
# outside the loop, two possible assignments
@@ -150,12 +150,12 @@ if x > 0:
self.assertEqual(len(xnames[2].lookup('x')[1]), 2)
def test_list_comps(self):
- astng = builder.string_build("""
+ astroid = builder.string_build("""
print ([ i for i in range(10) ])
print ([ i for i in range(10) ])
print ( list( i for i in range(10) ) )
""", __name__, __file__)
- xnames = [n for n in astng.nodes_of_class(nodes.Name) if n.name == 'i']
+ xnames = [n for n in astroid.nodes_of_class(nodes.Name) if n.name == 'i']
self.assertEqual(len(xnames[0].lookup('i')[1]), 1)
self.assertEqual(xnames[0].lookup('i')[1][0].lineno, 2)
self.assertEqual(len(xnames[1].lookup('i')[1]), 1)
@@ -165,11 +165,11 @@ print ( list( i for i in range(10) ) )
def test_list_comp_target(self):
"""test the list comprehension target"""
- astng = builder.string_build("""
+ astroid = builder.string_build("""
ten = [ var for var in range(10) ]
var
""")
- var = astng.body[1].value
+ var = astroid.body[1].value
if sys.version_info < (3, 0):
self.assertEqual(var.infered(), [YES])
else:
@@ -177,17 +177,17 @@ var
@require_version('2.7')
def test_dict_comps(self):
- astng = builder.string_build("""
+ astroid = builder.string_build("""
print ({ i: j for i in range(10) for j in range(10) })
print ({ i: j for i in range(10) for j in range(10) })
""", __name__, __file__)
- xnames = [n for n in astng.nodes_of_class(nodes.Name) if n.name == 'i']
+ xnames = [n for n in astroid.nodes_of_class(nodes.Name) if n.name == 'i']
self.assertEqual(len(xnames[0].lookup('i')[1]), 1)
self.assertEqual(xnames[0].lookup('i')[1][0].lineno, 2)
self.assertEqual(len(xnames[1].lookup('i')[1]), 1)
self.assertEqual(xnames[1].lookup('i')[1][0].lineno, 3)
- xnames = [n for n in astng.nodes_of_class(nodes.Name) if n.name == 'j']
+ xnames = [n for n in astroid.nodes_of_class(nodes.Name) if n.name == 'j']
self.assertEqual(len(xnames[0].lookup('i')[1]), 1)
self.assertEqual(xnames[0].lookup('i')[1][0].lineno, 2)
self.assertEqual(len(xnames[1].lookup('i')[1]), 1)
@@ -195,11 +195,11 @@ print ({ i: j for i in range(10) for j in range(10) })
@require_version('2.7')
def test_set_comps(self):
- astng = builder.string_build("""
+ astroid = builder.string_build("""
print ({ i for i in range(10) })
print ({ i for i in range(10) })
""", __name__, __file__)
- xnames = [n for n in astng.nodes_of_class(nodes.Name) if n.name == 'i']
+ xnames = [n for n in astroid.nodes_of_class(nodes.Name) if n.name == 'i']
self.assertEqual(len(xnames[0].lookup('i')[1]), 1)
self.assertEqual(xnames[0].lookup('i')[1][0].lineno, 2)
self.assertEqual(len(xnames[1].lookup('i')[1]), 1)
@@ -207,11 +207,11 @@ print ({ i for i in range(10) })
@require_version('2.7')
def test_set_comp_closure(self):
- astng = builder.string_build("""
+ astroid = builder.string_build("""
ten = { var for var in range(10) }
var
""")
- var = astng.body[1].value
+ var = astroid.body[1].value
self.assertRaises(UnresolvableName, var.infered)
def test_generator_attributes(self):
@@ -242,23 +242,23 @@ p2 = Pouet()
class NoName: pass
p3 = NoName()
'''
- astng = builder.string_build(code, __name__, __file__)
- p1 = astng['p1'].infer().next()
+ astroid = builder.string_build(code, __name__, __file__)
+ p1 = astroid['p1'].infer().next()
self.assertTrue(p1.getattr('__name__'))
- p2 = astng['p2'].infer().next()
+ p2 = astroid['p2'].infer().next()
self.assertTrue(p2.getattr('__name__'))
- self.assertTrue(astng['NoName'].getattr('__name__'))
- p3 = astng['p3'].infer().next()
+ self.assertTrue(astroid['NoName'].getattr('__name__'))
+ p3 = astroid['p3'].infer().next()
self.assertRaises(NotFoundError, p3.getattr, '__name__')
def test_function_module_special(self):
- astng = builder.string_build('''
+ astroid = builder.string_build('''
def initialize(linter):
"""initialize linter with checkers in this package """
package_load(linter, __path__[0])
''', 'data.__init__', 'data/__init__.py')
- path = [n for n in astng.nodes_of_class(nodes.Name) if n.name == '__path__'][0]
+ path = [n for n in astroid.nodes_of_class(nodes.Name) if n.name == '__path__'][0]
self.assertEqual(len(path.lookup('__path__')[1]), 1)
@@ -285,8 +285,8 @@ class foo:
def test(self):
pass
'''
- astng = builder.string_build(code, __name__, __file__)
- member = get_name_node(astng['foo'], 'member')
+ astroid = builder.string_build(code, __name__, __file__)
+ member = get_name_node(astroid['foo'], 'member')
it = member.infer()
obj = it.next()
self.assertIsInstance(obj, nodes.Const)
@@ -304,8 +304,8 @@ class FileA:
def funcA():
return 4
'''
- astng = builder.string_build(code, __name__, __file__)
- decname = get_name_node(astng['FileA'], 'decorator')
+ astroid = builder.string_build(code, __name__, __file__)
+ decname = get_name_node(astroid['FileA'], 'decorator')
it = decname.infer()
obj = it.next()
self.assertIsInstance(obj, nodes.Function)
@@ -326,8 +326,8 @@ class Test:
def __init__(self):
print (FileA.funcA())
'''
- astng = builder.string_build(code, __name__, __file__)
- it = astng['Test']['__init__'].ilookup('FileA')
+ astroid = builder.string_build(code, __name__, __file__)
+ it = astroid['Test']['__init__'].ilookup('FileA')
obj = it.next()
self.assertIsInstance(obj, nodes.Class)
self.assertRaises(StopIteration, it.next)
@@ -347,10 +347,10 @@ del Frobble
def run1():
f = Frobble()
'''
- astng = builder.string_build(code, __name__, __file__)
- stmts = astng['run2'].lookup('Frobbel')[1]
+ astroid = builder.string_build(code, __name__, __file__)
+ stmts = astroid['run2'].lookup('Frobbel')[1]
self.assertEqual(len(stmts), 0)
- stmts = astng['run1'].lookup('Frobbel')[1]
+ stmts = astroid['run1'].lookup('Frobbel')[1]
self.assertEqual(len(stmts), 0)
if __name__ == '__main__':
diff --git a/test/unittest_manager.py b/test/unittest_manager.py
index cc1cb60..7059f34 100644
--- a/test/unittest_manager.py
+++ b/test/unittest_manager.py
@@ -1,76 +1,76 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
from logilab.common.testlib import TestCase, unittest_main
import sys
from os.path import join, abspath, dirname
-from logilab.astng.manager import ASTNGManager, _silent_no_wrap
-from logilab.astng.bases import BUILTINS
+from astroid.manager import AstroidManager, _silent_no_wrap
+from astroid.bases import BUILTINS
DATA = join(dirname(abspath(__file__)), 'data')
-class ASTNGManagerTC(TestCase):
+class AstroidManagerTC(TestCase):
def setUp(self):
- self.manager = ASTNGManager()
- self.manager.astng_cache.clear()
+ self.manager = AstroidManager()
+ self.manager.astroid_cache.clear()
- def test_astng_from_module(self):
+ def test_astroid_from_module(self):
import unittest
- astng = self.manager.astng_from_module(unittest)
- self.assertEqual(astng.pure_python, True)
+ astroid = self.manager.astroid_from_module(unittest)
+ self.assertEqual(astroid.pure_python, True)
import time
- astng = self.manager.astng_from_module(time)
- self.assertEqual(astng.pure_python, False)
+ astroid = self.manager.astroid_from_module(time)
+ self.assertEqual(astroid.pure_python, False)
- def test_astng_from_class(self):
- astng = self.manager.astng_from_class(int)
- self.assertEqual(astng.name, 'int')
- self.assertEqual(astng.parent.frame().name, BUILTINS)
+ def test_astroid_from_class(self):
+ astroid = self.manager.astroid_from_class(int)
+ self.assertEqual(astroid.name, 'int')
+ self.assertEqual(astroid.parent.frame().name, BUILTINS)
- astng = self.manager.astng_from_class(object)
- self.assertEqual(astng.name, 'object')
- self.assertEqual(astng.parent.frame().name, BUILTINS)
- self.assertIn('__setattr__', astng)
+ astroid = self.manager.astroid_from_class(object)
+ self.assertEqual(astroid.name, 'object')
+ self.assertEqual(astroid.parent.frame().name, BUILTINS)
+ self.assertIn('__setattr__', astroid)
- def _test_astng_from_zip(self, archive):
+ def _test_astroid_from_zip(self, archive):
origpath = sys.path[:]
sys.modules.pop('mypypa', None)
archive_path = join(DATA, archive)
sys.path.insert(0, archive_path)
try:
- module = self.manager.astng_from_module_name('mypypa')
+ module = self.manager.astroid_from_module_name('mypypa')
self.assertEqual(module.name, 'mypypa')
self.assertTrue(module.file.endswith('%s/mypypa' % archive),
module.file)
finally:
# remove the module, else after importing egg, we don't get the zip
- if 'mypypa' in self.manager.astng_cache:
- del self.manager.astng_cache['mypypa']
+ if 'mypypa' in self.manager.astroid_cache:
+ del self.manager.astroid_cache['mypypa']
del self.manager._mod_file_cache[('mypypa', None)]
if archive_path in sys.path_importer_cache:
del sys.path_importer_cache[archive_path]
sys.path = origpath
- def test_astng_from_module_name_egg(self):
- self._test_astng_from_zip('MyPyPa-0.1.0-py2.5.egg')
+ def test_astroid_from_module_name_egg(self):
+ self._test_astroid_from_zip('MyPyPa-0.1.0-py2.5.egg')
- def test_astng_from_module_name_zip(self):
- self._test_astng_from_zip('MyPyPa-0.1.0-py2.5.zip')
+ def test_astroid_from_module_name_zip(self):
+ self._test_astroid_from_zip('MyPyPa-0.1.0-py2.5.zip')
def test_from_directory(self):
obj = self.manager.project_from_files([DATA], _silent_no_wrap, 'data')
@@ -89,21 +89,21 @@ class ASTNGManagerTC(TestCase):
self.assertListEqual(sorted(k for k in obj.keys()), expected)
def test_do_not_expose_main(self):
- obj = self.manager.astng_from_module_name('__main__')
+ obj = self.manager.astroid_from_module_name('__main__')
self.assertEqual(obj.name, '__main__')
self.assertEqual(obj.items(), [])
-class BorgASTNGManagerTC(TestCase):
+class BorgAstroidManagerTC(TestCase):
def test_borg(self):
- """test that the ASTNGManager is really a borg, i.e. that two different
+ """test that the AstroidManager is really a borg, i.e. that two different
instances has same cache"""
- first_manager = ASTNGManager()
- built = first_manager.astng_from_module_name(BUILTINS)
+ first_manager = AstroidManager()
+ built = first_manager.astroid_from_module_name(BUILTINS)
- second_manager = ASTNGManager()
- second_built = first_manager.astng_from_module_name(BUILTINS)
+ second_manager = AstroidManager()
+ second_built = first_manager.astroid_from_module_name(BUILTINS)
self.assertIs(built, second_built)
diff --git a/test/unittest_nodes.py b/test/unittest_nodes.py
index a47c55f..14813bb 100644
--- a/test/unittest_nodes.py
+++ b/test/unittest_nodes.py
@@ -1,29 +1,29 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""tests for specific behaviour of astng nodes
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""tests for specific behaviour of astroid nodes
"""
import sys
from logilab.common import testlib
-from logilab.astng.node_classes import unpack_infer
-from logilab.astng.bases import BUILTINS, YES, InferenceContext
-from logilab.astng.exceptions import ASTNGBuildingException, NotFoundError
-from logilab.astng import builder, nodes
+from astroid.node_classes import unpack_infer
+from astroid.bases import BUILTINS, YES, InferenceContext
+from astroid.exceptions import AstroidBuildingException, NotFoundError
+from astroid import builder, nodes
from data import module as test_module
@@ -31,7 +31,7 @@ from os.path import join, abspath, dirname
DATA = join(dirname(abspath(__file__)), 'data')
-abuilder = builder.ASTNGBuilder()
+abuilder = builder.AstroidBuilder()
class AsString(testlib.TestCase):
@@ -89,13 +89,13 @@ class _NodeTC(testlib.TestCase):
"""test transformation of If Node"""
CODE = None
@property
- def astng(self):
+ def astroid(self):
try:
- return self.__class__.__dict__['CODE_ASTNG']
+ return self.__class__.__dict__['CODE_Astroid']
except KeyError:
- astng = abuilder.string_build(self.CODE)
- self.__class__.CODE_ASTNG = astng
- return astng
+ astroid = abuilder.string_build(self.CODE)
+ self.__class__.CODE_Astroid = astroid
+ return astroid
class IfNodeTC(_NodeTC):
@@ -126,22 +126,22 @@ else:
def test_if_elif_else_node(self):
"""test transformation for If node"""
- self.assertEqual(len(self.astng.body), 4)
- for stmt in self.astng.body:
+ self.assertEqual(len(self.astroid.body), 4)
+ for stmt in self.astroid.body:
self.assertIsInstance( stmt, nodes.If)
- self.assertFalse(self.astng.body[0].orelse) # simple If
- self.assertIsInstance(self.astng.body[1].orelse[0], nodes.Pass) # If / else
- self.assertIsInstance(self.astng.body[2].orelse[0], nodes.If) # If / elif
- self.assertIsInstance(self.astng.body[3].orelse[0].orelse[0], nodes.If)
+ self.assertFalse(self.astroid.body[0].orelse) # simple If
+ self.assertIsInstance(self.astroid.body[1].orelse[0], nodes.Pass) # If / else
+ self.assertIsInstance(self.astroid.body[2].orelse[0], nodes.If) # If / elif
+ self.assertIsInstance(self.astroid.body[3].orelse[0].orelse[0], nodes.If)
def test_block_range(self):
# XXX ensure expected values
- self.assertEqual(self.astng.block_range(1), (0, 22))
- self.assertEqual(self.astng.block_range(10), (0, 22)) # XXX (10, 22) ?
- self.assertEqual(self.astng.body[1].block_range(5), (5, 6))
- self.assertEqual(self.astng.body[1].block_range(6), (6, 6))
- self.assertEqual(self.astng.body[1].orelse[0].block_range(7), (7, 8))
- self.assertEqual(self.astng.body[1].orelse[0].block_range(8), (8, 8))
+ self.assertEqual(self.astroid.block_range(1), (0, 22))
+ self.assertEqual(self.astroid.block_range(10), (0, 22)) # XXX (10, 22) ?
+ self.assertEqual(self.astroid.body[1].block_range(5), (5, 6))
+ self.assertEqual(self.astroid.body[1].block_range(6), (6, 6))
+ self.assertEqual(self.astroid.body[1].orelse[0].block_range(7), (7, 8))
+ self.assertEqual(self.astroid.body[1].orelse[0].block_range(8), (8, 8))
class TryExceptNodeTC(_NodeTC):
@@ -157,14 +157,14 @@ else:
"""
def test_block_range(self):
# XXX ensure expected values
- self.assertEqual(self.astng.body[0].block_range(1), (1, 8))
- self.assertEqual(self.astng.body[0].block_range(2), (2, 2))
- self.assertEqual(self.astng.body[0].block_range(3), (3, 8))
- self.assertEqual(self.astng.body[0].block_range(4), (4, 4))
- self.assertEqual(self.astng.body[0].block_range(5), (5, 5))
- self.assertEqual(self.astng.body[0].block_range(6), (6, 6))
- self.assertEqual(self.astng.body[0].block_range(7), (7, 7))
- self.assertEqual(self.astng.body[0].block_range(8), (8, 8))
+ self.assertEqual(self.astroid.body[0].block_range(1), (1, 8))
+ self.assertEqual(self.astroid.body[0].block_range(2), (2, 2))
+ self.assertEqual(self.astroid.body[0].block_range(3), (3, 8))
+ self.assertEqual(self.astroid.body[0].block_range(4), (4, 4))
+ self.assertEqual(self.astroid.body[0].block_range(5), (5, 5))
+ self.assertEqual(self.astroid.body[0].block_range(6), (6, 6))
+ self.assertEqual(self.astroid.body[0].block_range(7), (7, 7))
+ self.assertEqual(self.astroid.body[0].block_range(8), (8, 8))
class TryFinallyNodeTC(_NodeTC):
@@ -176,10 +176,10 @@ finally:
"""
def test_block_range(self):
# XXX ensure expected values
- self.assertEqual(self.astng.body[0].block_range(1), (1, 4))
- self.assertEqual(self.astng.body[0].block_range(2), (2, 2))
- self.assertEqual(self.astng.body[0].block_range(3), (3, 4))
- self.assertEqual(self.astng.body[0].block_range(4), (4, 4))
+ self.assertEqual(self.astroid.body[0].block_range(1), (1, 4))
+ self.assertEqual(self.astroid.body[0].block_range(2), (2, 2))
+ self.assertEqual(self.astroid.body[0].block_range(3), (3, 4))
+ self.assertEqual(self.astroid.body[0].block_range(4), (4, 4))
class TryFinally25NodeTC(_NodeTC):
@@ -193,12 +193,12 @@ finally:
"""
def test_block_range(self):
# XXX ensure expected values
- self.assertEqual(self.astng.body[0].block_range(1), (1, 6))
- self.assertEqual(self.astng.body[0].block_range(2), (2, 2))
- self.assertEqual(self.astng.body[0].block_range(3), (3, 4))
- self.assertEqual(self.astng.body[0].block_range(4), (4, 4))
- self.assertEqual(self.astng.body[0].block_range(5), (5, 5))
- self.assertEqual(self.astng.body[0].block_range(6), (6, 6))
+ self.assertEqual(self.astroid.body[0].block_range(1), (1, 6))
+ self.assertEqual(self.astroid.body[0].block_range(2), (2, 2))
+ self.assertEqual(self.astroid.body[0].block_range(3), (3, 4))
+ self.assertEqual(self.astroid.body[0].block_range(4), (4, 4))
+ self.assertEqual(self.astroid.body[0].block_range(5), (5, 5))
+ self.assertEqual(self.astroid.body[0].block_range(6), (6, 6))
class TryExcept2xNodeTC(_NodeTC):
@@ -211,7 +211,7 @@ except AttributeError, (retval, desc):
def test_tuple_attribute(self):
if sys.version_info >= (3, 0):
self.skipTest('syntax removed from py3.x')
- handler = self.astng.body[0].handlers[0]
+ handler = self.astroid.body[0].handlers[0]
self.assertIsInstance(handler.name, nodes.Tuple)
@@ -287,20 +287,20 @@ except PickleError:
pass
'''
- astng = abuilder.string_build(code)
- from_node = astng.body[1].handlers[0].body[0]
- handler_type = astng.body[1].handlers[0].type
+ astroid = abuilder.string_build(code)
+ from_node = astroid.body[1].handlers[0].body[0]
+ handler_type = astroid.body[1].handlers[0].type
excs = list(unpack_infer(handler_type))
def test_absolute_import(self):
- astng = abuilder.file_build(self.datapath('absimport.py'))
+ astroid = abuilder.file_build(self.datapath('absimport.py'))
ctx = InferenceContext()
ctx.lookupname = 'message'
# will fail if absolute import failed
- astng['message'].infer(ctx).next()
+ astroid['message'].infer(ctx).next()
ctx.lookupname = 'email'
- m = astng['email'].infer(ctx).next()
+ m = astroid['email'].infer(ctx).next()
self.assertFalse(m.file.startswith(self.datapath('email.py')))
@@ -351,7 +351,7 @@ def hello(False):
del True
"""
if sys.version_info >= (3, 0):
- self.assertRaises(SyntaxError,#might become ASTNGBuildingException
+ self.assertRaises(SyntaxError,#might become AstroidBuildingException
abuilder.string_build, code)
else:
ast = abuilder.string_build(code)
diff --git a/test/unittest_python3.py b/test/unittest_python3.py
index 9edf0ca..84650fc 100644
--- a/test/unittest_python3.py
+++ b/test/unittest_python3.py
@@ -1,41 +1,41 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
import sys
from logilab.common.testlib import TestCase, unittest_main, require_version
-from logilab.astng.node_classes import Assign
-from logilab.astng.manager import ASTNGManager
-from logilab.astng.builder import ASTNGBuilder
+from astroid.node_classes import Assign
+from astroid.manager import AstroidManager
+from astroid.builder import AstroidBuilder
class Python3TC(TestCase):
def setUp(self):
- self.manager = ASTNGManager()
- self.builder = ASTNGBuilder(self.manager)
- self.manager.astng_cache.clear()
+ self.manager = AstroidManager()
+ self.builder = AstroidBuilder(self.manager)
+ self.manager.astroid_cache.clear()
@require_version('3.0')
def test_starred_notation(self):
- astng = self.builder.string_build("*a, b = [1, 2, 3]", 'test', 'test')
+ astroid = self.builder.string_build("*a, b = [1, 2, 3]", 'test', 'test')
# Get the star node
- node = next(next(next(astng.get_children()).get_children()).get_children())
+ node = next(next(next(astroid.get_children()).get_children()).get_children())
self.assertTrue(isinstance(node.ass_type(), Assign))
diff --git a/test/unittest_regrtest.py b/test/unittest_regrtest.py
index d967c98..5cc114e 100644
--- a/test/unittest_regrtest.py
+++ b/test/unittest_regrtest.py
@@ -1,27 +1,27 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
from logilab.common.testlib import unittest_main, TestCase
-from logilab.astng import ResolveError, MANAGER, Instance, nodes, YES, InferenceError
-from logilab.astng.builder import ASTNGBuilder
-from logilab.astng.raw_building import build_module
-from logilab.astng.manager import ASTNGManager
+from astroid import ResolveError, MANAGER, Instance, nodes, YES, InferenceError
+from astroid.builder import AstroidBuilder
+from astroid.raw_building import build_module
+from astroid.manager import AstroidManager
import sys
from os.path import join, abspath, dirname
@@ -35,18 +35,18 @@ class NonRegressionTC(TestCase):
sys.path.pop(0)
def brainless_manager(self):
- manager = ASTNGManager()
- # avoid caching into the ASTNGManager borg since we get problems
+ manager = AstroidManager()
+ # avoid caching into the AstroidManager borg since we get problems
# with other tests :
manager.__dict__ = {}
- manager.astng_cache = {}
+ manager.astroid_cache = {}
manager._mod_file_cache = {}
manager.transformers = {}
return manager
def test_module_path(self):
man = self.brainless_manager()
- mod = man.astng_from_module_name('package.import_package_subpackage_module')
+ mod = man.astroid_from_module_name('package.import_package_subpackage_module')
package = mod.igetattr('package').next()
self.assertEqual(package.name, 'package')
subpackage = package.igetattr('subpackage').next()
@@ -59,8 +59,8 @@ class NonRegressionTC(TestCase):
def test_package_sidepackage(self):
manager = self.brainless_manager()
- assert 'package.sidepackage' not in MANAGER.astng_cache
- package = manager.astng_from_module_name('absimp')
+ assert 'package.sidepackage' not in MANAGER.astroid_cache
+ package = manager.astroid_from_module_name('absimp')
self.assertIsInstance(package, nodes.Module)
self.assertTrue(package.package)
subpackage = package.getattr('sidepackage')[0].infer().next()
@@ -70,7 +70,7 @@ class NonRegressionTC(TestCase):
def test_living_property(self):
- builder = ASTNGBuilder()
+ builder = AstroidBuilder()
builder._done = {}
builder._module = sys.modules[__name__]
builder.object_build(build_module('module_name', ''), Whatever)
@@ -83,7 +83,7 @@ class NonRegressionTC(TestCase):
self.skipTest('test skipped: pygtk is not available')
# XXX may fail on some pygtk version, because objects in
# gobject._gobject have __module__ set to gobject :(
- builder = ASTNGBuilder()
+ builder = AstroidBuilder()
data = """
import pygtk
pygtk.require("2.6")
@@ -92,8 +92,8 @@ import gobject
class A(gobject.GObject):
pass
"""
- astng = builder.string_build(data, __name__, __file__)
- a = astng['A']
+ astroid = builder.string_build(data, __name__, __file__)
+ a = astroid['A']
self.assertTrue(a.newstyle)
@@ -102,7 +102,7 @@ class A(gobject.GObject):
from pylint import lint
except ImportError:
self.skipTest('pylint not available')
- mod = MANAGER.astng_from_module_name('pylint.lint')
+ mod = MANAGER.astroid_from_module_name('pylint.lint')
pylinter = mod['PyLinter']
expect = ['OptionsManagerMixIn', 'object', 'MessagesHandlerMixIn',
'ReportsHandlerMixIn', 'BaseTokenChecker', 'BaseChecker',
@@ -123,14 +123,14 @@ class A(gobject.GObject):
import numpy
except ImportError:
self.skipTest('test skipped: numpy is not available')
- builder = ASTNGBuilder()
+ builder = AstroidBuilder()
data = """
from numpy import multiply
multiply(1, 2, 3)
"""
- astng = builder.string_build(data, __name__, __file__)
- callfunc = astng.body[1].value.func
+ astroid = builder.string_build(data, __name__, __file__)
+ callfunc = astroid.body[1].value.func
infered = callfunc.infered()
self.assertEqual(len(infered), 1)
self.assertIsInstance(infered[0], Instance)
diff --git a/test/unittest_scoped_nodes.py b/test/unittest_scoped_nodes.py
index 7b1222b..c924907 100644
--- a/test/unittest_scoped_nodes.py
+++ b/test/unittest_scoped_nodes.py
@@ -1,21 +1,21 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
-"""tests for specific behaviour of astng scoped nodes (i.e. module, class and
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
+"""tests for specific behaviour of astroid scoped nodes (i.e. module, class and
function)
"""
@@ -24,11 +24,11 @@ from os.path import join, abspath, dirname
from logilab.common.testlib import TestCase, unittest_main
-from logilab.astng import builder, nodes, scoped_nodes, \
+from astroid import builder, nodes, scoped_nodes, \
InferenceError, NotFoundError, NoDefault
-from logilab.astng.bases import BUILTINS, Instance, BoundMethod, UnboundMethod
+from astroid.bases import BUILTINS, Instance, BoundMethod, UnboundMethod
-abuilder = builder.ASTNGBuilder()
+abuilder = builder.AstroidBuilder()
DATA = join(dirname(abspath(__file__)), 'data')
REGRTEST_DATA = join(dirname(abspath(__file__)), 'regrtest_data')
MODULE = abuilder.file_build(join(DATA, 'module.py'), 'data.module')
@@ -54,7 +54,7 @@ class ModuleNodeTC(TestCase):
self.assertEqual(MODULE.getattr('__name__')[0].value, 'data.module')
self.assertEqual(len(MODULE.getattr('__doc__')), 1)
self.assertIsInstance(MODULE.getattr('__doc__')[0], nodes.Const)
- self.assertEqual(MODULE.getattr('__doc__')[0].value, 'test module for astng\n')
+ self.assertEqual(MODULE.getattr('__doc__')[0].value, 'test module for astroid\n')
self.assertEqual(len(MODULE.getattr('__file__')), 1)
self.assertIsInstance(MODULE.getattr('__file__')[0], nodes.Const)
self.assertEqual(MODULE.getattr('__file__')[0].value, join(DATA, 'module.py'))
@@ -106,10 +106,10 @@ appli = application
appli += 2
del appli
'''
- astng = abuilder.string_build(data, __name__, __file__)
+ astroid = abuilder.string_build(data, __name__, __file__)
# test del statement not returned by getattr
- self.assertEqual(len(astng.getattr('appli')), 2,
- astng.getattr('appli'))
+ self.assertEqual(len(astroid.getattr('appli')), 2,
+ astroid.getattr('appli'))
def test_relative_to_absolute_name(self):
# package
@@ -137,12 +137,12 @@ del appli
def test_import_1(self):
data = '''from . import subpackage'''
- astng = abuilder.string_build(data, 'package', join(REGRTEST_DATA, 'package', '__init__.py'))
+ astroid = abuilder.string_build(data, 'package', join(REGRTEST_DATA, 'package', '__init__.py'))
sys.path.insert(1, REGRTEST_DATA)
try:
- m = astng.import_module('', level=1)
+ m = astroid.import_module('', level=1)
self.assertEqual(m.name, 'package')
- infered = list(astng.igetattr('subpackage'))
+ infered = list(astroid.igetattr('subpackage'))
self.assertEqual(len(infered), 1)
self.assertEqual(infered[0].name, 'package.subpackage')
finally:
@@ -151,12 +151,12 @@ del appli
def test_import_2(self):
data = '''from . import subpackage as pouet'''
- astng = abuilder.string_build(data, 'package', join(dirname(abspath(__file__)), 'regrtest_data', 'package', '__init__.py'))
+ astroid = abuilder.string_build(data, 'package', join(dirname(abspath(__file__)), 'regrtest_data', 'package', '__init__.py'))
sys.path.insert(1, REGRTEST_DATA)
try:
- m = astng.import_module('', level=1)
+ m = astroid.import_module('', level=1)
self.assertEqual(m.name, 'package')
- infered = list(astng.igetattr('pouet'))
+ infered = list(astroid.igetattr('pouet'))
self.assertEqual(len(infered), 1)
self.assertEqual(infered[0].name, 'package.subpackage')
finally:
@@ -264,15 +264,15 @@ def nested_args(a, (b, c, d)):
def f():
g = lambda: None
'''
- astng = abuilder.string_build(data, __name__, __file__)
- g = list(astng['f'].ilookup('g'))[0]
+ astroid = abuilder.string_build(data, __name__, __file__)
+ g = list(astroid['f'].ilookup('g'))[0]
self.assertEqual(g.pytype(), '%s.function' % BUILTINS)
def test_lambda_qname(self):
- astng = abuilder.string_build('''
+ astroid = abuilder.string_build('''
lmbd = lambda: None
''', __name__, __file__)
- self.assertEqual('%s.<lambda>' % __name__, astng['lmbd'].parent.value.qname())
+ self.assertEqual('%s.<lambda>' % __name__, astroid['lmbd'].parent.value.qname())
def test_is_method(self):
data = '''
@@ -293,20 +293,20 @@ def function():
def sfunction():
return -1
'''
- astng = abuilder.string_build(data, __name__, __file__)
- self.assertTrue(astng['A']['meth1'].is_method())
- self.assertTrue(astng['A']['meth2'].is_method())
- self.assertTrue(astng['A']['meth3'].is_method())
- self.assertFalse(astng['function'].is_method())
- self.assertFalse(astng['sfunction'].is_method())
+ astroid = abuilder.string_build(data, __name__, __file__)
+ self.assertTrue(astroid['A']['meth1'].is_method())
+ self.assertTrue(astroid['A']['meth2'].is_method())
+ self.assertTrue(astroid['A']['meth3'].is_method())
+ self.assertFalse(astroid['function'].is_method())
+ self.assertFalse(astroid['sfunction'].is_method())
def test_argnames(self):
if sys.version_info < (3, 0):
code = 'def f(a, (b, c), *args, **kwargs): pass'
else:
code = 'def f(a, b, c, *args, **kwargs): pass'
- astng = abuilder.string_build(code, __name__, __file__)
- self.assertEqual(astng['f'].argnames(), ['a', 'b', 'c', 'args', 'kwargs'])
+ astroid = abuilder.string_build(code, __name__, __file__)
+ self.assertEqual(astroid['f'].argnames(), ['a', 'b', 'c', 'args', 'kwargs'])
def test_return_nothing(self):
"""test infered value on a function with empty return"""
@@ -316,8 +316,8 @@ def func():
a = func()
'''
- astng = abuilder.string_build(data, __name__, __file__)
- call = astng.body[1].value
+ astroid = abuilder.string_build(data, __name__, __file__)
+ call = astroid.body[1].value
func_vals = call.infered()
self.assertEqual(len(func_vals), 1)
self.assertIsInstance(func_vals[0], nodes.Const)
@@ -332,8 +332,8 @@ def test():
test.bar = 1
test()
"""
- astng = abuilder.string_build(data, 'mod', __file__)
- func = astng.body[2].value.func.infered()[0]
+ astroid = abuilder.string_build(data, 'mod', __file__)
+ func = astroid.body[2].value.func.infered()[0]
self.assertIsInstance(func, nodes.Function)
self.assertEqual(func.name, 'test')
one = func.getattr('bar')[0].infered()[0]
@@ -370,15 +370,15 @@ class ClassNodeTC(TestCase):
self.assertEqual(len(cls.getattr('__mro__')), 1)
def test_cls_special_attributes_2(self):
- astng = abuilder.string_build('''
+ astroid = abuilder.string_build('''
class A: pass
class B: pass
A.__bases__ += (B,)
''', __name__, __file__)
- self.assertEqual(len(astng['A'].getattr('__bases__')), 2)
- self.assertIsInstance(astng['A'].getattr('__bases__')[0], nodes.Tuple)
- self.assertIsInstance(astng['A'].getattr('__bases__')[1], nodes.AssAttr)
+ self.assertEqual(len(astroid['A'].getattr('__bases__')), 2)
+ self.assertIsInstance(astroid['A'].getattr('__bases__')[0], nodes.Tuple)
+ self.assertIsInstance(astroid['A'].getattr('__bases__')[1], nodes.AssAttr)
def test_instance_special_attributes(self):
for inst in (Instance(MODULE['YO']), nodes.List(), nodes.Const(1)):
@@ -479,7 +479,7 @@ A.__bases__ += (B,)
interfaces)
def test_concat_interfaces(self):
- astng = abuilder.string_build('''
+ astroid = abuilder.string_build('''
class IMachin: pass
class Correct2:
@@ -495,7 +495,7 @@ class InterfaceCanNowBeFound:
__implements__ = BadArgument.__implements__ + Correct2.__implements__
''')
- self.assertEqual([i.name for i in astng['InterfaceCanNowBeFound'].interfaces()],
+ self.assertEqual([i.name for i in astroid['InterfaceCanNowBeFound'].interfaces()],
['IMachin'])
def test_inner_classes(self):
@@ -513,8 +513,8 @@ class WebAppObject(object):
return cls
registered = classmethod(registered)
'''
- astng = abuilder.string_build(data, __name__, __file__)
- cls = astng['WebAppObject']
+ astroid = abuilder.string_build(data, __name__, __file__)
+ cls = astroid['WebAppObject']
self.assertEqual(sorted(cls.locals.keys()),
['appli', 'config', 'registered', 'schema'])
@@ -526,8 +526,8 @@ class WebAppObject(object):
appli += 2
del self.appli
'''
- astng = abuilder.string_build(data, __name__, __file__)
- cls = astng['WebAppObject']
+ astroid = abuilder.string_build(data, __name__, __file__)
+ cls = astroid['WebAppObject']
# test del statement not returned by getattr
self.assertEqual(len(cls.getattr('appli')), 2)
@@ -540,8 +540,8 @@ class WebAppObject(object):
self.appli += 2
del self.appli
'''
- astng = abuilder.string_build(data, __name__, __file__)
- inst = Instance(astng['WebAppObject'])
+ astroid = abuilder.string_build(data, __name__, __file__)
+ inst = Instance(astroid['WebAppObject'])
# test del statement not returned by getattr
self.assertEqual(len(inst.getattr('appli')), 2)
@@ -564,8 +564,8 @@ class Klass(Parent):
val = self.bb
self.aa += val
'''
- astng = abuilder.string_build(data, __name__, __file__)
- inst = Instance(astng['Klass'])
+ astroid = abuilder.string_build(data, __name__, __file__)
+ inst = Instance(astroid['Klass'])
self.assertEqual(len(inst.getattr('aa')), 3, inst.getattr('aa'))
self.assertEqual(len(inst.getattr('bb')), 1, inst.getattr('bb'))
self.assertEqual(len(inst.getattr('cc')), 2, inst.getattr('cc'))
@@ -587,8 +587,8 @@ Clazz.m3 = func
inst = Clazz()
inst.m4 = func
'''
- astng = abuilder.string_build(data, __name__, __file__)
- cls = astng['Clazz']
+ astroid = abuilder.string_build(data, __name__, __file__)
+ cls = astroid['Clazz']
# test del statement not returned by getattr
for method in ('m1', 'm2', 'm3'):
inferred = list(cls.igetattr(method))
@@ -612,8 +612,8 @@ class Present(Future):
class Past(Present):
pass
'''
- astng = abuilder.string_build(data)
- past = astng['Past']
+ astroid = abuilder.string_build(data)
+ past = astroid['Past']
attr = past.getattr('attr')
self.assertEqual(len(attr), 1)
attr1 = attr[0]
@@ -632,11 +632,11 @@ def g1(x):
def g2():
pass
'''
- astng = abuilder.string_build(data)
- self.assertEqual(astng['g1'].fromlineno, 4)
- self.assertEqual(astng['g1'].tolineno, 5)
- self.assertEqual(astng['g2'].fromlineno, 9)
- self.assertEqual(astng['g2'].tolineno, 10)
+ astroid = abuilder.string_build(data)
+ self.assertEqual(astroid['g1'].fromlineno, 4)
+ self.assertEqual(astroid['g1'].tolineno, 5)
+ self.assertEqual(astroid['g2'].fromlineno, 9)
+ self.assertEqual(astroid['g2'].tolineno, 10)
__all__ = ('ModuleNodeTC', 'ImportNodeTC', 'FunctionNodeTC', 'ClassNodeTC')
diff --git a/test/unittest_utils.py b/test/unittest_utils.py
index 0f06253..fddbc5a 100644
--- a/test/unittest_utils.py
+++ b/test/unittest_utils.py
@@ -1,30 +1,30 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
from logilab.common.testlib import TestCase, unittest_main
-from logilab.astng import builder, nodes
-from logilab.astng.node_classes import are_exclusive
+from astroid import builder, nodes
+from astroid.node_classes import are_exclusive
-builder = builder.ASTNGBuilder()
+builder = builder.AstroidBuilder()
class AreExclusiveTC(TestCase):
def test_not_exclusive(self):
- astng = builder.string_build("""
+ astroid = builder.string_build("""
x = 10
for x in range(5):
print (x)
@@ -32,16 +32,16 @@ for x in range(5):
if x > 0:
print ('#' * x)
""", __name__, __file__)
- xass1 = astng.locals['x'][0]
+ xass1 = astroid.locals['x'][0]
assert xass1.lineno == 2
- xnames = [n for n in astng.nodes_of_class(nodes.Name) if n.name == 'x']
+ xnames = [n for n in astroid.nodes_of_class(nodes.Name) if n.name == 'x']
assert len(xnames) == 3
assert xnames[1].lineno == 6
self.assertEqual(are_exclusive(xass1, xnames[1]), False)
self.assertEqual(are_exclusive(xass1, xnames[2]), False)
def test_if(self):
- astng = builder.string_build('''
+ astroid = builder.string_build('''
if 1:
a = 1
@@ -53,12 +53,12 @@ else:
a = 3
a = 4
''')
- a1 = astng.locals['a'][0]
- a2 = astng.locals['a'][1]
- a3 = astng.locals['a'][2]
- a4 = astng.locals['a'][3]
- a5 = astng.locals['a'][4]
- a6 = astng.locals['a'][5]
+ a1 = astroid.locals['a'][0]
+ a2 = astroid.locals['a'][1]
+ a3 = astroid.locals['a'][2]
+ a4 = astroid.locals['a'][3]
+ a5 = astroid.locals['a'][4]
+ a6 = astroid.locals['a'][5]
self.assertEqual(are_exclusive(a1, a2), False)
self.assertEqual(are_exclusive(a1, a3), True)
self.assertEqual(are_exclusive(a1, a5), True)
@@ -67,7 +67,7 @@ else:
self.assertEqual(are_exclusive(a5, a6), False)
def test_try_except(self):
- astng = builder.string_build('''
+ astroid = builder.string_build('''
try:
def exclusive_func2():
"docstring"
@@ -82,10 +82,10 @@ else:
"this one redefine the one defined line 42"
''')
- f1 = astng.locals['exclusive_func2'][0]
- f2 = astng.locals['exclusive_func2'][1]
- f3 = astng.locals['exclusive_func2'][2]
- f4 = astng.locals['exclusive_func2'][3]
+ f1 = astroid.locals['exclusive_func2'][0]
+ f2 = astroid.locals['exclusive_func2'][1]
+ f3 = astroid.locals['exclusive_func2'][2]
+ f4 = astroid.locals['exclusive_func2'][3]
self.assertEqual(are_exclusive(f1, f2), True)
self.assertEqual(are_exclusive(f1, f3), True)
self.assertEqual(are_exclusive(f1, f4), False)
diff --git a/utils.py b/utils.py
index 7c6f7ea..1cd0e77 100644
--- a/utils.py
+++ b/utils.py
@@ -1,28 +1,28 @@
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
-# This file is part of logilab-astng.
+# This file is part of astroid.
#
-# logilab-astng is free software: you can redistribute it and/or modify it
+# astroid is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# logilab-astng is distributed in the hope that it will be useful, but
+# astroid is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
+# with astroid. If not, see <http://www.gnu.org/licenses/>.
"""this module contains some utilities to navigate in the tree or to
extract information from it
"""
__docformat__ = "restructuredtext en"
-from logilab.astng.exceptions import ASTNGBuildingException
-from logilab.astng.builder import parse
+from astroid.exceptions import AstroidBuildingException
+from astroid.builder import parse
class ASTWalker:
@@ -123,12 +123,12 @@ def _check_children(node):
if not ok:
print "lines;", node.lineno, child.lineno
print "of module", node.root(), node.root().name
- raise ASTNGBuildingException
+ raise AstroidBuildingException
_check_children(child)
class TreeTester(object):
- '''A helper class to see _ast tree and compare with astng tree
+ '''A helper class to see _ast tree and compare with astroid tree
indent: string for tree indent representation
lineno: bool to tell if we should print the line numbers
@@ -141,7 +141,7 @@ class TreeTester(object):
. <Print>
. . nl = True
. ]
- >>> print tester.astng_tree_repr()
+ >>> print tester.astroid_tree_repr()
Module()
body = [
Print()
@@ -219,16 +219,16 @@ class TreeTester(object):
self._string += '\n' + indent + field + " = " + repr(attr)
- def build_astng_tree(self):
- """build astng tree from the _ast tree
+ def build_astroid_tree(self):
+ """build astroid tree from the _ast tree
"""
- from logilab.astng.builder import ASTNGBuilder
- tree = ASTNGBuilder().string_build(self.sourcecode)
+ from astroid.builder import AstroidBuilder
+ tree = AstroidBuilder().string_build(self.sourcecode)
return tree
- def astng_tree_repr(self, ids=False):
- """build the astng tree and return a nice tree representation"""
- mod = self.build_astng_tree()
+ def astroid_tree_repr(self, ids=False):
+ """build the astroid tree and return a nice tree representation"""
+ mod = self.build_astroid_tree()
return mod.repr_tree(ids)