def __init__(self, space, pto): bases_w = space.fixedview(from_ref(space, pto.c_tp_bases)) dict_w = {} add_operators(space, dict_w, pto) convert_method_defs(space, dict_w, pto.c_tp_methods, self) convert_getset_defs(space, dict_w, pto.c_tp_getset, self) convert_member_defs(space, dict_w, pto.c_tp_members, self) name = rffi.charp2str(cts.cast('char*', pto.c_tp_name)) flag_heaptype = pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE if flag_heaptype: minsize = rffi.sizeof(PyHeapTypeObject.TO) else: minsize = rffi.sizeof(PyObject.TO) new_layout = (pto.c_tp_basicsize > minsize or pto.c_tp_itemsize > 0) W_TypeObject.__init__(self, space, name, bases_w or [space.w_object], dict_w, force_new_layout=new_layout, is_heaptype=flag_heaptype) self.flag_cpytype = True # if a sequence or a mapping, then set the flag to force it if pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_item: self.flag_map_or_seq = 'S' elif (pto.c_tp_as_mapping and pto.c_tp_as_mapping.c_mp_subscript and not (pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_slice)): self.flag_map_or_seq = 'M' if pto.c_tp_doc: self.w_doc = space.newtext( rffi.charp2str(cts.cast('char*', pto.c_tp_doc)))
def __init__(self, space, pto): bases_w = space.fixedview(from_ref(space, pto.c_tp_bases)) dict_w = {} add_operators(space, dict_w, pto) convert_method_defs(space, dict_w, pto.c_tp_methods, self) convert_getset_defs(space, dict_w, pto.c_tp_getset, self) convert_member_defs(space, dict_w, pto.c_tp_members, self) name = rffi.charp2str(pto.c_tp_name) flag_heaptype = pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE if flag_heaptype: minsize = rffi.sizeof(PyHeapTypeObject.TO) else: minsize = rffi.sizeof(PyObject.TO) new_layout = (pto.c_tp_basicsize > minsize or pto.c_tp_itemsize > 0) W_TypeObject.__init__(self, space, name, bases_w or [space.w_object], dict_w, force_new_layout=new_layout, is_heaptype=flag_heaptype) self.flag_cpytype = True # if a sequence or a mapping, then set the flag to force it if pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_item: self.flag_map_or_seq = 'S' elif (pto.c_tp_as_mapping and pto.c_tp_as_mapping.c_mp_subscript and not (pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_slice)): self.flag_map_or_seq = 'M' if pto.c_tp_doc: self.w_doc = space.wrap(rffi.charp2str(pto.c_tp_doc))
def __init__(self, space, name, bases_w, dict_w, basicsize=0): # XXX: there is a discussion going on to make it possible to create # non-heap types with HPyType_FromSpec. Remember to fix this place # when it's the case. W_TypeObject.__init__(self, space, name, bases_w, dict_w, is_heaptype=True) self.basicsize = basicsize
def descr__new__(space, w_typetype, w_name, w_bases=gateway.NoneNotWrapped, w_dict=gateway.NoneNotWrapped): "This is used to create user-defined classes only." from pypy.objspace.std.typeobject import W_TypeObject # XXX check types w_typetype = _precheck_for_new(space, w_typetype) # special case for type(x) if (space.is_w(space.type(w_typetype), space.w_type) and w_bases is None and w_dict is None): return space.type(w_name) elif w_bases is None or w_dict is None: raise OperationError(space.w_TypeError, space.wrap("type() takes 1 or 3 arguments")) bases_w = space.fixedview(w_bases) w_winner = w_typetype for base in bases_w: w_typ = space.type(base) if space.is_w(w_typ, space.w_classobj): continue # special-case old-style classes if space.is_true(space.issubtype(w_winner, w_typ)): continue if space.is_true(space.issubtype(w_typ, w_winner)): w_winner = w_typ continue raise OperationError(space.w_TypeError, space.wrap("metaclass conflict: " "the metaclass of a derived class " "must be a (non-strict) subclass " "of the metaclasses of all its bases")) if not space.is_w(w_winner, w_typetype): newfunc = space.getattr(w_winner, space.wrap('__new__')) if not space.is_w(newfunc, space.getattr(space.w_type, space.wrap('__new__'))): return space.call_function(newfunc, w_winner, w_name, w_bases, w_dict) w_typetype = w_winner name = space.str_w(w_name) assert isinstance(name, str) dict_w = {} dictkeys_w = space.listview(w_dict) for w_key in dictkeys_w: key = space.str_w(w_key) dict_w[key] = space.getitem(w_dict, w_key) w_type = space.allocate_instance(W_TypeObject, w_typetype) W_TypeObject.__init__(w_type, space, name, bases_w or [space.w_object], dict_w) w_type.ready() return w_type
def _create_new_type(space, w_typetype, w_name, w_bases, w_dict): # this is in its own function because we want the special case 'type(x)' # above to be seen by the jit. from pypy.objspace.std.typeobject import W_TypeObject if w_bases is None or w_dict is None: raise OperationError(space.w_TypeError, space.wrap("type() takes 1 or 3 arguments")) bases_w = space.fixedview(w_bases) w_winner = w_typetype for base in bases_w: w_typ = space.type(base) if space.is_w(w_typ, space.w_classobj): continue # special-case old-style classes if space.is_true(space.issubtype(w_winner, w_typ)): continue if space.is_true(space.issubtype(w_typ, w_winner)): w_winner = w_typ continue raise OperationError( space.w_TypeError, space.wrap("metaclass conflict: " "the metaclass of a derived class " "must be a (non-strict) subclass " "of the metaclasses of all its bases")) if not space.is_w(w_winner, w_typetype): newfunc = space.getattr(w_winner, space.wrap('__new__')) if not space.is_w(newfunc, space.getattr(space.w_type, space.wrap('__new__'))): return space.call_function(newfunc, w_winner, w_name, w_bases, w_dict) w_typetype = w_winner name = space.str_w(w_name) assert isinstance(name, str) dict_w = {} dictkeys_w = space.listview(w_dict) for w_key in dictkeys_w: key = space.str_w(w_key) dict_w[key] = space.getitem(w_dict, w_key) w_type = space.allocate_instance(W_TypeObject, w_typetype) W_TypeObject.__init__(w_type, space, name, bases_w or [space.w_object], dict_w) w_type.ready() return w_type
def _create_new_type(space, w_typetype, w_name, w_bases, w_dict): # this is in its own function because we want the special case 'type(x)' # above to be seen by the jit. from pypy.objspace.std.typeobject import W_TypeObject if w_bases is None or w_dict is None: raise OperationError(space.w_TypeError, space.wrap("type() takes 1 or 3 arguments")) bases_w = space.fixedview(w_bases) w_winner = w_typetype for base in bases_w: w_typ = space.type(base) if space.is_w(w_typ, space.w_classobj): continue # special-case old-style classes if space.is_true(space.issubtype(w_winner, w_typ)): continue if space.is_true(space.issubtype(w_typ, w_winner)): w_winner = w_typ continue raise OperationError( space.w_TypeError, space.wrap( "metaclass conflict: " "the metaclass of a derived class " "must be a (non-strict) subclass " "of the metaclasses of all its bases" ), ) if not space.is_w(w_winner, w_typetype): newfunc = space.getattr(w_winner, space.wrap("__new__")) if not space.is_w(newfunc, space.getattr(space.w_type, space.wrap("__new__"))): return space.call_function(newfunc, w_winner, w_name, w_bases, w_dict) w_typetype = w_winner name = space.str_w(w_name) assert isinstance(name, str) dict_w = {} dictkeys_w = space.listview(w_dict) for w_key in dictkeys_w: key = space.str_w(w_key) dict_w[key] = space.getitem(w_dict, w_key) w_type = space.allocate_instance(W_TypeObject, w_typetype) W_TypeObject.__init__(w_type, space, name, bases_w or [space.w_object], dict_w) w_type.ready() return w_type
def descr__new__(space, w_typetype, w_name, w_bases, w_dict): "This is used to create user-defined classes only." from pypy.objspace.std.typeobject import W_TypeObject # XXX check types w_typetype = _precheck_for_new(space, w_typetype) bases_w = space.unpackiterable(w_bases) w_winner = w_typetype for base in bases_w: w_typ = space.type(base) if space.is_w(w_typ, space.w_classobj): continue # special-case old-style classes if space.is_true(space.issubtype(w_winner, w_typ)): continue if space.is_true(space.issubtype(w_typ, w_winner)): w_winner = w_typ continue raise OperationError( space.w_TypeError, space.wrap("metaclass conflict: " "the metaclass of a derived class " "must be a (non-strict) subclass " "of the metaclasses of all its bases")) if not space.is_w(w_winner, w_typetype): newfunc = space.getattr(w_winner, space.wrap('__new__')) if not space.is_w(newfunc, space.getattr(space.w_type, space.wrap('__new__'))): return space.call_function(newfunc, w_winner, w_name, w_bases, w_dict) w_typetype = w_winner name = space.str_w(w_name) assert isinstance(name, str) dict_w = {} dictkeys_w = space.unpackiterable(w_dict) for w_key in dictkeys_w: key = space.str_w(w_key) dict_w[key] = space.getitem(w_dict, w_key) w_type = space.allocate_instance(W_TypeObject, w_typetype) W_TypeObject.__init__(w_type, space, name, bases_w or [space.w_object], dict_w) w_type.ready() return w_type
def __init__(self, space, pto): bases_w = space.fixedview(from_ref(space, pto.c_tp_bases)) dict_w = {} add_operators(space, dict_w, pto) convert_method_defs(space, dict_w, pto.c_tp_methods, self) convert_getset_defs(space, dict_w, pto.c_tp_getset, self) convert_member_defs(space, dict_w, pto.c_tp_members, self) name = rffi.charp2str(pto.c_tp_name) W_TypeObject.__init__(self, space, name, bases_w or [space.w_object], dict_w) if not space.is_true(space.issubtype(self, space.w_type)): self.flag_cpytype = True self.flag_heaptype = False if pto.c_tp_doc: self.w_doc = space.wrap(rffi.charp2str(pto.c_tp_doc))
def __init__(self, space, pto): bases_w = space.fixedview(from_ref(space, pto.c_tp_bases)) dict_w = {} add_operators(space, dict_w, pto) convert_method_defs(space, dict_w, pto.c_tp_methods, self) convert_getset_defs(space, dict_w, pto.c_tp_getset, self) convert_member_defs(space, dict_w, pto.c_tp_members, self) name = rffi.charp2str(pto.c_tp_name) W_TypeObject.__init__(self, space, name, bases_w or [space.w_object], dict_w) if not space.is_true(space.issubtype(self, space.w_type)): self.flag_cpytype = True self.flag_heaptype = False if pto.c_tp_doc: self.w_doc = space.wrap(rffi.charp2str(pto.c_tp_doc))
def __init__(self, space, pto): bases_w = space.fixedview(from_ref(space, pto.c_tp_bases)) dict_w = {} add_operators(space, dict_w, pto) convert_method_defs(space, dict_w, pto.c_tp_methods, self) convert_getset_defs(space, dict_w, pto.c_tp_getset, self) convert_member_defs(space, dict_w, pto.c_tp_members, self) full_name = rffi.charp2str(pto.c_tp_name) if '.' in full_name: module_name, extension_name = rsplit(full_name, ".", 1) dict_w["__module__"] = space.wrap(module_name) else: extension_name = full_name W_TypeObject.__init__(self, space, extension_name, bases_w or [space.w_object], dict_w) if not space.is_true(space.issubtype(self, space.w_type)): self.flag_cpytype = True self.flag_heaptype = False
def __init__(self, space, pto): bases_w = space.fixedview(from_ref(space, pto.c_tp_bases)) dict_w = {} add_operators(space, dict_w, pto) convert_method_defs(space, dict_w, pto.c_tp_methods, self) convert_getset_defs(space, dict_w, pto.c_tp_getset, self) convert_member_defs(space, dict_w, pto.c_tp_members, self) full_name = rffi.charp2str(pto.c_tp_name) if '.' in full_name: module_name, extension_name = rsplit(full_name, ".", 1) dict_w["__module__"] = space.wrap(module_name) else: extension_name = full_name W_TypeObject.__init__(self, space, extension_name, bases_w or [space.w_object], dict_w) if not space.is_true(space.issubtype(self, space.w_type)): self.flag_cpytype = True self.flag_heaptype = False if pto.c_tp_doc: self.w_doc = space.wrap(rffi.charp2str(pto.c_tp_doc))
def __init__(self, space, pto): bases_w = space.fixedview(from_ref(space, pto.c_tp_bases)) dict_w = {} name = rffi.charp2str(cts.cast('char*', pto.c_tp_name)) add_operators(space, self, dict_w, pto, name) convert_method_defs(space, dict_w, pto.c_tp_methods, self) convert_getset_defs(space, dict_w, pto.c_tp_getset, self) convert_member_defs(space, dict_w, pto.c_tp_members, self) w_dict = from_ref(space, pto.c_tp_dict) if w_dict is not None: dictkeys_w = space.listview(w_dict) for w_key in dictkeys_w: key = space.text_w(w_key) dict_w[key] = space.getitem(w_dict, w_key) flag_heaptype = pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE if flag_heaptype: minsize = rffi.sizeof(PyHeapTypeObject.TO) else: minsize = rffi.sizeof(PyObject.TO) new_layout = (pto.c_tp_basicsize > minsize or pto.c_tp_itemsize > 0) self.flag_cpytype = True W_TypeObject.__init__(self, space, name, bases_w or [space.w_object], dict_w, force_new_layout=new_layout, is_heaptype=flag_heaptype) # if a sequence or a mapping, then set the flag to force it if pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_item: self.flag_map_or_seq = 'S' elif pto.c_tp_as_mapping and pto.c_tp_as_mapping.c_mp_subscript: self.flag_map_or_seq = 'M' if pto.c_tp_doc: rawdoc = rffi.charp2str(cts.cast('char*', pto.c_tp_doc)) self.w_doc = space.newtext_or_none(extract_doc(rawdoc, name)) self.text_signature = extract_txtsig(rawdoc, name)