except InferenceError: break def for_assigned_stmts(self, node, context=None, asspath=None): if asspath is None: for lst in self.iter.infer(context): if isinstance(lst, (nodes.Tuple, nodes.List)): for item in lst.elts: yield item else: for infered in _resolve_looppart(self.iter.infer(context), asspath, context): yield infered nodes.For.assigned_stmts = raise_if_nothing_infered(for_assigned_stmts) nodes.Comprehension.assigned_stmts = raise_if_nothing_infered(for_assigned_stmts) def mulass_assigned_stmts(self, node, context=None, asspath=None): if asspath is None: asspath = [] asspath.insert(0, self.elts.index(node)) return self.parent.assigned_stmts(self, context, asspath) nodes.Tuple.assigned_stmts = mulass_assigned_stmts nodes.List.assigned_stmts = mulass_assigned_stmts def assend_assigned_stmts(self, context=None): return self.parent.assigned_stmts(self, context=context) nodes.AssName.assigned_stmts = assend_assigned_stmts
"""infer a CallFunc node by trying to guess what the function returns""" callcontext = context.clone() callcontext.callcontext = CallContext(self.args, self.starargs, self.kwargs) callcontext.boundnode = None for callee in self.func.infer(context): if callee is YES: yield callee continue try: if hasattr(callee, 'infer_call_result'): for infered in callee.infer_call_result(self, callcontext): yield infered except InferenceError: ## XXX log error ? continue nodes.CallFunc.infer = path_wrapper(raise_if_nothing_infered(infer_callfunc)) def infer_import(self, context=None, asname=True): """infer an Import node: return the imported module/object""" name = context.lookupname if name is None: raise InferenceError() if asname: yield self.do_import_module(self.real_name(name)) else: yield self.do_import_module(name) nodes.Import.infer = path_wrapper(infer_import) def infer_name_module(self, name): context = InferenceContext()
self.kwargs) callcontext.boundnode = None for callee in self.func.infer(context): if callee is YES: yield callee continue try: if hasattr(callee, 'infer_call_result'): for infered in callee.infer_call_result(self, callcontext): yield infered except InferenceError: ## XXX log error ? continue nodes.CallFunc.infer = path_wrapper(raise_if_nothing_infered(infer_callfunc)) def infer_import(self, context=None, asname=True): """infer an Import node: return the imported module/object""" name = context.lookupname if name is None: raise InferenceError() if asname: yield self.do_import_module(self.real_name(name)) else: yield self.do_import_module(name) nodes.Import.infer = path_wrapper(infer_import)
break def for_assigned_stmts(self, node, context=None, asspath=None): if asspath is None: for lst in self.iter.infer(context): if isinstance(lst, (nodes.Tuple, nodes.List)): for item in lst.elts: yield item else: for infered in _resolve_looppart(self.iter.infer(context), asspath, context): yield infered nodes.For.assigned_stmts = raise_if_nothing_infered(for_assigned_stmts) nodes.Comprehension.assigned_stmts = raise_if_nothing_infered( for_assigned_stmts) def mulass_assigned_stmts(self, node, context=None, asspath=None): if asspath is None: asspath = [] asspath.insert(0, self.elts.index(node)) return self.parent.assigned_stmts(self, context, asspath) nodes.Tuple.assigned_stmts = mulass_assigned_stmts nodes.List.assigned_stmts = mulass_assigned_stmts
if asspath is None: for lst in self.iter.infer(context): if isinstance(lst, (nodes.Tuple, nodes.List)): if hasattr(lst, "infer_item"): for item in lst.infer_item(None, context): yield item else: for item in lst.elts: yield item else: for infered in protocols._resolve_looppart(self.iter.infer(context), asspath, context): yield infered nodes.For.assigned_stmts = bases.raise_if_nothing_infered(for_assigned_stmts) def file_from_modname(modname, path=None, context_file=None): """ handle namespace package """ try: return file_from_modpath(modname.split("."), path, context_file) except ImportError: loader = pkgutil.find_loader(modname) if loader is None: raise if not hasattr(loader, "filename"): raise init_file = os.path.join(loader.filename, "__init__.py")
def for_assigned_stmts(self, node, context=None, asspath=None): if asspath is None: for lst in self.iter.infer(context): if isinstance(lst, (nodes.Tuple, nodes.List)): if hasattr(lst, "infer_item"): for item in lst.infer_item(None, context): yield item else: for item in lst.elts: yield item else: for infered in protocols._resolve_looppart(self.iter.infer(context), asspath, context): yield infered nodes.For.assigned_stmts = bases.raise_if_nothing_infered(for_assigned_stmts) def file_from_modname(modname, path=None, context_file=None): """ handle namespace package """ try: return file_from_modpath(modname.split("."), path, context_file) except ImportError: loader = pkgutil.find_loader(modname) if loader is None: raise if not hasattr(loader, "filename"): raise init_file = os.path.join(loader.filename, "__init__.py") if os.path.exists(init_file):