def __new__(cls, name, bases, dictionary): # pylint: disable=I0021,arguments-differ _checkBases(name, bases) if "__slots__" not in dictionary: dictionary["__slots__"] = () if "named_child" in dictionary: named_child = dictionary["named_child"] if type(named_child) is not str: raise NuitkaNodeDesignError( name, "Class named_child attribute must be string not", type(named_child), ) dictionary["__slots__"] += (intern("subnode_" + dictionary["named_child"]), ) if "named_children" in dictionary: if len(dictionary["named_children"]) <= 1: raise NuitkaNodeDesignError( name, "Use ExpressionChildHaving for one child node classes") assert type(dictionary["named_children"]) is tuple dictionary["__slots__"] += tuple( intern("subnode_" + named_child) for named_child in dictionary["named_children"]) # Not a method: if "checker" in dictionary: dictionary["checker"] = staticmethod(dictionary["checker"]) # false alarm, pylint: disable=I0021,too-many-function-args return ABCMeta.__new__(cls, name, bases, dictionary)
def childGetter(name): attr_name = intern("subnode_" + name) def getter(self): return getattr(self, attr_name) return getter
def __new__(cls, name, bases, dictionary): # pylint: disable=I0021,arguments-differ _checkBases(name, bases) if "__slots__" not in dictionary: dictionary["__slots__"] = () if "named_child" in dictionary: dictionary["__slots__"] += (intern("subnode_" + dictionary["named_child"]),) # Not a method: if "checker" in dictionary: dictionary["checker"] = staticmethod(dictionary["checker"]) return ABCMeta.__new__(cls, name, bases, dictionary)
def __new__(cls, name, bases, dictionary): # pylint: disable=I0021,arguments-differ _checkBases(name, bases) if "__slots__" not in dictionary: dictionary["__slots__"] = () if "named_child" in dictionary: dictionary["__slots__"] += (intern("subnode_" + dictionary["named_child"]),) # Not a method: if "checker" in dictionary: dictionary["checker"] = staticmethod(dictionary["checker"]) # false alarm, pylint: disable=I0021,too-many-function-args return ABCMeta.__new__(cls, name, bases, dictionary)
def checkModuleSourceCode(self, module_name, source_code): annotations = {} for count, line in enumerate(source_code.split("\n")): match = re.search(r"#.*pylint:\s*disable=\s*([\w,-]+)", line) if match: comment_only = line[: line.find("#") - 1].strip() == "" if comment_only: # TODO: Parse block wide annotations too. pass else: annotations[count + 1] = set( intern(match.strip()) for match in match.group(1).split(",") ) # Only remember them if there were any. if annotations: self.line_annotations[module_name] = annotations
def __new__(cls, name, bases, dictionary): # pylint: disable=I0021,arguments-differ _checkBases(name, bases) if "__slots__" not in dictionary: dictionary["__slots__"] = () if "named_child" in dictionary: dictionary["__slots__"] += (intern("subnode_" + dictionary["named_child"]), ) if "named_children" in dictionary and not name.endswith("Base"): if len(dictionary["named_children"]) <= 1: raise NuitkaNodeDesignError( name, "Use ExpressionChildHaving for one child node classes") # Not a method: if "checker" in dictionary: dictionary["checker"] = staticmethod(dictionary["checker"]) # false alarm, pylint: disable=I0021,too-many-function-args return ABCMeta.__new__(cls, name, bases, dictionary)
def onModuleSourceCode(self, module_name, source_code): annotations = {} for count, line in enumerate(source_code.split("\n")): match = re.search(r"#.*pylint:\s*disable=\s*([\w,-]+)", line) if match: comment_only = line[: line.find("#") - 1].strip() == "" if comment_only: # TODO: Parse block wide annotations too. pass else: annotations[count + 1] = set( intern(match.strip()) for match in match.group(1).split(",") ) # Only remember them if there were any. if annotations: self.line_annotations[module_name] = annotations # Do nothing to it. return source_code
def _buildContractionNode(provider, node, name, emit_class, start_value, source_ref): # The contraction nodes are reformulated to function bodies, with loops as # described in the developer manual. They use a lot of temporary names, # nested blocks, etc. and so a lot of variable names. function_body = ExpressionOutlineFunction(provider=provider, name=intern(name[1:-1]), source_ref=source_ref) iter_tmp = function_body.allocateTempVariable(temp_scope=None, name=".0") container_tmp = function_body.allocateTempVariable(temp_scope=None, name="contraction") statements, release_statements = _buildContractionBodyNode( provider=provider, node=node, emit_class=emit_class, iter_tmp=iter_tmp, temp_scope=None, start_value=start_value, container_tmp=container_tmp, function_body=function_body, assign_provider=False, for_asyncgen=False, source_ref=source_ref, ) assign_iter_statement = StatementAssignmentVariable( source=_makeIteratorCreation( provider=provider, qual=node.generators[0], for_asyncgen=False, source_ref=source_ref, ), variable=iter_tmp, source_ref=source_ref, ) statements.append( StatementReturn( expression=ExpressionTempVariableRef(variable=container_tmp, source_ref=source_ref), source_ref=source_ref, )) statements = (makeTryFinallyStatement( provider=function_body, tried=statements, final=release_statements, source_ref=source_ref.atInternal(), ), ) if python_version < 300: body = makeStatementsSequenceFromStatements(assign_iter_statement, statements) else: parent_module = provider.getParentModule() code_object = CodeObjectSpec( co_name=name, co_kind="Function", co_varnames=(), co_freevars=(), co_argcount=1, co_posonlyargcount=0, co_kwonlyargcount=0, co_has_starlist=False, co_has_stardict=False, co_filename=parent_module.getRunTimeFilename(), co_lineno=source_ref.getLineNumber(), future_spec=parent_module.getFutureSpec(), ) body = makeStatementsSequenceFromStatements( assign_iter_statement, StatementsFrameFunction( statements=mergeStatements(statements, False), code_object=code_object, source_ref=source_ref, ), ) function_body.setBody(body) return function_body
def _buildContractionNode(provider, node, name, emit_class, start_value, source_ref): # The contraction nodes are reformulated to function bodies, with loops as # described in the developer manual. They use a lot of temporary names, # nested blocks, etc. and so a lot of variable names. function_body = ExpressionOutlineFunction( provider=provider, name=intern(name[1:-1]), source_ref=source_ref ) iter_tmp = function_body.allocateTempVariable(temp_scope=None, name=".0") container_tmp = function_body.allocateTempVariable( temp_scope=None, name="contraction" ) statements, release_statements = _buildContractionBodyNode( provider=provider, node=node, emit_class=emit_class, iter_tmp=iter_tmp, temp_scope=None, start_value=start_value, container_tmp=container_tmp, function_body=function_body, assign_provider=False, for_asyncgen=False, source_ref=source_ref, ) assign_iter_statement = StatementAssignmentVariable( source=_makeIteratorCreation( provider=provider, qual=node.generators[0], for_asyncgen=False, source_ref=source_ref, ), variable=iter_tmp, source_ref=source_ref, ) statements.append( StatementReturn( expression=ExpressionTempVariableRef( variable=container_tmp, source_ref=source_ref ), source_ref=source_ref, ) ) statements = ( makeTryFinallyStatement( provider=function_body, tried=statements, final=release_statements, source_ref=source_ref.atInternal(), ), ) if python_version < 300: body = makeStatementsSequenceFromStatements(assign_iter_statement, statements) else: parent_module = provider.getParentModule() code_object = CodeObjectSpec( co_name=name, co_kind="Function", co_varnames=(), co_argcount=1, co_kwonlyargcount=0, co_has_starlist=False, co_has_stardict=False, co_filename=parent_module.getRunTimeFilename(), co_lineno=source_ref.getLineNumber(), future_spec=parent_module.getFutureSpec(), ) body = makeStatementsSequenceFromStatements( assign_iter_statement, StatementsFrameFunction( statements=mergeStatements(statements, False), code_object=code_object, source_ref=source_ref, ), ) function_body.setBody(body) return function_body