diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-07-24 08:52:20 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-07-24 08:52:20 +0200 |
commit | 492a32dc8743e43c9dd2db0ede8d1dc311555258 (patch) | |
tree | 489c28b1285a78557d2073a8fe74e3a140981b4d | |
parent | fe795a18c6c9b0e743d3f8acc614fa61e36d33bb (diff) | |
download | astroid-492a32dc8743e43c9dd2db0ede8d1dc311555258.tar.gz |
rename all astroid_from* method, introduced by sed, into ast_from*
-rw-r--r-- | inference.py | 2 | ||||
-rw-r--r-- | manager.py | 26 | ||||
-rw-r--r-- | scoped_nodes.py | 6 | ||||
-rw-r--r-- | test/unittest_builder.py | 6 | ||||
-rw-r--r-- | test/unittest_manager.py | 30 | ||||
-rw-r--r-- | test/unittest_regrtest.py | 6 |
6 files changed, 38 insertions, 38 deletions
diff --git a/inference.py b/inference.py index ce6dd6c..29c97be 100644 --- a/inference.py +++ b/inference.py @@ -375,7 +375,7 @@ def infer_empty_node(self, context=None): yield YES else: try: - for infered in MANAGER.infer_astroid_from_something(self.object, + for infered in MANAGER.infer_ast_from_something(self.object, context=context): yield infered except AstroidError: @@ -85,7 +85,7 @@ class AstroidManager(OptionsProviderMixIn): self._mod_file_cache = {} self.transforms = {} - def astroid_from_file(self, filepath, modname=None, fallback=True, source=False): + def ast_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) @@ -103,11 +103,11 @@ class AstroidManager(OptionsProviderMixIn): from astroid.builder import AstroidBuilder return AstroidBuilder(self).file_build(filepath, modname) elif fallback and modname: - return self.astroid_from_module_name(modname) + return self.ast_from_module_name(modname) raise AstroidBuildingException('unable to get astroid for file %s' % filepath) - def astroid_from_module_name(self, modname, context_file=None): + def ast_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] @@ -129,8 +129,8 @@ class AstroidManager(OptionsProviderMixIn): except Exception, ex: msg = 'Unable to load module %s (%s)' % (modname, ex) raise AstroidBuildingException(msg) - return self.astroid_from_module(module, modname) - return self.astroid_from_file(filepath, modname, fallback=False) + return self.ast_from_module(module, modname) + return self.ast_from_file(filepath, modname, fallback=False) finally: os.chdir(old_cwd) @@ -171,7 +171,7 @@ class AstroidManager(OptionsProviderMixIn): raise value return value - def astroid_from_module(self, module, modname=None): + def ast_from_module(self, module, modname=None): """given an imported module, return the astroid object""" modname = modname or module.__name__ if modname in self.astroid_cache: @@ -180,13 +180,13 @@ class AstroidManager(OptionsProviderMixIn): # some builtin modules don't have __file__ attribute filepath = module.__file__ if is_python_source(filepath): - return self.astroid_from_file(filepath, modname) + return self.ast_from_file(filepath, modname) except AttributeError: pass from astroid.builder import AstroidBuilder return AstroidBuilder(self).module_build(module, modname) - def astroid_from_class(self, klass, modname=None): + def ast_from_class(self, klass, modname=None): """get astroid for the given class""" if modname is None: try: @@ -194,11 +194,11 @@ class AstroidManager(OptionsProviderMixIn): except AttributeError: raise AstroidBuildingException( 'Unable to get module for class %s' % safe_repr(klass)) - modastroid = self.astroid_from_module_name(modname) + modastroid = self.ast_from_module_name(modname) return modastroid.getattr(klass.__name__)[0] # XXX - def infer_astroid_from_something(self, obj, context=None): + def infer_ast_from_something(self, obj, context=None): """infer astroid for the given class""" if hasattr(obj, '__class__') and not isinstance(obj, type): klass = obj.__class__ @@ -223,7 +223,7 @@ class AstroidManager(OptionsProviderMixIn): 'Unexpected error while retrieving name for %s: %s' % (safe_repr(klass), ex)) # take care, on living object __module__ is regularly wrong :( - modastroid = self.astroid_from_module_name(modname) + modastroid = self.ast_from_module_name(modname) if klass is obj: for infered in modastroid.igetattr(name, context): yield infered @@ -245,7 +245,7 @@ class AstroidManager(OptionsProviderMixIn): fpath = join(something, '__init__.py') else: fpath = something - astroid = func_wrapper(self.astroid_from_file, fpath) + astroid = func_wrapper(self.ast_from_file, fpath) if astroid is None: continue # XXX why is first file defining the project.path ? @@ -257,7 +257,7 @@ class AstroidManager(OptionsProviderMixIn): # recurse on others packages / modules if this is a package for fpath in get_module_files(dirname(astroid.file), black_list): - astroid = func_wrapper(self.astroid_from_file, fpath) + astroid = func_wrapper(self.ast_from_file, fpath) if astroid is None or astroid.name == base_name: continue project.add_module(astroid) diff --git a/scoped_nodes.py b/scoped_nodes.py index 3886b7e..0ee29be 100644 --- a/scoped_nodes.py +++ b/scoped_nodes.py @@ -78,7 +78,7 @@ def builtin_lookup(name): return the list of matching statements and the astroid for the builtin module """ - builtin_astroid = MANAGER.astroid_from_module(builtins) + builtin_astroid = MANAGER.ast_from_module(builtins) if name == '__dict__': return builtin_astroid, () try: @@ -336,13 +336,13 @@ class Module(LocalsDictNodeNG): level = 0 absmodname = self.relative_to_absolute_name(modname, level) try: - return MANAGER.astroid_from_module_name(absmodname) + return MANAGER.ast_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.astroid_from_module_name(modname) + return MANAGER.ast_from_module_name(modname) def relative_to_absolute_name(self, modname, level): """return the absolute module name for a relative import. diff --git a/test/unittest_builder.py b/test/unittest_builder.py index 9932caf..e56f7e8 100644 --- a/test/unittest_builder.py +++ b/test/unittest_builder.py @@ -264,7 +264,7 @@ class BuilderTC(TestCase): def test_inspect_build0(self): """test astroid tree build from a living object""" - builtin_astroid = MANAGER.astroid_from_module_name(BUILTINS) + builtin_astroid = MANAGER.ast_from_module_name(BUILTINS) if sys.version_info < (3, 0): fclass = builtin_astroid['file'] self.assertIn('name', fclass) @@ -298,7 +298,7 @@ class BuilderTC(TestCase): self.assertIsInstance(builtin_astroid['NotImplementedError'], nodes.Class) def test_inspect_build1(self): - time_astroid = MANAGER.astroid_from_module_name('time') + time_astroid = MANAGER.ast_from_module_name('time') self.assertTrue(time_astroid) self.assertEqual(time_astroid['time'].args.defaults, []) @@ -332,7 +332,7 @@ class BuilderTC(TestCase): self.assertIn('filename', container) def test_inspect_build_type_object(self): - builtin_astroid = MANAGER.astroid_from_module_name(BUILTINS) + builtin_astroid = MANAGER.ast_from_module_name(BUILTINS) infered = list(builtin_astroid.igetattr('object')) self.assertEqual(len(infered), 1) diff --git a/test/unittest_manager.py b/test/unittest_manager.py index 7059f34..5711a23 100644 --- a/test/unittest_manager.py +++ b/test/unittest_manager.py @@ -29,31 +29,31 @@ class AstroidManagerTC(TestCase): self.manager = AstroidManager() self.manager.astroid_cache.clear() - def test_astroid_from_module(self): + def test_ast_from_module(self): import unittest - astroid = self.manager.astroid_from_module(unittest) + astroid = self.manager.ast_from_module(unittest) self.assertEqual(astroid.pure_python, True) import time - astroid = self.manager.astroid_from_module(time) + astroid = self.manager.ast_from_module(time) self.assertEqual(astroid.pure_python, False) - def test_astroid_from_class(self): - astroid = self.manager.astroid_from_class(int) + def test_ast_from_class(self): + astroid = self.manager.ast_from_class(int) self.assertEqual(astroid.name, 'int') self.assertEqual(astroid.parent.frame().name, BUILTINS) - astroid = self.manager.astroid_from_class(object) + astroid = self.manager.ast_from_class(object) self.assertEqual(astroid.name, 'object') self.assertEqual(astroid.parent.frame().name, BUILTINS) self.assertIn('__setattr__', astroid) - def _test_astroid_from_zip(self, archive): + def _test_ast_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.astroid_from_module_name('mypypa') + module = self.manager.ast_from_module_name('mypypa') self.assertEqual(module.name, 'mypypa') self.assertTrue(module.file.endswith('%s/mypypa' % archive), module.file) @@ -66,11 +66,11 @@ class AstroidManagerTC(TestCase): del sys.path_importer_cache[archive_path] sys.path = origpath - def test_astroid_from_module_name_egg(self): - self._test_astroid_from_zip('MyPyPa-0.1.0-py2.5.egg') + def test_ast_from_module_name_egg(self): + self._test_ast_from_zip('MyPyPa-0.1.0-py2.5.egg') - def test_astroid_from_module_name_zip(self): - self._test_astroid_from_zip('MyPyPa-0.1.0-py2.5.zip') + def test_ast_from_module_name_zip(self): + self._test_ast_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,7 +89,7 @@ class AstroidManagerTC(TestCase): self.assertListEqual(sorted(k for k in obj.keys()), expected) def test_do_not_expose_main(self): - obj = self.manager.astroid_from_module_name('__main__') + obj = self.manager.ast_from_module_name('__main__') self.assertEqual(obj.name, '__main__') self.assertEqual(obj.items(), []) @@ -100,10 +100,10 @@ class BorgAstroidManagerTC(TestCase): """test that the AstroidManager is really a borg, i.e. that two different instances has same cache""" first_manager = AstroidManager() - built = first_manager.astroid_from_module_name(BUILTINS) + built = first_manager.ast_from_module_name(BUILTINS) second_manager = AstroidManager() - second_built = first_manager.astroid_from_module_name(BUILTINS) + second_built = first_manager.ast_from_module_name(BUILTINS) self.assertIs(built, second_built) diff --git a/test/unittest_regrtest.py b/test/unittest_regrtest.py index b5878bc..5521210 100644 --- a/test/unittest_regrtest.py +++ b/test/unittest_regrtest.py @@ -46,7 +46,7 @@ class NonRegressionTC(TestCase): def test_module_path(self): man = self.brainless_manager() - mod = man.astroid_from_module_name('package.import_package_subpackage_module') + mod = man.ast_from_module_name('package.import_package_subpackage_module') package = mod.igetattr('package').next() self.assertEqual(package.name, 'package') subpackage = package.igetattr('subpackage').next() @@ -60,7 +60,7 @@ class NonRegressionTC(TestCase): def test_package_sidepackage(self): manager = self.brainless_manager() assert 'package.sidepackage' not in MANAGER.astroid_cache - package = manager.astroid_from_module_name('absimp') + package = manager.ast_from_module_name('absimp') self.assertIsInstance(package, nodes.Module) self.assertTrue(package.package) subpackage = package.getattr('sidepackage')[0].infer().next() @@ -102,7 +102,7 @@ class A(gobject.GObject): from pylint import lint except ImportError: self.skipTest('pylint not available') - mod = MANAGER.astroid_from_module_name('pylint.lint') + mod = MANAGER.ast_from_module_name('pylint.lint') pylinter = mod['PyLinter'] expect = ['OptionsManagerMixIn', 'object', 'MessagesHandlerMixIn', 'ReportsHandlerMixIn', 'BaseTokenChecker', 'BaseChecker', |