[pypy-svn] r12336 - in pypy/dist/pypy/objspace: . std std/test
arigo at codespeak.net
arigo at codespeak.net
Mon May 16 00:33:00 CEST 2005
Author: arigo
Date: Mon May 16 00:33:00 2005
New Revision: 12336
Modified:
pypy/dist/pypy/objspace/descroperation.py
pypy/dist/pypy/objspace/std/test/test_typeobject.py
pypy/dist/pypy/objspace/std/typeobject.py
pypy/dist/pypy/objspace/std/typetype.py
Log:
Made the __name__ of types writeable. This triggered a chain of obscure
and mostly funny problems leading to eventual bug fixes.
Modified: pypy/dist/pypy/objspace/descroperation.py
==============================================================================
--- pypy/dist/pypy/objspace/descroperation.py (original)
+++ pypy/dist/pypy/objspace/descroperation.py Mon May 16 00:33:00 2005
@@ -46,7 +46,8 @@
w_descr = space.lookup(w_obj, name)
if w_descr is not None:
if space.is_data_descr(w_descr):
- return space.delete(w_descr, w_obj)
+ space.delete(w_descr, w_obj)
+ return
w_dict = w_obj.getdict()
if w_dict is not None:
try:
Modified: pypy/dist/pypy/objspace/std/test/test_typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_typeobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_typeobject.py Mon May 16 00:33:00 2005
@@ -428,3 +428,11 @@
raises(TypeError, "X().__class__ = object")
raises(TypeError, "X().__class__ = 1")
+
+ def test_name(self):
+ class Abc(object):
+ pass
+ assert Abc.__name__ == 'Abc'
+ Abc.__name__ = 'Def'
+ assert Abc.__name__ == 'Def'
+ raises(TypeError, "Abc.__name__ = 42")
Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py (original)
+++ pypy/dist/pypy/objspace/std/typeobject.py Mon May 16 00:33:00 2005
@@ -322,26 +322,17 @@
raise OperationError(space.w_AttributeError, space.wrap(msg))
def setattr__Type_ANY_ANY(space, w_type, w_name, w_value):
+ # Note. This is exactly the same thing as descroperation.descr__setattr__,
+ # but it is needed at bootstrap to avoid a call to w_type.getdict() which
+ # would un-lazify the whole type.
name = space.str_w(w_name)
w_descr = space.lookup(w_type, name)
if w_descr is not None:
if space.is_data_descr(w_descr):
- space.set(w_descr,w_type,space.type(w_type))
+ space.set(w_descr, w_type, w_value)
+ return
w_type.dict_w[name] = w_value
-def delattr__Type_ANY(space, w_type, w_name):
- if w_type.lazyloaders:
- w_type._freeze_() # force un-lazification
- name = space.str_w(w_name)
- w_descr = space.lookup(w_type, name)
- if w_descr is not None:
- if space.is_data_descr(w_descr):
- space.delete(w_descr, space.type(w_type))
- del w_type.dict_w[name]
-
-# XXX __delattr__
-# XXX __hash__ ??
-
# ____________________________________________________________
Modified: pypy/dist/pypy/objspace/std/typetype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typetype.py (original)
+++ pypy/dist/pypy/objspace/std/typetype.py Mon May 16 00:33:00 2005
@@ -64,6 +64,14 @@
w_type = _check(space, w_type)
return space.wrap(w_type.name)
+def descr_set__name__(space, w_type, w_value):
+ w_type = _check(space, w_type)
+ if not w_type.is_heaptype():
+ raise OperationError(space.w_TypeError,
+ space.wrap("can't set %s.__name__" %
+ w_type.name))
+ w_type.name = space.str_w(w_value)
+
def descr_get__mro__(space, w_type):
w_type = _check(space, w_type)
# XXX this should be inside typeobject.py
@@ -124,17 +132,13 @@
raise OperationError(space.w_TypeError,
space.wrap("can't set %s.__module__" %
w_type.name))
- if w_value is None:
- raise OperationError(space.w_TypeError,
- space.wrap("can't delete %s.__module__" %
- w_type.name))
w_type.dict_w['__module__'] = w_value
# ____________________________________________________________
type_typedef = StdTypeDef("type",
__new__ = newmethod(descr__new__),
- __name__ = GetSetProperty(descr_get__name__),
+ __name__ = GetSetProperty(descr_get__name__, descr_set__name__),
__bases__ = GetSetProperty(descr__bases),
__base__ = GetSetProperty(descr__base),
__mro__ = GetSetProperty(descr_get__mro__),
More information about the Pypy-commit
mailing list