def getRootInContext(pyAstNode, isClassContext): if not NodeVisitorBases.isScopeNode(pyAstNode): raise Exceptions.InternalError( "Unsupported type of root node in Analysis (%s)." % type(pyAstNode)) if isinstance(pyAstNode, ast.FunctionDef): if isClassContext is None: raise Exceptions.InternalError( "Value for `isClassContext is required when `type(pyAstNode) is `ast.FunctionDef." ) elif isClassContext is False: pyAstNode = ast.Module([pyAstNode]) # else nothing return pyAstNode
def _cachedCompute(self): if not self._isComputed: if PyAstUtil.isScopeNode(self._root): self.generic_visit(self._root) self._isComputed = True else: raise Exceptions.InternalError( "'%s' called on unsupported node-type (%s)" % (self.__class__.__name__, type(self._root)))
def collectPossiblyUninitializedLocalVariables(pyAstNode): """Returns the possibly free local variables of the code rooted at `pyAstNode.""" # Context doesn't play a role below, but we reuse the code for checking `pyAstNode if not PyAstUtil.isScopeNode(pyAstNode): raise Exceptions.InternalError( "Unsupported type of root node in Analysis (%s)" % type(pyAstNode)) possiblyUninitVisitor = _PossiblyUninitializedScopedVisitor() possiblyUninitVisitor.visit(pyAstNode) return possiblyUninitVisitor.getPossiblyUninitializedLocalVariables()
def _cachedCompute(self): if not self._isComputed: if isScopeNode(self._root): if isinstance(self._root, ast.FunctionDef) and hasattr( self._root, 'arguments'): self._root.arguments.lineno = self._root.lineno self._root.arguments.col_offset = self._root.col_offset self.generic_visit(self._root) self._isComputed = True else: raise Exceptions.InternalError( "'%s' called on unsupported node-type (%s)" % (self.__class__.__name__, type(self._root)))
def _collectDataMembersSetInInitAst(initAst): _assertOnlySimpleStatements(initAst) if len(initAst.args.args) == 0: raise Exceptions.PythonToForaConversionError( "the `__init__ method is missing a first, positional, " \ "`self argument (line %s)." % (initAst.lineno) ) selfArg = initAst.args.args[0] if not isinstance(selfArg, ast.Name): raise Exceptions.InternalError( "the `self argument to the `__init__ method" \ " is not of type `ast.Name (line %s)." % (initAst.lineno) ) return _extractSimpleSelfMemberAssignments(initFunctionDef=initAst, selfName=selfArg.id)
def visit_Module(self, _): raise Exceptions.InternalError( "Unexpected call of 'visit_Module' in '%s'" % self.__class__.__name__)