Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r50739:957bcdcb424d
Date: 2011-12-19 23:26 +0100
http://bitbucket.org/pypy/pypy/changeset/957bcdcb424d/
Log: Kill more code related to old-style classes
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -924,19 +924,14 @@
def exception_match(self, w_exc_type, w_check_class):
"""Checks if the given exception type matches 'w_check_class'."""
if self.is_w(w_exc_type, w_check_class):
- return True # fast path (also here to handle string exceptions)
- try:
- if self.is_true(self.isinstance(w_check_class, self.w_tuple)):
- for w_t in self.fixedview(w_check_class):
- if self.exception_match(w_exc_type, w_t):
- return True
- else:
- return False
- return self.exception_issubclass_w(w_exc_type, w_check_class)
- except OperationError, e:
- if e.match(self, self.w_TypeError): # string exceptions maybe
+ return True # fast path
+ if self.is_true(self.isinstance(w_check_class, self.w_tuple)):
+ for w_t in self.fixedview(w_check_class):
+ if self.exception_match(w_exc_type, w_t):
+ return True
+ else:
return False
- raise
+ return self.exception_issubclass_w(w_exc_type, w_check_class)
def call_obj_args(self, w_callable, w_obj, args):
if not self.config.objspace.disable_call_speedhacks:
@@ -1016,26 +1011,11 @@
return w_value
return None
- def is_oldstyle_instance(self, w_obj):
- # xxx hack hack hack
- from pypy.module.__builtin__.interp_classobj import W_InstanceObject
- obj = self.interpclass_w(w_obj)
- return obj is not None and isinstance(obj, W_InstanceObject)
-
def callable(self, w_obj):
if self.lookup(w_obj, "__call__") is not None:
- if self.is_oldstyle_instance(w_obj):
- # ugly old style class special treatment, but well ...
- try:
- self.getattr(w_obj, self.wrap("__call__"))
- return self.w_True
- except OperationError, e:
- if not e.match(self, self.w_AttributeError):
- raise
- return self.w_False
- else:
- return self.w_True
- return self.w_False
+ return self.w_True
+ else:
+ return self.w_None
def issequence_w(self, w_obj):
return (self.findattr(w_obj, self.wrap("__getitem__")) is not None)
@@ -1064,8 +1044,7 @@
# Equivalent to 'obj.__class__'.
return self.type(w_obj)
- # CPython rules allows old style classes or subclasses
- # of BaseExceptions to be exceptions.
+ # CPython rules allows subclasses of BaseExceptions to be exceptions.
# This is slightly less general than the case above, so we prefix
# it with exception_
diff --git a/pypy/module/__builtin__/functional.py
b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -218,14 +218,9 @@
def reversed(space, w_sequence):
"""Return a iterator that yields items of sequence in reverse."""
- w_reversed = None
- if space.is_oldstyle_instance(w_sequence):
- w_reversed = space.findattr(w_sequence, space.wrap("__reversed__"))
- else:
- w_reversed_descr = space.lookup(w_sequence, "__reversed__")
- if w_reversed_descr is not None:
- w_reversed = space.get(w_reversed_descr, w_sequence)
- if w_reversed is not None:
+ w_reversed_descr = space.lookup(w_sequence, "__reversed__")
+ if w_reversed_descr is not None:
+ w_reversed = space.get(w_reversed_descr, w_sequence)
return space.call_function(w_reversed)
return space.wrap(W_ReversedIterator(space, w_sequence))
diff --git a/pypy/module/__pypy__/interp_magic.py
b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -62,9 +62,6 @@
@unwrap_spec(ObjSpace, W_Root, str)
def lookup_special(space, w_obj, meth):
"""Lookup up a special method on an object."""
- if space.is_oldstyle_instance(w_obj):
- w_msg = space.wrap("this doesn't do what you want on old-style
classes")
- raise OperationError(space.w_TypeError, w_msg)
w_descr = space.lookup(w_obj, meth)
if w_descr is None:
return space.w_None
diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -181,9 +181,8 @@
exc is a class object, this also returns true when given is an instance
of a subclass. If exc is a tuple, all exceptions in the tuple (and
recursively in subtuples) are searched for a match."""
- if (space.is_true(space.isinstance(w_given, space.w_BaseException)) or
- space.is_oldstyle_instance(w_given)):
- w_given_type = space.exception_getclass(w_given)
+ if space.is_true(space.isinstance(w_given, space.w_BaseException)):
+ w_given_type = space.type(w_given)
else:
w_given_type = w_given
return space.exception_match(w_given_type, w_exc)
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -55,14 +55,7 @@
"'%s' object attribute '%s' is read-only",
typename, name)
-# Helpers for old-style and mix-style mixup
-
def _same_class_w(space, w_obj1, w_obj2, w_typ1, w_typ2):
- if (space.is_oldstyle_instance(w_obj1) and
- space.is_oldstyle_instance(w_obj2)):
- assert isinstance(w_obj1, W_InstanceObject)
- assert isinstance(w_obj2, W_InstanceObject)
- return space.is_w(w_obj1.w_class, w_obj2.w_class)
return space.is_w(w_typ1, w_typ2)
@@ -350,7 +343,7 @@
w_typ1 = space.type(w_obj1)
w_typ2 = space.type(w_obj2)
w_left_src, w_left_impl = space.lookup_in_type_where(w_typ1, '__pow__')
- if _same_class_w(space, w_obj1, w_obj2, w_typ1, w_typ2):
+ if space.is_w(w_typ1, w_typ2):
w_right_impl = None
else:
w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2,
'__rpow__')
@@ -616,53 +609,6 @@
space.lookup(w_obj, '__float__') is not None)
-
-# what is the maximum value slices can get on CPython?
-# we need to stick to that value, because fake.py etc.
-class Temp(object):
- def __getslice__(self, i, j):
- return j
-slice_max = Temp()[:]
-del Temp
-
-def old_slice_range_getlength(space, w_obj):
- # NB. the language ref is inconsistent with the new-style class
- # behavior when w_obj doesn't implement __len__(), so we just
- # follow cpython. Also note that CPython slots make it easier
- # to check for object implementing it or not. We just catch errors
- # so this behavior is slightly different
- try:
- return space.len(w_obj)
- except OperationError, e:
- if not ((e.match(space, space.w_AttributeError) or
- e.match(space, space.w_TypeError))):
- raise
- return None
-
-def old_slice_range(space, w_obj, w_start, w_stop):
- """Only for backward compatibility for __getslice__()&co methods."""
- w_length = None
- if space.is_w(w_start, space.w_None):
- w_start = space.wrap(0)
- else:
- start = space.getindex_w(w_start, None)
- w_start = space.wrap(start)
- if start < 0:
- w_length = old_slice_range_getlength(space, w_obj)
- if w_length is not None:
- w_start = space.add(w_start, w_length)
- if space.is_w(w_stop, space.w_None):
- w_stop = space.wrap(slice_max)
- else:
- stop = space.getindex_w(w_stop, None)
- w_stop = space.wrap(stop)
- if stop < 0:
- if w_length is None:
- w_length = old_slice_range_getlength(space, w_obj)
- if w_length is not None:
- w_stop = space.add(w_stop, w_length)
- return w_start, w_stop
-
# regular methods def helpers
def _make_binop_impl(symbol, specialnames):
@@ -674,7 +620,7 @@
w_typ1 = space.type(w_obj1)
w_typ2 = space.type(w_obj2)
w_left_src, w_left_impl = space.lookup_in_type_where(w_typ1, left)
- if _same_class_w(space, w_obj1, w_obj2, w_typ1, w_typ2):
+ if space.is_w(w_typ1, w_typ2):
w_right_impl = None
else:
w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2,
right)
@@ -716,21 +662,20 @@
w_first = w_obj1
w_second = w_obj2
#
- if left == right and _same_class_w(space, w_obj1, w_obj2,
- w_typ1, w_typ2):
+ if left == right and space.is_w(w_typ1, w_typ2):
# for __eq__ and __ne__, if the objects have the same
- # (old-style or new-style) class, then don't try the
- # opposite method, which is the same one.
+ # class, then don't try the opposite method, which is the
+ # same one.
w_right_impl = None
else:
# in all other cases, try the opposite method.
w_right_src, w_right_impl =
space.lookup_in_type_where(w_typ2,right)
if space.is_w(w_typ1, w_typ2):
- # if the type is the same, *or* if both are old-style classes,
- # then don't reverse: try left first, right next.
+ # if the type is the same, then don't reverse: try
+ # left first, right next.
pass
elif space.is_true(space.issubtype(w_typ2, w_typ1)):
- # for new-style classes, if typ2 is a subclass of typ1.
+ # if typ2 is a subclass of typ1.
w_obj1, w_obj2 = w_obj2, w_obj1
w_left_impl, w_right_impl = w_right_impl, w_left_impl
diff --git a/pypy/objspace/std/complextype.py b/pypy/objspace/std/complextype.py
--- a/pypy/objspace/std/complextype.py
+++ b/pypy/objspace/std/complextype.py
@@ -173,20 +173,10 @@
return (w_complex.realval, w_complex.imagval)
#
# test for a '__complex__' method, and call it if found.
- # special case old-style instances, like CPython does.
w_z = None
- if space.is_oldstyle_instance(w_complex):
- try:
- w_method = space.getattr(w_complex, space.wrap('__complex__'))
- except OperationError, e:
- if not e.match(space, space.w_AttributeError):
- raise
- else:
- w_z = space.call_function(w_method)
- else:
- w_method = space.lookup(w_complex, '__complex__')
- if w_method is not None:
- w_z = space.get_and_call_function(w_method, w_complex)
+ w_method = space.lookup(w_complex, '__complex__')
+ if w_method is not None:
+ w_z = space.get_and_call_function(w_method, w_complex)
#
if w_z is not None:
# __complex__() must return a complex object
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit