def __init__(self, parent_reporter, parent_frame, parent_space, anchor, name, bases, evals, tree): from pyntch.syntax import build_stmt self.anchor = anchor self.loc = (tree._module, tree.lineno) self.space = Namespace(parent_space, name) TreeReporter.__init__(self, parent_reporter) ClassType.__init__(self, name, bases) if tree.code: self.space.register_names(tree.code) build_stmt(self, parent_frame, self.space, tree.code, evals, parent_space=parent_space) for (name,var) in self.space: # Do not consider the values of attributes inherited from the base class # if they are explicitly overriden. attr = self.ClassAttr(parent_frame, anchor, name, self) var.connect(attr.recv) self.attrs[name] = attr return
def __init__(self, parent_reporter, parent_frame, parent_space, anchor, name, argnames, defaults, variargs, kwargs, tree): TreeReporter.__init__(self, parent_reporter) def maprec(func, x): if isinstance(x, tuple): return tuple(maprec(func, y) for y in x) else: return func(x) self.name = name # prepare local variables that hold passed arguments. self.space = Namespace(parent_space, name) self.frame = ExecutionFrame(None, tree) # handle "**kwd". self.kwarg = None if kwargs: self.kwarg = argnames[-1] del argnames[-1] self.space.register_var(self.kwarg) # handle "*args". self.variarg = None if variargs: self.variarg = argnames[-1] del argnames[-1] self.space.register_var(self.variarg) # handle normal args. self.argnames = tuple(argnames) maprec(lambda argname: self.space.register_var(argname), self.argnames) # build the function body. self.space.register_names(tree.code) self.body = self.FuncBody(name) self.body.set_retval(self.build_evals(tree.code)) self.argvars = maprec(lambda argname: self.space[argname], self.argnames) # assign the default values. self.defaults = tuple(defaults) for (var1, arg1) in zip(self.argvars[-len(defaults):], self.defaults): assign_arg(parent_frame, anchor, var1, arg1) self.frames = set() BuiltinType.__init__(self) return