Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: third_party/logilab/astroid/manager.py

Issue 876793002: pylint: upgrade to 1.4.1 (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. 1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
3 # 3 #
4 # This file is part of astroid. 4 # This file is part of astroid.
5 # 5 #
6 # astroid is free software: you can redistribute it and/or modify it 6 # astroid is free software: you can redistribute it and/or modify it
7 # under the terms of the GNU Lesser General Public License as published by the 7 # under the terms of the GNU Lesser General Public License as published by the
8 # Free Software Foundation, either version 2.1 of the License, or (at your 8 # Free Software Foundation, either version 2.1 of the License, or (at your
9 # option) any later version. 9 # option) any later version.
10 # 10 #
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 old_cwd = os.getcwd() 137 old_cwd = os.getcwd()
138 if context_file: 138 if context_file:
139 os.chdir(dirname(context_file)) 139 os.chdir(dirname(context_file))
140 try: 140 try:
141 filepath, mp_type = self.file_from_module_name(modname, context_file ) 141 filepath, mp_type = self.file_from_module_name(modname, context_file )
142 if mp_type == modutils.PY_ZIPMODULE: 142 if mp_type == modutils.PY_ZIPMODULE:
143 module = self.zip_import_data(filepath) 143 module = self.zip_import_data(filepath)
144 if module is not None: 144 if module is not None:
145 return module 145 return module
146 elif mp_type in (imp.C_BUILTIN, imp.C_EXTENSION): 146 elif mp_type in (imp.C_BUILTIN, imp.C_EXTENSION):
147 if mp_type == imp.C_EXTENSION and not self._can_load_extension(m odname): 147 if mp_type == imp.C_EXTENSION and not self._can_load_extension(m odname):
148 return self._build_stub_module(modname) 148 return self._build_stub_module(modname)
149 try: 149 try:
150 module = modutils.load_module_from_name(modname) 150 module = modutils.load_module_from_name(modname)
151 except Exception as ex: 151 except Exception as ex:
152 msg = 'Unable to load module %s (%s)' % (modname, ex) 152 msg = 'Unable to load module %s (%s)' % (modname, ex)
153 raise AstroidBuildingException(msg) 153 raise AstroidBuildingException(msg)
154 return self.ast_from_module(module, modname) 154 return self.ast_from_module(module, modname)
155 elif mp_type == imp.PY_COMPILED: 155 elif mp_type == imp.PY_COMPILED:
156 raise AstroidBuildingException("Unable to load compiled module % s" % (modname,)) 156 raise AstroidBuildingException("Unable to load compiled module % s" % (modname,))
157 if filepath is None: 157 if filepath is None:
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 The transform function may return a value which is then used to 304 The transform function may return a value which is then used to
305 substitute the original node in the tree. 305 substitute the original node in the tree.
306 """ 306 """
307 self.transforms[node_class].append((transform, predicate)) 307 self.transforms[node_class].append((transform, predicate))
308 308
309 def unregister_transform(self, node_class, transform, predicate=None): 309 def unregister_transform(self, node_class, transform, predicate=None):
310 """Unregister the given transform.""" 310 """Unregister the given transform."""
311 self.transforms[node_class].remove((transform, predicate)) 311 self.transforms[node_class].remove((transform, predicate))
312 312
313 def register_failed_import_hook(self, hook): 313 def register_failed_import_hook(self, hook):
314 """"Registers a hook to resolve imports that cannot be found otherwise. 314 """Registers a hook to resolve imports that cannot be found otherwise.
315 315
316 `hook` must be a function that accepts a single argument `modname` which 316 `hook` must be a function that accepts a single argument `modname` which
317 contains the name of the module or package that could not be imported. 317 contains the name of the module or package that could not be imported.
318 If `hook` can resolve the import, must return a node of type `astroid.Mo dule`, 318 If `hook` can resolve the import, must return a node of type `astroid.Mo dule`,
319 otherwise, it must raise `AstroidBuildingException`. 319 otherwise, it must raise `AstroidBuildingException`.
320 """ 320 """
321 self._failed_import_hooks.append(hook) 321 self._failed_import_hooks.append(hook)
322 322
323 def transform(self, node): 323 def transform(self, node):
324 """Call matching transforms for the given node if any and return the 324 """Call matching transforms for the given node if any and return the
(...skipping 16 matching lines...) Expand all
341 # node has already be modified by some previous 341 # node has already be modified by some previous
342 # transformation, warn about it 342 # transformation, warn about it
343 warn('node %s substituted multiple times' % node) 343 warn('node %s substituted multiple times' % node)
344 node = ret 344 node = ret
345 return node 345 return node
346 346
347 def cache_module(self, module): 347 def cache_module(self, module):
348 """Cache a module if no module with the same name is known yet.""" 348 """Cache a module if no module with the same name is known yet."""
349 self.astroid_cache.setdefault(module.name, module) 349 self.astroid_cache.setdefault(module.name, module)
350 350
351 def clear_cache(self): 351 def clear_cache(self, astroid_builtin=None):
352 # XXX clear transforms 352 # XXX clear transforms
353 self.astroid_cache.clear() 353 self.astroid_cache.clear()
354 # force bootstrap again, else we may ends up with cache inconsistency 354 # force bootstrap again, else we may ends up with cache inconsistency
355 # between the manager and CONST_PROXY, making 355 # between the manager and CONST_PROXY, making
356 # unittest_lookup.LookupTC.test_builtin_lookup fail depending on the 356 # unittest_lookup.LookupTC.test_builtin_lookup fail depending on the
357 # test order 357 # test order
358 from astroid.raw_building import astroid_bootstrapping 358 import astroid.raw_building
359 astroid_bootstrapping() 359 astroid.raw_building._astroid_bootstrapping(
360 astroid_builtin=astroid_builtin)
360 361
361 362
362 class Project(object): 363 class Project(object):
363 """a project handle a set of modules / packages""" 364 """a project handle a set of modules / packages"""
364 def __init__(self, name=''): 365 def __init__(self, name=''):
365 self.name = name 366 self.name = name
366 self.path = None 367 self.path = None
367 self.modules = [] 368 self.modules = []
368 self.locals = {} 369 self.locals = {}
369 self.__getitem__ = self.locals.__getitem__ 370 self.__getitem__ = self.locals.__getitem__
(...skipping 10 matching lines...) Expand all
380 return self.locals[name] 381 return self.locals[name]
381 382
382 def get_children(self): 383 def get_children(self):
383 return self.modules 384 return self.modules
384 385
385 def __repr__(self): 386 def __repr__(self):
386 return '<Project %r at %s (%s modules)>' % (self.name, id(self), 387 return '<Project %r at %s (%s modules)>' % (self.name, id(self),
387 len(self.modules)) 388 len(self.modules))
388 389
389 390
OLDNEW
« no previous file with comments | « third_party/logilab/astroid/brain/pysix_moves.py ('k') | third_party/logilab/astroid/modutils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698