[pypy-svn] r4940 - pypy/branch/src-newobjectmodel/pypy/objspace/std
mwh at codespeak.net
mwh at codespeak.net
Sat Jun 5 12:20:49 CEST 2004
Author: mwh
Date: Sat Jun 5 12:20:49 2004
New Revision: 4940
Modified:
pypy/branch/src-newobjectmodel/pypy/objspace/std/floattype.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/inttype.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/objspace.py
pypy/branch/src-newobjectmodel/pypy/objspace/std/stringtype.py
Log:
be careful with defaults in __new__ implementations
nudges for string -> int conversion
import all object implementations *before* building type objects!
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/floattype.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/floattype.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/floattype.py Sat Jun 5 12:20:49 2004
@@ -1,15 +1,18 @@
from pypy.objspace.std.stdtypedef import *
from pypy.objspace.std.objecttype import object_typedef
-def descr__new__(space, w_floattype, w_value=0):
- if space.is_true(space.isinstance(w_value, space.w_str)):
- try:
- w_obj = space.newfloat(float(space.unwrap(w_value)))
- except ValueError, e:
- raise OperationError(space.w_ValueError,
- space.wrap(str(e)))
+def descr__new__(space, w_floattype, w_value=None):
+ if w_value is None:
+ w_obj = space.newfloat(0.0)
else:
- w_obj = space.float(w_value)
+ if space.is_true(space.isinstance(w_value, space.w_str)):
+ try:
+ w_obj = space.newfloat(float(space.unwrap(w_value)))
+ except ValueError, e:
+ raise OperationError(space.w_ValueError,
+ space.wrap(str(e)))
+ else:
+ w_obj = space.float(w_value)
return space.w_float.check_user_subclass(w_floattype, w_obj)
# ____________________________________________________________
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/inttype.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/inttype.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/inttype.py Sat Jun 5 12:20:49 2004
@@ -1,15 +1,22 @@
from pypy.objspace.std.stdtypedef import *
from pypy.objspace.std.objecttype import object_typedef
+from pypy.interpreter.error import OperationError
-
-def descr__new__(space, w_inttype, w_value=0, w_base=None):
+def descr__new__(space, w_inttype, w_value=None, w_base=None):
from intobject import W_IntObject
- if w_base == space.w_None:
- w_obj = space.int(w_value)
+ if w_base is None:
+ w_base = space.w_None
+ if w_value is None:
+ space.newint(0)
+ if w_base == space.w_None and not space.is_true(space.isinstance(w_value, space.w_str)):
+ w_obj = space.int(w_value)
else:
+ if w_base == space.w_None:
+ base = 0
+ else:
+ base = space.unwrap(w_base)
# XXX write the logic for int("str", base)
s = space.unwrap(w_value)
- base = space.unwrap(w_base)
try:
value = int(s, base)
except TypeError, e:
@@ -21,7 +28,7 @@
except OverflowError, e:
raise OperationError(space.w_OverflowError,
space.wrap(str(e)))
- w_obj = W_IntObject(value)
+ w_obj = W_IntObject(space, value)
return space.w_int.check_user_subclass(w_inttype, w_obj)
# ____________________________________________________________
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/objspace.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/objspace.py Sat Jun 5 12:20:49 2004
@@ -55,6 +55,14 @@
from stringtype import str_typedef
from typetype import type_typedef
from slicetype import slice_typedef
+ import floatobject
+ import objectobject
+ import boolobject
+ import tupleobject
+ import listobject
+ import stringobject
+ import typeobject
+ import sliceobject
return [value for key, value in result.__dict__.items()
if not key.startswith('_')] # don't look
Modified: pypy/branch/src-newobjectmodel/pypy/objspace/std/stringtype.py
==============================================================================
--- pypy/branch/src-newobjectmodel/pypy/objspace/std/stringtype.py (original)
+++ pypy/branch/src-newobjectmodel/pypy/objspace/std/stringtype.py Sat Jun 5 12:20:49 2004
@@ -36,8 +36,11 @@
# ____________________________________________________________
-def descr__new__(space, w_stringtype, w_obj=''):
- w_obj = space.str(w_obj)
+def descr__new__(space, w_stringtype, w_obj=None):
+ if w_obj is None:
+ w_obj = space.newstring('')
+ else:
+ w_obj = space.str(w_obj)
return space.w_str.check_user_subclass(w_stringtype, w_obj)
# ____________________________________________________________
More information about the Pypy-commit
mailing list