Commit 3742b81d authored by mattip's avatar mattip

merge heads

parents ddbe5e00 edfbc709
String formatting routines.
"""String formatting routines"""
import sys
from pypy.interpreter.error import OperationError, oefmt
from rpython.rlib import jit
from rpython.rlib.rfloat import formatd, DTSF_ALT, isnan, isinf
from rpython.rlib.rarithmetic import INT_MAX
from rpython.rlib.rfloat import DTSF_ALT, formatd, isnan, isinf
from rpython.rlib.rstring import StringBuilder, UnicodeBuilder
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib.rarithmetic import INT_MAX
from rpython.tool.sourcetools import func_with_new_name
from pypy.interpreter.error import OperationError, oefmt
class BaseStringFormatter(object):
def __init__(self, space, values_w, w_valuedict):
"""The builtin object type implementation"""
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import applevel, interp2app, unwrap_spec
from pypy.interpreter.typedef import GetSetProperty, default_identity_hash, TypeDef
from pypy.interpreter.typedef import (
GetSetProperty, TypeDef, default_identity_hash)
from pypy.objspace.descroperation import Object
......@@ -25,7 +28,7 @@ def reduce_2(obj):
args = getnewargs()
if not isinstance(args, tuple):
raise TypeError, "__getnewargs__ should return a tuple"
raise TypeError("__getnewargs__ should return a tuple")
getstate = obj.__getstate__
......@@ -46,15 +49,8 @@ def reduce_2(obj):
state = getstate()
if isinstance(obj, list):
listitems = iter(obj)
listitems = None
if isinstance(obj, dict):
dictitems = obj.iteritems()
dictitems = None
listitems = iter(obj) if isinstance(obj, list) else None
dictitems = obj.iteritems() if isinstance(obj, dict) else None
import copy_reg
newobj = copy_reg.__newobj__
......@@ -74,7 +70,7 @@ def slotnames(cls):
import copy_reg
slotnames = copy_reg._slotnames(cls)
if not isinstance(slotnames, list) and slotnames is not None:
raise TypeError, "copy_reg._slotnames didn't return a list or None"
raise TypeError("copy_reg._slotnames didn't return a list or None")
return slotnames
''', filename=__file__)
......@@ -94,14 +90,13 @@ def descr__new__(space, w_type, __args__):
# don't allow arguments if the default object.__init__() is about
# to be called
w_type = _precheck_for_new(space, w_type)
w_parentinit, w_ignored = w_type.lookup_where('__init__')
w_parentinit, _ = w_type.lookup_where('__init__')
if w_parentinit is space.w_object:
except ValueError:
raise OperationError(space.w_TypeError,
space.wrap("default __new__ takes "
"no parameters"))
raise oefmt(space.w_TypeError,
"default __new__ takes no parameters")
if w_type.is_abstract():
_abstract_method_error(space, w_type)
w_obj = space.allocate_instance(W_ObjectObject, w_type)
......@@ -120,8 +115,8 @@ def descr__init__(space, w_obj, __args__):
except ValueError:
raise OperationError(space.w_TypeError,
space.wrap("object.__init__() takes no parameters"))
raise oefmt(space.w_TypeError,
"object.__init__() takes no parameters")
def descr_get___class__(space, w_obj):
......@@ -135,11 +130,12 @@ def descr_set___class__(space, w_obj, w_newcls):
"__class__ must be set to new-style class, not '%T' "
"object", w_newcls)
if not w_newcls.is_heaptype():
raise OperationError(space.w_TypeError,
space.wrap("__class__ assignment: only for heap types"))
raise oefmt(space.w_TypeError,
"__class__ assignment: only for heap types")
w_oldcls = space.type(w_obj)
assert isinstance(w_oldcls, W_TypeObject)
if w_oldcls.get_full_instance_layout() == w_newcls.get_full_instance_layout():
if (w_oldcls.get_full_instance_layout() ==
w_obj.setclass(space, w_newcls)
raise oefmt(space.w_TypeError,
......@@ -167,8 +163,8 @@ def descr__str__(space, w_obj):
w_type = space.type(w_obj)
w_impl = w_type.lookup("__repr__")
if w_impl is None:
raise OperationError(space.w_TypeError, # can it really occur?
space.wrap("operand does not support unary str"))
# can it really occur?
raise oefmt(space.w_TypeError, "operand does not support unary str")
return space.get_and_call_function(w_impl, w_obj)
from pypy.interpreter.error import oefmt, OperationError
from rpython.rlib.rstring import InvalidBaseError
from pypy.interpreter.error import OperationError, oefmt
This diff is collapsed.
from rpython.annotator.description import ClassDesc
from rpython.annotator.description import ClassDesc, is_mixin
class FakeBookkeeper:
def __init__(self):
......@@ -20,3 +20,13 @@ def test_getcommonbase():
dC = bk.getdesc(C)
dD = bk.getdesc(D)
assert ClassDesc.getcommonbase([dC, dD]) is dA
def test_is_mixin():
class Mixin1(object):
_mixin_ = True
class A(Mixin1):
assert is_mixin(Mixin1)
assert not is_mixin(A)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment