[pypy-commit] pypy reflex-support: merge default into branch
wlav
noreply at buildbot.pypy.org
Mon Mar 25 23:44:29 CET 2013
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r62767:1c230df535d9
Date: 2013-03-25 13:18 -0700
http://bitbucket.org/pypy/pypy/changeset/1c230df535d9/
Log: merge default into branch
diff too long, truncating to 2000 out of 6369 lines
diff --git a/lib-python/2/pickle.py b/lib-python/2/pickle.py
--- a/lib-python/2/pickle.py
+++ b/lib-python/2/pickle.py
@@ -1409,26 +1409,11 @@
except ImportError:
from StringIO import StringIO
-try:
- from __pypy__.builders import StringBuilder
-except ImportError:
- assert '__pypy__' not in sys.builtin_module_names
- StringBuilderFile = StringIO
-else:
- class StringBuilderFile(object):
- ''' pickle uses only file.write - provide this method,
- use StringBuilder for speed
- '''
- def __init__(self):
- self.builder = StringBuilder()
- self.write = self.builder.append
- self.getvalue = self.builder.build
-
def dump(obj, file, protocol=None):
Pickler(file, protocol).dump(obj)
def dumps(obj, protocol=None):
- file = StringBuilderFile()
+ file = StringIO()
Pickler(file, protocol).dump(obj)
return file.getvalue()
diff --git a/lib_pypy/cPickle.py b/lib_pypy/cPickle.py
--- a/lib_pypy/cPickle.py
+++ b/lib_pypy/cPickle.py
@@ -97,18 +97,12 @@
from pickle import StringIO
-try:
- from pickle import StringBuilderFile
-except ImportError:
- assert '__pypy__' not in sys.builtin_module_names
- StringBuilderFile = StringIO
-
PythonPickler = Pickler
class Pickler(PythonPickler):
def __init__(self, *args, **kw):
self.__f = None
if len(args) == 1 and isinstance(args[0], int):
- self.__f = StringBuilderFile()
+ self.__f = StringIO()
PythonPickler.__init__(self, self.__f, args[0], **kw)
else:
PythonPickler.__init__(self, *args, **kw)
@@ -126,7 +120,7 @@
@builtinify
def dumps(obj, protocol=None):
- file = StringBuilderFile()
+ file = StringIO()
Pickler(file, protocol).dump(obj)
return file.getvalue()
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -189,11 +189,6 @@
BoolOption("withtproxy", "support transparent proxies",
default=True),
- BoolOption("withsmallint", "use tagged integers",
- default=False,
- requires=[("objspace.std.withprebuiltint", False),
- ("translation.taggedpointers", True)]),
-
BoolOption("withprebuiltint", "prebuild commonly used int objects",
default=False),
@@ -204,9 +199,7 @@
default=100, cmdline="--prebuiltintto"),
BoolOption("withsmalllong", "use a version of 'long' in a C long long",
- default=False,
- requires=[("objspace.std.withsmallint", False)]),
- # ^^^ because of missing delegate_xx2yy
+ default=False),
BoolOption("withstrbuf", "use strings optimized for addition (ver 2)",
default=False),
diff --git a/pypy/interpreter/astcompiler/test/test_astbuilder.py b/pypy/interpreter/astcompiler/test/test_astbuilder.py
--- a/pypy/interpreter/astcompiler/test/test_astbuilder.py
+++ b/pypy/interpreter/astcompiler/test/test_astbuilder.py
@@ -1144,7 +1144,7 @@
assert space.eq_w(get_num("-0"), space.wrap(0))
assert space.eq_w(get_num("-0xAAAAAAL"), space.wrap(-0xAAAAAAL))
n = get_num(str(-sys.maxint - 1))
- assert space.is_true(space.isinstance(n, space.w_int))
+ assert space.isinstance_w(n, space.w_int)
for num in ("0o53", "0O53", "0o0000053", "0O00053"):
assert space.eq_w(get_num(num), space.wrap(053))
for num in ("0b00101", "0B00101", "0b101", "0B101"):
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -211,6 +211,10 @@
raise OperationError(space.w_TypeError,
typed_unwrap_error_msg(space, "integer", self))
+ def float_w(self, space):
+ raise OperationError(space.w_TypeError,
+ typed_unwrap_error_msg(space, "float", self))
+
def uint_w(self, space):
raise OperationError(space.w_TypeError,
typed_unwrap_error_msg(space, "integer", self))
@@ -219,6 +223,22 @@
raise OperationError(space.w_TypeError,
typed_unwrap_error_msg(space, "integer", self))
+ def int(self, space):
+ w_impl = space.lookup(self, '__int__')
+ if w_impl is None:
+ typename = space.type(self).getname(space)
+ raise operationerrfmt(space.w_TypeError,
+ "unsupported operand type for int(): '%s'",
+ typename)
+ w_result = space.get_and_call_function(w_impl, self)
+
+ if (space.isinstance_w(w_result, space.w_int) or
+ space.isinstance_w(w_result, space.w_long)):
+ return w_result
+ typename = space.type(w_result).getname(space)
+ msg = "__int__ returned non-int (type '%s')"
+ raise operationerrfmt(space.w_TypeError, msg, typename)
+
def __spacebind__(self, space):
return self
@@ -257,18 +277,13 @@
def __init__(self, space):
Cache.__init__(self)
self.space = space
+
def _build(self, key):
- val = self.space.enter_cache_building_mode()
- try:
- return self.build(key)
- finally:
- self.space.leave_cache_building_mode(val)
+ return self.build(key)
+
def _ready(self, result):
- val = self.space.enter_cache_building_mode()
- try:
- return self.ready(result)
- finally:
- self.space.leave_cache_building_mode(val)
+ return self.ready(result)
+
def ready(self, result):
pass
@@ -557,11 +572,6 @@
"""NOT_RPYTHON: Abstract method that should put some minimal
content into the w_builtins."""
- def enter_cache_building_mode(self):
- "hook for the flow object space"
- def leave_cache_building_mode(self, val):
- "hook for the flow object space"
-
@jit.loop_invariant
def getexecutioncontext(self):
"Return what we consider to be the active execution context."
@@ -903,7 +913,7 @@
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)):
+ if self.isinstance_w(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
@@ -1031,9 +1041,6 @@
def issequence_w(self, w_obj):
return (self.findattr(w_obj, self.wrap("__getitem__")) is not None)
- def isinstance_w(self, w_obj, w_type):
- return self.is_true(self.isinstance(w_obj, w_type))
-
# The code below only works
# for the simple case (new-style instance).
# These methods are patched with the full logic by the __builtin__
@@ -1045,11 +1052,11 @@
def abstract_isinstance_w(self, w_obj, w_cls):
# Equivalent to 'isinstance(obj, cls)'.
- return self.is_true(self.isinstance(w_obj, w_cls))
+ return self.isinstance_w(w_obj, w_cls)
def abstract_isclass_w(self, w_obj):
# Equivalent to 'isinstance(obj, type)'.
- return self.is_true(self.isinstance(w_obj, self.w_type))
+ return self.isinstance_w(w_obj, self.w_type)
def abstract_getclass(self, w_obj):
# Equivalent to 'obj.__class__'.
@@ -1087,7 +1094,7 @@
expression = compiler.compile(expression, '?', 'eval', 0,
hidden_applevel=hidden_applevel)
else:
- raise TypeError, 'space.eval(): expected a string, code or PyCode object'
+ raise TypeError('space.eval(): expected a string, code or PyCode object')
return expression.exec_code(self, w_globals, w_locals)
def exec_(self, statement, w_globals, w_locals, hidden_applevel=False,
@@ -1101,7 +1108,7 @@
statement = compiler.compile(statement, filename, 'exec', 0,
hidden_applevel=hidden_applevel)
if not isinstance(statement, PyCode):
- raise TypeError, 'space.exec_(): expected a string, code or PyCode object'
+ raise TypeError('space.exec_(): expected a string, code or PyCode object')
w_key = self.wrap('__builtins__')
if not self.is_true(self.contains(w_globals, w_key)):
self.setitem(w_globals, w_key, self.wrap(self.builtin))
@@ -1157,7 +1164,7 @@
-> (index, 0, 0) or
(start, stop, step)
"""
- if self.is_true(self.isinstance(w_index_or_slice, self.w_slice)):
+ if self.isinstance_w(w_index_or_slice, self.w_slice):
from pypy.objspace.std.sliceobject import W_SliceObject
assert isinstance(w_index_or_slice, W_SliceObject)
start, stop, step = w_index_or_slice.indices3(self, seqlength)
@@ -1177,7 +1184,7 @@
-> (index, 0, 0, 1) or
(start, stop, step, slice_length)
"""
- if self.is_true(self.isinstance(w_index_or_slice, self.w_slice)):
+ if self.isinstance_w(w_index_or_slice, self.w_slice):
from pypy.objspace.std.sliceobject import W_SliceObject
assert isinstance(w_index_or_slice, W_SliceObject)
start, stop, step, length = w_index_or_slice.indices4(self,
@@ -1305,15 +1312,21 @@
def int_w(self, w_obj):
return w_obj.int_w(self)
+ def int(self, w_obj):
+ return w_obj.int(self)
+
def uint_w(self, w_obj):
return w_obj.uint_w(self)
def bigint_w(self, w_obj):
return w_obj.bigint_w(self)
+ def float_w(self, w_obj):
+ return w_obj.float_w(self)
+
def realstr_w(self, w_obj):
# Like str_w, but only works if w_obj is really of type 'str'.
- if not self.is_true(self.isinstance(w_obj, self.w_str)):
+ if not self.isinstance_w(w_obj, self.w_str):
raise OperationError(self.w_TypeError,
self.wrap('argument must be a string'))
return self.str_w(w_obj)
@@ -1333,7 +1346,7 @@
def realunicode_w(self, w_obj):
# Like unicode_w, but only works if w_obj is really of type
# 'unicode'.
- if not self.is_true(self.isinstance(w_obj, self.w_unicode)):
+ if not self.isinstance_w(w_obj, self.w_unicode):
raise OperationError(self.w_TypeError,
self.wrap('argument must be a unicode'))
return self.unicode_w(w_obj)
@@ -1345,7 +1358,7 @@
# This is all interface for gateway.py.
def gateway_int_w(self, w_obj):
- if self.is_true(self.isinstance(w_obj, self.w_float)):
+ if self.isinstance_w(w_obj, self.w_float):
raise OperationError(self.w_TypeError,
self.wrap("integer argument expected, got float"))
return self.int_w(self.int(w_obj))
@@ -1354,19 +1367,19 @@
return self.float_w(self.float(w_obj))
def gateway_r_longlong_w(self, w_obj):
- if self.is_true(self.isinstance(w_obj, self.w_float)):
+ if self.isinstance_w(w_obj, self.w_float):
raise OperationError(self.w_TypeError,
self.wrap("integer argument expected, got float"))
return self.r_longlong_w(self.int(w_obj))
def gateway_r_uint_w(self, w_obj):
- if self.is_true(self.isinstance(w_obj, self.w_float)):
+ if self.isinstance_w(w_obj, self.w_float):
raise OperationError(self.w_TypeError,
self.wrap("integer argument expected, got float"))
return self.uint_w(self.int(w_obj))
def gateway_r_ulonglong_w(self, w_obj):
- if self.is_true(self.isinstance(w_obj, self.w_float)):
+ if self.isinstance_w(w_obj, self.w_float):
raise OperationError(self.w_TypeError,
self.wrap("integer argument expected, got float"))
return self.r_ulonglong_w(self.int(w_obj))
@@ -1483,23 +1496,28 @@
space.exec_(str(source), w_glob, w_glob)
return space.getitem(w_glob, space.wrap('anonymous'))
+
class DummyLock(object):
def acquire(self, flag):
return True
+
def release(self):
pass
+
def _freeze_(self):
return True
+
def __enter__(self):
pass
+
def __exit__(self, *args):
pass
dummy_lock = DummyLock()
-## Table describing the regular part of the interface of object spaces,
-## namely all methods which only take w_ arguments and return a w_ result
-## (if any). Note: keep in sync with rpython.flowspace.operation.Table.
+# Table describing the regular part of the interface of object spaces,
+# namely all methods which only take w_ arguments and return a w_ result
+# (if any).
ObjSpace.MethodTable = [
# method name # symbol # number of arguments # special method name(s)
@@ -1526,7 +1544,7 @@
('pos', 'pos', 1, ['__pos__']),
('neg', 'neg', 1, ['__neg__']),
('nonzero', 'truth', 1, ['__nonzero__']),
- ('abs' , 'abs', 1, ['__abs__']),
+ ('abs', 'abs', 1, ['__abs__']),
('hex', 'hex', 1, ['__hex__']),
('oct', 'oct', 1, ['__oct__']),
('ord', 'ord', 1, []),
@@ -1579,12 +1597,12 @@
('delete', 'delete', 2, ['__delete__']),
('userdel', 'del', 1, ['__del__']),
('buffer', 'buffer', 1, ['__buffer__']), # see buffer.py
- ]
+]
ObjSpace.BuiltinModuleTable = [
'__builtin__',
'sys',
- ]
+]
ObjSpace.ConstantTable = [
'None',
@@ -1592,7 +1610,7 @@
'True',
'Ellipsis',
'NotImplemented',
- ]
+]
ObjSpace.ExceptionTable = [
'ArithmeticError',
@@ -1635,7 +1653,7 @@
'ZeroDivisionError',
'RuntimeWarning',
'PendingDeprecationWarning',
- ]
+]
if sys.platform.startswith("win"):
ObjSpace.ExceptionTable += ['WindowsError']
@@ -1673,4 +1691,4 @@
'newslice',
'call_args',
'marshal_w',
- ]
+]
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -183,7 +183,7 @@
#
w_type = self.w_type
w_value = self.get_w_value(space)
- while space.is_true(space.isinstance(w_type, space.w_tuple)):
+ while space.isinstance_w(w_type, space.w_tuple):
w_type = space.getitem(w_type, space.wrap(0))
if space.exception_is_valid_obj_as_class_w(w_type):
@@ -198,7 +198,7 @@
# raise Type, Instance: let etype be the exact type of value
w_type = w_valuetype
else:
- if space.is_true(space.isinstance(w_value, space.w_tuple)):
+ if space.isinstance_w(w_value, space.w_tuple):
# raise Type, tuple: assume the tuple contains the
# constructor args
w_value = space.call(w_type, w_value)
diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -208,7 +208,7 @@
def descr_function__new__(space, w_subtype, w_code, w_globals,
w_name=None, w_argdefs=None, w_closure=None):
code = space.interp_w(Code, w_code)
- if not space.is_true(space.isinstance(w_globals, space.w_dict)):
+ if not space.isinstance_w(w_globals, space.w_dict):
raise OperationError(space.w_TypeError, space.wrap("expected dict"))
if not space.is_none(w_name):
name = space.str_w(w_name)
@@ -356,7 +356,7 @@
if space.is_w(w_defaults, space.w_None):
self.defs_w = []
return
- if not space.is_true(space.isinstance(w_defaults, space.w_tuple)):
+ if not space.isinstance_w(w_defaults, space.w_tuple):
raise OperationError(space.w_TypeError, space.wrap("func_defaults must be set to a tuple object or None"))
self.defs_w = space.fixedview(w_defaults)
diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -81,7 +81,7 @@
def descr__reduce__(self, space):
w_name = space.finditem(self.w_dict, space.wrap('__name__'))
if (w_name is None or
- not space.is_true(space.isinstance(w_name, space.w_str))):
+ not space.isinstance_w(w_name, space.w_str)):
# maybe raise exception here (XXX this path is untested)
return space.w_None
w_modules = space.sys.get('modules')
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -232,7 +232,7 @@
def getdocstring(self, space):
if self.co_consts_w: # it is probably never empty
w_first = self.co_consts_w[0]
- if space.is_true(space.isinstance(w_first, space.w_basestring)):
+ if space.isinstance_w(w_first, space.w_basestring):
return w_first
return space.w_None
@@ -246,20 +246,20 @@
else:
consts[num] = self.space.unwrap(w)
num += 1
- return new.code( self.co_argcount,
- self.co_nlocals,
- self.co_stacksize,
- self.co_flags,
- self.co_code,
- tuple(consts),
- tuple(self.co_names),
- tuple(self.co_varnames),
- self.co_filename,
- self.co_name,
- self.co_firstlineno,
- self.co_lnotab,
- tuple(self.co_freevars),
- tuple(self.co_cellvars) )
+ return new.code(self.co_argcount,
+ self.co_nlocals,
+ self.co_stacksize,
+ self.co_flags,
+ self.co_code,
+ tuple(consts),
+ tuple(self.co_names),
+ tuple(self.co_varnames),
+ self.co_filename,
+ self.co_name,
+ self.co_firstlineno,
+ self.co_lnotab,
+ tuple(self.co_freevars),
+ tuple(self.co_cellvars))
def exec_host_bytecode(self, w_globals, w_locals):
from pypy.interpreter.pyframe import CPythonFrame
@@ -349,12 +349,12 @@
if nlocals < 0:
raise OperationError(space.w_ValueError,
space.wrap("code: nlocals must not be negative"))
- if not space.is_true(space.isinstance(w_constants, space.w_tuple)):
+ if not space.isinstance_w(w_constants, space.w_tuple):
raise OperationError(space.w_TypeError,
space.wrap("Expected tuple for constants"))
- consts_w = space.fixedview(w_constants)
- names = unpack_str_tuple(space, w_names)
- varnames = unpack_str_tuple(space, w_varnames)
+ consts_w = space.fixedview(w_constants)
+ names = unpack_str_tuple(space, w_names)
+ varnames = unpack_str_tuple(space, w_varnames)
if w_freevars is not None:
freevars = unpack_str_tuple(space, w_freevars)
else:
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -777,12 +777,12 @@
@jit.unroll_safe
def cmp_exc_match(self, w_1, w_2):
space = self.space
- if space.is_true(space.isinstance(w_2, space.w_tuple)):
+ if space.isinstance_w(w_2, space.w_tuple):
for w_t in space.fixedview(w_2):
- if space.is_true(space.isinstance(w_t, space.w_str)):
+ if space.isinstance_w(w_t, space.w_str):
msg = "catching of string exceptions is deprecated"
space.warn(space.wrap(msg), space.w_DeprecationWarning)
- elif space.is_true(space.isinstance(w_2, space.w_str)):
+ elif space.isinstance_w(w_2, space.w_str):
msg = "catching of string exceptions is deprecated"
space.warn(space.wrap(msg), space.w_DeprecationWarning)
return space.newbool(space.exception_match(w_1, w_2))
@@ -796,7 +796,7 @@
w_result = getattr(self, attr)(w_1, w_2)
break
else:
- raise BytecodeCorruption, "bad COMPARE_OP oparg"
+ raise BytecodeCorruption("bad COMPARE_OP oparg")
self.pushvalue(w_result)
def IMPORT_NAME(self, nameindex, next_instr):
diff --git a/pypy/interpreter/pytraceback.py b/pypy/interpreter/pytraceback.py
--- a/pypy/interpreter/pytraceback.py
+++ b/pypy/interpreter/pytraceback.py
@@ -61,7 +61,6 @@
def check_traceback(space, w_tb, msg):
from pypy.interpreter.typedef import PyTraceback
- if w_tb is None or not space.is_true(space.isinstance(w_tb,
- space.gettypeobject(PyTraceback.typedef))):
+ if w_tb is None or not space.isinstance_w(w_tb, space.gettypeobject(PyTraceback.typedef)):
raise OperationError(space.w_TypeError, space.wrap(msg))
return w_tb
diff --git a/pypy/interpreter/test/test_gateway.py b/pypy/interpreter/test/test_gateway.py
--- a/pypy/interpreter/test/test_gateway.py
+++ b/pypy/interpreter/test/test_gateway.py
@@ -24,8 +24,12 @@
assert code.signature() == Signature(['x', 'y'], 'hello', None)
def d(self, w_boo):
pass
+
+ class W_X(W_Root):
+ pass
+
code = gateway.BuiltinCode(d, unwrap_spec= ['self',
- gateway.W_Root], self_type=gateway.W_Root)
+ gateway.W_Root], self_type=W_X)
assert code.signature() == Signature(['self', 'boo'], None, None)
def e(space, w_x, w_y, __args__):
pass
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -342,7 +342,7 @@
# a couple of helpers for the Proto classes above, factored out to reduce
# the translated code size
def check_new_dictionary(space, w_dict):
- if not space.is_true(space.isinstance(w_dict, space.w_dict)):
+ if not space.isinstance_w(w_dict, space.w_dict):
raise OperationError(space.w_TypeError,
space.wrap("setting dictionary to a non-dict"))
from pypy.objspace.std import dictmultiobject
@@ -552,7 +552,7 @@
self.w_cls = w_cls
def typecheck(self, space, w_obj):
- if not space.is_true(space.isinstance(w_obj, self.w_cls)):
+ if not space.isinstance_w(w_obj, self.w_cls):
raise operationerrfmt(space.w_TypeError,
"descriptor '%s' for '%s'"
" objects doesn't apply to '%s' object",
diff --git a/pypy/module/__builtin__/__init__.py b/pypy/module/__builtin__/__init__.py
--- a/pypy/module/__builtin__/__init__.py
+++ b/pypy/module/__builtin__/__init__.py
@@ -114,7 +114,7 @@
else:
if w_builtin is space.builtin: # common case
return space.builtin
- if space.is_true(space.isinstance(w_builtin, space.w_dict)):
+ if space.isinstance_w(w_builtin, space.w_dict):
return module.Module(space, None, w_builtin)
if isinstance(w_builtin, module.Module):
return w_builtin
diff --git a/pypy/module/__builtin__/abstractinst.py b/pypy/module/__builtin__/abstractinst.py
--- a/pypy/module/__builtin__/abstractinst.py
+++ b/pypy/module/__builtin__/abstractinst.py
@@ -8,10 +8,12 @@
"""
from rpython.rlib import jit
+
+from pypy.interpreter.baseobjspace import ObjSpace as BaseObjSpace
from pypy.interpreter.error import OperationError
from pypy.module.__builtin__.interp_classobj import W_ClassObject
from pypy.module.__builtin__.interp_classobj import W_InstanceObject
-from pypy.interpreter.baseobjspace import ObjSpace as BaseObjSpace
+
def _get_bases(space, w_cls):
"""Returns 'cls.__bases__'. Returns None if there is
@@ -23,7 +25,7 @@
if not e.match(space, space.w_AttributeError):
raise # propagate other errors
return None
- if space.is_true(space.isinstance(w_bases, space.w_tuple)):
+ if space.isinstance_w(w_bases, space.w_tuple):
return w_bases
else:
return None
@@ -47,10 +49,9 @@
@jit.unroll_safe
def abstract_isinstance_w(space, w_obj, w_klass_or_tuple, allow_override=False):
"""Implementation for the full 'isinstance(obj, klass_or_tuple)'."""
-
# -- case (anything, tuple)
# XXX it might be risky that the JIT sees this
- if space.is_true(space.isinstance(w_klass_or_tuple, space.w_tuple)):
+ if space.isinstance_w(w_klass_or_tuple, space.w_tuple):
for w_klass in space.fixedview(w_klass_or_tuple):
if abstract_isinstance_w(space, w_obj, w_klass, allow_override):
return True
@@ -129,8 +130,7 @@
"""Implementation for the full 'issubclass(derived, klass_or_tuple)'."""
# -- case (class-like-object, tuple-of-classes)
- # XXX it might be risky that the JIT sees this
- if space.is_true(space.isinstance(w_klass_or_tuple, space.w_tuple)):
+ if space.isinstance_w(w_klass_or_tuple, space.w_tuple):
for w_klass in space.fixedview(w_klass_or_tuple):
if abstract_issubclass_w(space, w_derived, w_klass, allow_override):
return True
diff --git a/pypy/module/__builtin__/compiling.py b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -7,6 +7,7 @@
from pypy.interpreter.astcompiler import consts, ast
from pypy.interpreter.gateway import unwrap_spec
+
@unwrap_spec(filename=str, mode=str, flags=int, dont_inherit=int)
def compile(space, w_source, filename, mode, flags=0, dont_inherit=0):
"""Compile the source string (a Python module, statement or expression)
@@ -25,10 +26,10 @@
ast_node = None
w_ast_type = space.gettypeobject(ast.AST.typedef)
str_ = None
- if space.is_true(space.isinstance(w_source, w_ast_type)):
+ if space.isinstance_w(w_source, w_ast_type):
ast_node = space.interp_w(ast.mod, w_source)
ast_node.sync_app_attrs(space)
- elif space.is_true(space.isinstance(w_source, space.w_unicode)):
+ elif space.isinstance_w(w_source, space.w_unicode):
w_utf_8_source = space.call_method(w_source, "encode",
space.wrap("utf-8"))
str_ = space.str_w(w_utf_8_source)
@@ -72,8 +73,8 @@
"""
w = space.wrap
- if (space.is_true(space.isinstance(w_code, space.w_str)) or
- space.is_true(space.isinstance(w_code, space.w_unicode))):
+ if (space.isinstance_w(w_code, space.w_str) or
+ space.isinstance_w(w_code, space.w_unicode)):
w_code = compile(space,
space.call_method(w_code, 'lstrip',
space.wrap(' \t')),
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
@@ -47,7 +47,8 @@
n = 0
return n
- at unwrap_spec(w_step = WrappedDefault(1))
+
+ at unwrap_spec(w_step=WrappedDefault(1))
def range_int(space, w_x, w_y=None, w_step=None):
"""Return a list of integers in arithmetic position from start (defaults
to zero) to stop - 1 by step (defaults to 1). Use a negative step to
@@ -60,24 +61,24 @@
w_start = w_x
w_stop = w_y
- if space.is_true(space.isinstance(w_stop, space.w_float)):
+ if space.isinstance_w(w_stop, space.w_float):
raise OperationError(space.w_TypeError,
space.wrap("range() integer end argument expected, got float."))
- if space.is_true(space.isinstance(w_start, space.w_float)):
+ if space.isinstance_w(w_start, space.w_float):
raise OperationError(space.w_TypeError,
space.wrap("range() integer start argument expected, got float."))
- if space.is_true(space.isinstance(w_step, space.w_float)):
+ if space.isinstance_w(w_step, space.w_float):
raise OperationError(space.w_TypeError,
space.wrap("range() integer step argument expected, got float."))
w_start = space.int(w_start)
- w_stop = space.int(w_stop)
- w_step = space.int(w_step)
+ w_stop = space.int(w_stop)
+ w_step = space.int(w_step)
try:
start = space.int_w(w_start)
- stop = space.int_w(w_stop)
- step = space.int_w(w_step)
+ stop = space.int_w(w_stop)
+ step = space.int_w(w_step)
except OperationError, e:
if not e.match(space, space.w_OverflowError):
raise
@@ -107,7 +108,7 @@
start = lo = space.bigint_w(w_start)
hi = space.bigint_w(w_stop)
- step = st = space.bigint_w(w_step)
+ step = st = space.bigint_w(w_step)
if not step.tobool():
raise OperationError(space.w_ValueError,
@@ -201,8 +202,8 @@
@specialize.arg(2)
def min_max(space, args, implementation_of):
- if not jit.we_are_jitted() or (jit.isconstant(len(args.arguments_w)) and
- len(args.arguments_w) == 2):
+ if not jit.we_are_jitted() or len(args.arguments_w) != 1 and \
+ jit.loop_unrolling_heuristic(args.arguments_w, len(args.arguments_w)):
return min_max_unroll(space, args, implementation_of)
else:
return min_max_normal(space, args, implementation_of)
diff --git a/pypy/module/__builtin__/interp_classobj.py b/pypy/module/__builtin__/interp_classobj.py
--- a/pypy/module/__builtin__/interp_classobj.py
+++ b/pypy/module/__builtin__/interp_classobj.py
@@ -25,10 +25,10 @@
# XXX it's not clear that we have to catch the TypeError...
def descr_classobj_new(space, w_subtype, w_name, w_bases, w_dict):
- if not space.is_true(space.isinstance(w_bases, space.w_tuple)):
+ if not space.isinstance_w(w_bases, space.w_tuple):
raise_type_err(space, 'bases', 'tuple', w_bases)
- if not space.is_true(space.isinstance(w_dict, space.w_dict)):
+ if not space.isinstance_w(w_dict, space.w_dict):
raise_type_err(space, 'bases', 'tuple', w_bases)
if not space.is_true(space.contains(w_dict, space.wrap("__doc__"))):
@@ -68,27 +68,24 @@
return self.w_dict
def setdict(self, space, w_dict):
- if not space.is_true(space.isinstance(w_dict, space.w_dict)):
+ if not space.isinstance_w(w_dict, space.w_dict):
raise OperationError(
space.w_TypeError,
space.wrap("__dict__ must be a dictionary object"))
self.w_dict = w_dict
def setname(self, space, w_newname):
- if not space.is_true(space.isinstance(w_newname, space.w_str)):
- raise OperationError(
- space.w_TypeError,
- space.wrap("__name__ must be a string object"))
+ if not space.isinstance_w(w_newname, space.w_str):
+ raise OperationError(space.w_TypeError,
+ space.wrap("__name__ must be a string object")
+ )
self.name = space.str_w(w_newname)
def setbases(self, space, w_bases):
- # XXX in theory, this misses a check against inheritance cycles
- # although on pypy we don't get a segfault for infinite
- # recursion anyway
- if not space.is_true(space.isinstance(w_bases, space.w_tuple)):
- raise OperationError(
- space.w_TypeError,
- space.wrap("__bases__ must be a tuple object"))
+ if not space.isinstance_w(w_bases, space.w_tuple):
+ raise OperationError(space.w_TypeError,
+ space.wrap("__bases__ must be a tuple object")
+ )
bases_w = space.fixedview(w_bases)
for w_base in bases_w:
if not isinstance(w_base, W_ClassObject):
@@ -194,7 +191,7 @@
if not e.match(space, space.w_AttributeError):
raise
return "?"
- if space.is_true(space.isinstance(w_mod, space.w_str)):
+ if space.isinstance_w(w_mod, space.w_str):
return space.str_w(w_mod)
return "?"
@@ -464,7 +461,7 @@
def descr_len(self, space):
w_meth = self.getattr(space, '__len__')
w_result = space.call_function(w_meth)
- if space.is_true(space.isinstance(w_result, space.w_int)):
+ if space.isinstance_w(w_result, space.w_int):
if space.is_true(space.lt(w_result, space.wrap(0))):
raise OperationError(
space.w_ValueError,
@@ -532,7 +529,7 @@
if w_func is None:
return space.w_True
w_result = space.call_function(w_func)
- if space.is_true(space.isinstance(w_result, space.w_int)):
+ if space.isinstance_w(w_result, space.w_int):
if space.is_true(space.lt(w_result, space.wrap(0))):
raise OperationError(
space.w_ValueError,
@@ -594,16 +591,16 @@
def descr_hash(self, space):
w_func = self.getattr(space, '__hash__', False)
if w_func is None:
- w_eq = self.getattr(space, '__eq__', False)
- w_cmp = self.getattr(space, '__cmp__', False)
+ w_eq = self.getattr(space, '__eq__', False)
+ w_cmp = self.getattr(space, '__cmp__', False)
if w_eq is not None or w_cmp is not None:
raise OperationError(space.w_TypeError,
space.wrap("unhashable instance"))
else:
return space.wrap(compute_identity_hash(self))
w_ret = space.call_function(w_func)
- if (not space.is_true(space.isinstance(w_ret, space.w_int)) and
- not space.is_true(space.isinstance(w_ret, space.w_long))):
+ if (not space.isinstance_w(w_ret, space.w_int) and
+ not space.isinstance_w(w_ret, space.w_long)):
raise OperationError(
space.w_TypeError,
space.wrap("__hash__ must return int or long"))
@@ -654,7 +651,6 @@
if space.eq_w(w_x, w_obj):
return space.w_True
-
def descr_pow(self, space, w_other, w_modulo=None):
if space.is_none(w_modulo):
w_a, w_b = _coerce_helper(space, self, w_other)
diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -56,13 +56,13 @@
def nonzero(self):
return self.space.wrap(bool(self._cdata))
- def int(self):
- w_result = self.ctype.int(self._cdata)
+ def int(self, space):
+ w_result = self.ctype.cast_to_int(self._cdata)
keepalive_until_here(self)
return w_result
- def long(self):
- w_result = self.int()
+ def long(self, space):
+ w_result = self.int(space)
space = self.space
if space.is_w(space.type(w_result), space.w_int):
w_result = space.newlong(space.int_w(w_result))
diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -54,7 +54,7 @@
raise operationerrfmt(space.w_TypeError,
"cannot cast to '%s'", self.name)
- def int(self, cdata):
+ def cast_to_int(self, cdata):
space = self.space
raise operationerrfmt(space.w_TypeError,
"int() not supported on cdata '%s'", self.name)
diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -99,7 +99,7 @@
_attrs_ = []
cast_anything = True
- def int(self, cdata):
+ def cast_to_int(self, cdata):
return self.space.wrap(ord(cdata[0]))
def convert_to_object(self, cdata):
@@ -124,7 +124,7 @@
class W_CTypePrimitiveUniChar(W_CTypePrimitiveCharOrUniChar):
_attrs_ = []
- def int(self, cdata):
+ def cast_to_int(self, cdata):
unichardata = rffi.cast(rffi.CWCHARP, cdata)
return self.space.wrap(ord(unichardata[0]))
@@ -168,7 +168,7 @@
self.vmin = r_uint(-1) << (sh - 1)
self.vrangemax = (r_uint(1) << sh) - 1
- def int(self, cdata):
+ def cast_to_int(self, cdata):
return self.convert_to_object(cdata)
def convert_to_object(self, cdata):
@@ -213,7 +213,7 @@
sh = self.size * 8
return (r_uint(1) << sh) - 1
- def int(self, cdata):
+ def cast_to_int(self, cdata):
return self.convert_to_object(cdata)
def convert_from_object(self, cdata, w_ob):
@@ -288,7 +288,7 @@
keepalive_until_here(w_cdata)
return w_cdata
- def int(self, cdata):
+ def cast_to_int(self, cdata):
w_value = self.float(cdata)
return self.space.int(w_value)
diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -3,6 +3,7 @@
from rpython.rlib.rstring import UnicodeBuilder
from rpython.rlib.objectmodel import we_are_translated
+
class CodecState(object):
def __init__(self, space):
self.codec_search_path = []
@@ -35,11 +36,11 @@
space.wrap(endpos),
space.wrap(reason))
w_res = space.call_function(w_errorhandler, w_exc)
- if (not space.is_true(space.isinstance(w_res, space.w_tuple))
+ if (not space.isinstance_w(w_res, space.w_tuple)
or space.len_w(w_res) != 2
- or not space.is_true(space.isinstance(
+ or not space.isinstance_w(
space.getitem(w_res, space.wrap(0)),
- space.w_unicode))):
+ space.w_unicode)):
if decode:
msg = ("decoding error handler must return "
"(unicode, int) tuple, not %s")
@@ -135,8 +136,7 @@
w_result = space.call_function(w_search,
space.wrap(normalized_encoding))
if not space.is_w(w_result, space.w_None):
- if not (space.is_true(space.isinstance(w_result,
- space.w_tuple)) and
+ if not (space.isinstance_w(w_result, space.w_tuple) and
space.len_w(w_result) == 4):
raise OperationError(
space.w_TypeError,
@@ -322,8 +322,7 @@
w_decoder = space.getitem(lookup_codec(space, encoding), space.wrap(1))
if space.is_true(w_decoder):
w_res = space.call_function(w_decoder, w_obj, space.wrap(errors))
- if (not space.is_true(space.isinstance(w_res, space.w_tuple))
- or space.len_w(w_res) != 2):
+ if (not space.isinstance_w(w_res, space.w_tuple) or space.len_w(w_res) != 2):
raise OperationError(
space.w_TypeError,
space.wrap("encoder must return a tuple (object, integer)"))
@@ -493,7 +492,7 @@
self.w_mapping = w_mapping
# fast path for all the stuff in the encodings module
- if space.is_true(space.isinstance(w_mapping, space.w_tuple)):
+ if space.isinstance_w(w_mapping, space.w_tuple):
self.mapping_w = space.fixedview(w_mapping)
else:
self.mapping_w = None
diff --git a/pypy/module/_locale/interp_locale.py b/pypy/module/_locale/interp_locale.py
--- a/pypy/module/_locale/interp_locale.py
+++ b/pypy/module/_locale/interp_locale.py
@@ -118,11 +118,12 @@
_strcoll = rlocale.external('strcoll', [rffi.CCHARP, rffi.CCHARP], rffi.INT)
_wcscoll = rlocale.external('wcscoll', [rffi.CWCHARP, rffi.CWCHARP], rffi.INT)
+
def strcoll(space, w_s1, w_s2):
"string,string -> int. Compares two strings according to the locale."
- if space.is_true(space.isinstance(w_s1, space.w_str)) and \
- space.is_true(space.isinstance(w_s2, space.w_str)):
+ if (space.isinstance_w(w_s1, space.w_str) and
+ space.isinstance_w(w_s2, space.w_str)):
s1, s2 = space.str_w(w_s1), space.str_w(w_s2)
s1_c = rffi.str2charp(s1)
@@ -133,11 +134,6 @@
rffi.free_charp(s1_c)
rffi.free_charp(s2_c)
- #if not space.is_true(space.isinstance(w_s1, space.w_unicode)) and \
- # not space.is_true(space.isinstance(w_s2, space.w_unicode)):
- # raise OperationError(space.w_ValueError,
- # space.wrap("strcoll arguments must be strings"))
-
s1, s2 = space.unicode_w(w_s1), space.unicode_w(w_s2)
s1_c = rffi.unicode2wcharp(s1)
diff --git a/pypy/module/_random/interp_random.py b/pypy/module/_random/interp_random.py
--- a/pypy/module/_random/interp_random.py
+++ b/pypy/module/_random/interp_random.py
@@ -28,9 +28,9 @@
if w_n is None:
w_n = space.newint(int(time.time()))
else:
- if space.is_true(space.isinstance(w_n, space.w_int)):
+ if space.isinstance_w(w_n, space.w_int):
w_n = space.abs(w_n)
- elif space.is_true(space.isinstance(w_n, space.w_long)):
+ elif space.isinstance_w(w_n, space.w_long):
w_n = space.abs(w_n)
else:
# XXX not perfectly like CPython
@@ -59,7 +59,7 @@
return space.newtuple(state)
def setstate(self, space, w_state):
- if not space.is_true(space.isinstance(w_state, space.w_tuple)):
+ if not space.isinstance_w(w_state, space.w_tuple):
errstring = space.wrap("state vector must be tuple")
raise OperationError(space.w_TypeError, errstring)
if space.len_w(w_state) != rrandom.N + 1:
@@ -78,7 +78,7 @@
self._rnd.index = space.int_w(w_item)
def jumpahead(self, space, w_n):
- if space.is_true(space.isinstance(w_n, space.w_long)):
+ if space.isinstance_w(w_n, space.w_long):
num = space.bigint_w(w_n)
n = intmask(num.uintmask())
else:
diff --git a/pypy/module/_rawffi/array.py b/pypy/module/_rawffi/array.py
--- a/pypy/module/_rawffi/array.py
+++ b/pypy/module/_rawffi/array.py
@@ -163,7 +163,7 @@
return itemsize * self.length
def decodeslice(self, space, w_slice):
- if not space.is_true(space.isinstance(w_slice, space.w_slice)):
+ if not space.isinstance_w(w_slice, space.w_slice):
raise OperationError(space.w_TypeError,
space.wrap('index must be int or slice'))
letter = self.shape.itemcode
diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -91,7 +91,7 @@
def unpack_simple_shape(space, w_shape):
# 'w_shape' must be either a letter or a tuple (struct, 1).
- if space.is_true(space.isinstance(w_shape, space.w_str)):
+ if space.isinstance_w(w_shape, space.w_str):
letter = space.str_w(w_shape)
return letter2tp(space, letter)
else:
@@ -102,7 +102,7 @@
def unpack_shape_with_length(space, w_shape):
# Allow 'w_shape' to be a letter or any (shape, number).
# The result is always a W_Array.
- if space.is_true(space.isinstance(w_shape, space.w_str)):
+ if space.isinstance_w(w_shape, space.w_str):
letter = space.str_w(w_shape)
return letter2tp(space, letter)
else:
@@ -171,7 +171,7 @@
else:
ffi_restype = ffi_type_void
- if space.is_true(space.isinstance(w_name, space.w_str)):
+ if space.isinstance_w(w_name, space.w_str):
name = space.str_w(w_name)
try:
@@ -183,8 +183,7 @@
except LibFFIError:
raise got_libffi_error(space)
- elif (_MS_WINDOWS and
- space.is_true(space.isinstance(w_name, space.w_int))):
+ elif (_MS_WINDOWS and space.isinstance_w(w_name, space.w_int)):
ordinal = space.int_w(w_name)
try:
ptr = self.cdll.getrawpointer_byordinal(ordinal, ffi_argtypes,
@@ -311,12 +310,13 @@
raise NotImplementedError("abstract base class")
def unwrap_truncate_int(TP, space, w_arg):
- if space.is_true(space.isinstance(w_arg, space.w_int)):
+ if space.isinstance_w(w_arg, space.w_int):
return rffi.cast(TP, space.int_w(w_arg))
else:
return rffi.cast(TP, space.bigint_w(w_arg).ulonglongmask())
unwrap_truncate_int._annspecialcase_ = 'specialize:arg(0)'
+
def unwrap_value(space, push_func, add_arg, argdesc, letter, w_arg):
w = space.wrap
if letter in TYPEMAP_PTR_LETTERS:
diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py
--- a/pypy/module/_rawffi/structure.py
+++ b/pypy/module/_rawffi/structure.py
@@ -32,7 +32,7 @@
name = space.str_w(l_w[0])
except OperationError:
raise OperationError(space.w_TypeError, space.wrap(
- "structure field name must be string not %s" %
+ "structure field name must be string not %s" %
space.type(l_w[0]).getname(space)))
tp = unpack_shape_with_length(space, l_w[1])
@@ -153,7 +153,7 @@
bitsizes = None
self.fields = fields
self.size = size
- self.alignment = alignment
+ self.alignment = alignment
self.ll_positions = pos
self.ll_bitsizes = bitsizes
self.name_to_index = name_to_index
@@ -223,11 +223,10 @@
self.alignment,
fieldtypes)
return self.ffi_struct.ffistruct
-
+
def __del__(self):
if self.ffi_struct:
lltype.free(self.ffi_struct, flavor='raw')
-
@unwrap_spec(union=bool, pack=int)
@@ -236,7 +235,7 @@
raise OperationError(space.w_ValueError, space.wrap(
"_pack_ must be a non-negative integer"))
- if space.is_true(space.isinstance(w_shapeinfo, space.w_tuple)):
+ if space.isinstance_w(w_shapeinfo, space.w_tuple):
w_size, w_alignment = space.fixedview(w_shapeinfo, expected_length=2)
S = W_Structure(space, None, space.int_w(w_size),
space.int_w(w_alignment), union)
@@ -372,7 +371,7 @@
def __del__(self):
if self.ll_buffer:
self._free()
-
+
W_StructureInstanceAutoFree.typedef = TypeDef(
'StructureInstanceAutoFree',
__repr__ = interp2app(W_StructureInstance.descr_repr),
diff --git a/pypy/module/_socket/interp_func.py b/pypy/module/_socket/interp_func.py
--- a/pypy/module/_socket/interp_func.py
+++ b/pypy/module/_socket/interp_func.py
@@ -255,9 +255,9 @@
# host can be None, string or unicode
if space.is_w(w_host, space.w_None):
host = None
- elif space.is_true(space.isinstance(w_host, space.w_str)):
+ elif space.isinstance_w(w_host, space.w_str):
host = space.str_w(w_host)
- elif space.is_true(space.isinstance(w_host, space.w_unicode)):
+ elif space.isinstance_w(w_host, space.w_unicode):
w_shost = space.call_method(w_host, "encode", space.wrap("idna"))
host = space.str_w(w_shost)
else:
@@ -268,9 +268,9 @@
# port can be None, int or string
if space.is_w(w_port, space.w_None):
port = None
- elif space.is_true(space.isinstance(w_port, space.w_int)):
+ elif space.isinstance_w(w_port, space.w_int):
port = str(space.int_w(w_port))
- elif space.is_true(space.isinstance(w_port, space.w_str)):
+ elif space.isinstance_w(w_port, space.w_str):
port = space.str_w(w_port)
else:
raise OperationError(space.w_TypeError,
diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -32,7 +32,19 @@
assert space.unwrap(ip) == socket.gethostbyname_ex(host)
def test_gethostbyaddr():
+ try:
+ socket.gethostbyaddr("::1")
+ except socket.herror:
+ ipv6 = False
+ else:
+ ipv6 = True
for host in ["localhost", "127.0.0.1", "::1"]:
+ if host == "::1" and not ipv6:
+ from pypy.interpreter.error import OperationError
+ with py.test.raises(OperationError):
+ space.appexec([w_socket, space.wrap(host)],
+ "(_socket, host): return _socket.gethostbyaddr(host)")
+ continue
ip = space.appexec([w_socket, space.wrap(host)],
"(_socket, host): return _socket.gethostbyaddr(host)")
assert space.unwrap(ip) == socket.gethostbyaddr(host)
@@ -219,7 +231,7 @@
"(_socket, host, port): return _socket.getaddrinfo(host, port)")
assert space.unwrap(w_l) == info
-def test_unknown_addr_as_object():
+def test_unknown_addr_as_object():
from pypy.module._socket.interp_socket import addr_as_object
c_addr = lltype.malloc(rsocket._c.sockaddr, flavor='raw')
c_addr.c_sa_data[0] = 'c'
@@ -228,7 +240,7 @@
# to be short enough so we have some data, 1 sounds good enough
# + sizeof USHORT
w_obj = addr_as_object(rsocket.Address(c_addr, 1 + 2), -1, space)
- assert space.is_true(space.isinstance(w_obj, space.w_tuple))
+ assert space.isinstance_w(w_obj, space.w_tuple)
assert space.int_w(space.getitem(w_obj, space.wrap(0))) == 15
assert space.str_w(space.getitem(w_obj, space.wrap(1))) == 'c'
diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py
--- a/pypy/module/_sre/interp_sre.py
+++ b/pypy/module/_sre/interp_sre.py
@@ -101,18 +101,24 @@
"""Make a StrMatchContext or a UnicodeMatchContext for searching
in the given w_string object."""
space = self.space
- if pos < 0: pos = 0
- if endpos < pos: endpos = pos
- if space.is_true(space.isinstance(w_string, space.w_unicode)):
+ if pos < 0:
+ pos = 0
+ if endpos < pos:
+ endpos = pos
+ if space.isinstance_w(w_string, space.w_unicode):
unicodestr = space.unicode_w(w_string)
- if pos > len(unicodestr): pos = len(unicodestr)
- if endpos > len(unicodestr): endpos = len(unicodestr)
+ if pos > len(unicodestr):
+ pos = len(unicodestr)
+ if endpos > len(unicodestr):
+ endpos = len(unicodestr)
return rsre_core.UnicodeMatchContext(self.code, unicodestr,
pos, endpos, self.flags)
else:
str = space.bufferstr_w(w_string)
- if pos > len(str): pos = len(str)
- if endpos > len(str): endpos = len(str)
+ if pos > len(str):
+ pos = len(str)
+ if endpos > len(str):
+ endpos = len(str)
return rsre_core.StrMatchContext(self.code, str,
pos, endpos, self.flags)
@@ -212,7 +218,7 @@
w_filter = w_ptemplate
filter_is_callable = True
else:
- if space.is_true(space.isinstance(w_ptemplate, space.w_unicode)):
+ if space.isinstance_w(w_ptemplate, space.w_unicode):
filter_as_unicode = space.unicode_w(w_ptemplate)
literal = u'\\' not in filter_as_unicode
else:
@@ -267,7 +273,7 @@
sublist_w.append(slice_w(space, ctx, last_pos, ctx.end,
space.w_None))
- if space.is_true(space.isinstance(w_string, space.w_unicode)):
+ if space.isinstance_w(w_string, space.w_unicode):
w_emptystr = space.wrap(u'')
else:
w_emptystr = space.wrap('')
@@ -381,15 +387,15 @@
return space.call_method(w_re, '_expand', space.wrap(self.srepat),
space.wrap(self), w_template)
- @unwrap_spec(w_groupnum = WrappedDefault(0))
+ @unwrap_spec(w_groupnum=WrappedDefault(0))
def start_w(self, w_groupnum):
return self.space.wrap(self.do_span(w_groupnum)[0])
- @unwrap_spec(w_groupnum = WrappedDefault(0))
+ @unwrap_spec(w_groupnum=WrappedDefault(0))
def end_w(self, w_groupnum):
return self.space.wrap(self.do_span(w_groupnum)[1])
- @unwrap_spec(w_groupnum = WrappedDefault(0))
+ @unwrap_spec(w_groupnum=WrappedDefault(0))
def span_w(self, w_groupnum):
start, end = self.do_span(w_groupnum)
return self.space.newtuple([self.space.wrap(start),
diff --git a/pypy/module/_weakref/interp__weakref.py b/pypy/module/_weakref/interp__weakref.py
--- a/pypy/module/_weakref/interp__weakref.py
+++ b/pypy/module/_weakref/interp__weakref.py
@@ -92,8 +92,7 @@
w_weakreftype = space.gettypeobject(W_Weakref.typedef)
for wref in self.other_refs_weak.items():
w_ref = wref()
- if (w_ref is not None and
- space.is_true(space.isinstance(w_ref, w_weakreftype))):
+ if (w_ref is not None and space.isinstance_w(w_ref, w_weakreftype)):
return w_ref
return space.w_None
@@ -103,8 +102,8 @@
def __init__(self, space, oldlifeline=None):
self.space = space
if oldlifeline is not None:
- self.cached_weakref = oldlifeline.cached_weakref
- self.cached_proxy = oldlifeline.cached_proxy
+ self.cached_weakref = oldlifeline.cached_weakref
+ self.cached_proxy = oldlifeline.cached_proxy
self.other_refs_weak = oldlifeline.other_refs_weak
def __del__(self):
diff --git a/pypy/module/_winreg/interp_winreg.py b/pypy/module/_winreg/interp_winreg.py
--- a/pypy/module/_winreg/interp_winreg.py
+++ b/pypy/module/_winreg/interp_winreg.py
@@ -108,9 +108,9 @@
raise OperationError(space.w_TypeError, errstring)
elif isinstance(w_hkey, W_HKEY):
return w_hkey.hkey
- elif space.is_true(space.isinstance(w_hkey, space.w_int)):
+ elif space.isinstance_w(w_hkey, space.w_int):
return rffi.cast(rwinreg.HKEY, space.int_w(w_hkey))
- elif space.is_true(space.isinstance(w_hkey, space.w_long)):
+ elif space.isinstance_w(w_hkey, space.w_long):
return rffi.cast(rwinreg.HKEY, space.uint_w(w_hkey))
else:
errstring = space.wrap("The object is not a PyHKEY object")
@@ -266,7 +266,7 @@
buf = None
if typ == rwinreg.REG_DWORD:
- if space.is_true(space.isinstance(w_value, space.w_int)):
+ if space.isinstance_w(w_value, space.w_int):
buflen = rffi.sizeof(rwin32.DWORD)
buf1 = lltype.malloc(rffi.CArray(rwin32.DWORD), 1, flavor='raw')
buf1[0] = space.uint_w(w_value)
@@ -278,7 +278,7 @@
buf = lltype.malloc(rffi.CCHARP.TO, buflen, flavor='raw')
buf[0] = '\0'
else:
- if space.is_true(space.isinstance(w_value, space.w_unicode)):
+ if space.isinstance_w(w_value, space.w_unicode):
w_value = space.call_method(w_value, 'encode',
space.wrap('mbcs'))
buf = rffi.str2charp(space.str_w(w_value))
@@ -289,7 +289,7 @@
buflen = 1
buf = lltype.malloc(rffi.CCHARP.TO, buflen, flavor='raw')
buf[0] = '\0'
- elif space.is_true(space.isinstance(w_value, space.w_list)):
+ elif space.isinstance_w(w_value, space.w_list):
strings = []
buflen = 0
@@ -298,7 +298,7 @@
while True:
try:
w_item = space.next(w_iter)
- if space.is_true(space.isinstance(w_item, space.w_unicode)):
+ if space.isinstance_w(w_item, space.w_unicode):
w_item = space.call_method(w_item, 'encode',
space.wrap('mbcs'))
item = space.str_w(w_item)
diff --git a/pypy/module/cpyext/complexobject.py b/pypy/module/cpyext/complexobject.py
--- a/pypy/module/cpyext/complexobject.py
+++ b/pypy/module/cpyext/complexobject.py
@@ -12,21 +12,24 @@
Py_complex_fields = (("real", rffi.DOUBLE), ("imag", rffi.DOUBLE))
cpython_struct("Py_complex", Py_complex_fields, Py_complex_t)
+
@cpython_api([lltype.Float, lltype.Float], PyObject)
def PyComplex_FromDoubles(space, real, imag):
return space.newcomplex(real, imag)
+
@cpython_api([PyObject], lltype.Float, error=-1)
def PyComplex_RealAsDouble(space, w_obj):
- if space.is_true(space.isinstance(w_obj, space.w_complex)):
+ if space.isinstance_w(w_obj, space.w_complex):
assert isinstance(w_obj, W_ComplexObject)
return w_obj.realval
else:
return space.float_w(w_obj)
+
@cpython_api([PyObject], lltype.Float, error=-1)
def PyComplex_ImagAsDouble(space, w_obj):
- if space.is_true(space.isinstance(w_obj, space.w_complex)):
+ if space.isinstance_w(w_obj, space.w_complex):
assert isinstance(w_obj, W_ComplexObject)
return w_obj.imagval
else:
diff --git a/pypy/module/cpyext/import_.py b/pypy/module/cpyext/import_.py
--- a/pypy/module/cpyext/import_.py
+++ b/pypy/module/cpyext/import_.py
@@ -29,7 +29,7 @@
space.setitem(w_globals, space.wrap("__builtins__"), w_builtin)
# Get the __import__ function from the builtins
- if space.is_true(space.isinstance(w_builtin, space.w_dict)):
+ if space.isinstance_w(w_builtin, space.w_dict):
w_import = space.getitem(w_builtin, space.wrap("__import__"))
else:
w_import = space.getattr(w_builtin, space.wrap("__import__"))
diff --git a/pypy/module/cpyext/intobject.py b/pypy/module/cpyext/intobject.py
--- a/pypy/module/cpyext/intobject.py
+++ b/pypy/module/cpyext/intobject.py
@@ -69,6 +69,7 @@
space.wrap("an integer is required, got NULL"))
return space.uint_w(space.int(w_obj))
+
@cpython_api([PyObject], rffi.ULONG, error=-1)
def PyInt_AsUnsignedLongMask(space, w_obj):
"""Will first attempt to cast the object to a PyIntObject or
@@ -76,13 +77,14 @@
unsigned long. This function does not check for overflow.
"""
w_int = space.int(w_obj)
- if space.is_true(space.isinstance(w_int, space.w_int)):
+ if space.isinstance_w(w_int, space.w_int):
num = space.int_w(w_int)
return r_uint(num)
else:
num = space.bigint_w(w_int)
return num.uintmask()
+
@cpython_api([PyObject], rffi.ULONGLONG, error=-1)
def PyInt_AsUnsignedLongLongMask(space, w_obj):
"""Will first attempt to cast the object to a PyIntObject or
@@ -90,7 +92,7 @@
unsigned long long, without checking for overflow.
"""
w_int = space.int(w_obj)
- if space.is_true(space.isinstance(w_int, space.w_int)):
+ if space.isinstance_w(w_int, space.w_int):
num = space.int_w(w_int)
return r_ulonglong(num)
else:
diff --git a/pypy/module/cpyext/longobject.py b/pypy/module/cpyext/longobject.py
--- a/pypy/module/cpyext/longobject.py
+++ b/pypy/module/cpyext/longobject.py
@@ -23,6 +23,13 @@
"""
return space.newlong(val)
+ at cpython_api([rffi.SIZE_T], PyObject)
+def PyLong_FromSize_t(space, val):
+ """Return a new PyLongObject object from a C size_t, or NULL on
+ failure.
+ """
+ return space.wrap(val)
+
@cpython_api([rffi.LONGLONG], PyObject)
def PyLong_FromLongLong(space, val):
"""Return a new PyLongObject object from a C long long, or NULL
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
@@ -182,7 +182,7 @@
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
+ if (space.isinstance_w(w_given, space.w_BaseException) or
space.is_oldstyle_instance(w_given)):
w_given_type = space.exception_getclass(w_given)
else:
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -1395,13 +1395,6 @@
"""
raise NotImplementedError
- at cpython_api([rffi.SIZE_T], PyObject)
-def PyLong_FromSize_t(space, v):
- """Return a new PyLongObject object from a C size_t, or
- NULL on failure.
- """
- raise NotImplementedError
-
@cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.INT_real], PyObject)
def PyLong_FromUnicode(space, u, length, base):
"""Convert a sequence of Unicode digits to a Python long integer value. The first
diff --git a/pypy/module/cpyext/test/test_longobject.py b/pypy/module/cpyext/test/test_longobject.py
--- a/pypy/module/cpyext/test/test_longobject.py
+++ b/pypy/module/cpyext/test/test_longobject.py
@@ -146,6 +146,15 @@
assert module.from_longlong() == -1
assert module.from_unsignedlonglong() == (1<<64) - 1
+ def test_from_size_t(self):
+ module = self.import_extension('foo', [
+ ("from_unsignedlong", "METH_NOARGS",
+ """
+ return PyLong_FromSize_t((size_t)-1);
+ """)])
+ import sys
+ assert module.from_unsignedlong() == 2 * sys.maxint + 1
+
def test_fromstring(self):
module = self.import_extension('foo', [
("from_string", "METH_NOARGS",
diff --git a/pypy/module/cpyext/test/test_unicodeobject.py b/pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py
+++ b/pypy/module/cpyext/test/test_unicodeobject.py
@@ -304,7 +304,7 @@
api.PyUnicode_Decode(b_text, 4, b_encoding, None)) == u'caf\xe9'
w_text = api.PyUnicode_FromEncodedObject(space.wrap("test"), b_encoding, None)
- assert space.is_true(space.isinstance(w_text, space.w_unicode))
+ assert space.isinstance_w(w_text, space.w_unicode)
assert space.unwrap(w_text) == "test"
assert api.PyUnicode_FromEncodedObject(space.wrap(u"test"), b_encoding, None) is None
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -248,7 +248,7 @@
Py_DecRef(space, base_object_pyo)
def check_descr(space, w_self, w_type):
- if not space.is_true(space.isinstance(w_self, w_type)):
+ if not space.isinstance_w(w_self, w_type):
raise DescrMismatch()
class GettersAndSetters:
@@ -489,7 +489,7 @@
pto.c_tp_as_sequence = heaptype.c_as_sequence
pto.c_tp_as_mapping = heaptype.c_as_mapping
pto.c_tp_as_buffer = heaptype.c_as_buffer
-
+
return rffi.cast(PyObject, heaptype)
def type_attach(space, py_obj, w_type):
@@ -734,4 +734,4 @@
return
if w_obj.is_cpytype():
w_obj.mutated(None)
-
+
diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -1,6 +1,5 @@
from pypy.interpreter.error import OperationError
from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rtyper.lltypesystem import llmemory
from pypy.module.unicodedata import unicodedb
from pypy.module.cpyext.api import (
CANNOT_FAIL, Py_ssize_t, build_type_checkers, cpython_api,
@@ -388,7 +387,7 @@
# - unicode is disallowed
# - raise TypeError for non-string types
- if space.is_true(space.isinstance(w_obj, space.w_unicode)):
+ if space.isinstance_w(w_obj, space.w_unicode):
w_meth = None
else:
try:
diff --git a/pypy/module/exceptions/interp_exceptions.py b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -156,7 +156,7 @@
return self.w_dict
def setdict(self, space, w_dict):
- if not space.is_true(space.isinstance(w_dict, space.w_dict)):
+ if not space.isinstance_w(w_dict, space.w_dict):
raise OperationError(space.w_TypeError, space.wrap("setting exceptions's dictionary to a non-dict"))
self.w_dict = w_dict
diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py
--- a/pypy/module/math/interp_math.py
+++ b/pypy/module/math/interp_math.py
@@ -182,7 +182,7 @@
def _log_any(space, w_x, base):
# base is supposed to be positive or 0.0, which means we use e
try:
- if space.is_true(space.isinstance(w_x, space.w_long)):
+ if space.isinstance_w(w_x, space.w_long):
# special case to support log(extremely-large-long)
num = space.bigint_w(w_x)
result = num.log(base)
diff --git a/pypy/module/operator/interp_operator.py b/pypy/module/operator/interp_operator.py
--- a/pypy/module/operator/interp_operator.py
+++ b/pypy/module/operator/interp_operator.py
@@ -233,8 +233,8 @@
raise OperationError(space.w_TypeError,
space.wrap("non-sequence object can't be repeated"))
- if not (space.is_true(space.isinstance(w_obj2, space.w_int)) or \
- space.is_true(space.isinstance(w_obj2, space.w_long))):
+ if not (space.isinstance_w(w_obj2, space.w_int) or
+ space.isinstance_w(w_obj2, space.w_long)):
# second arg has to be int/long
raise OperationError(space.w_TypeError,
space.wrap('an integer is required'))
diff --git a/pypy/module/oracle/interp_cursor.py b/pypy/module/oracle/interp_cursor.py
--- a/pypy/module/oracle/interp_cursor.py
+++ b/pypy/module/oracle/interp_cursor.py
@@ -82,7 +82,7 @@
# perform binds
if w_vars is None:
pass
- elif space.is_true(space.isinstance(w_vars, space.w_dict)):
+ elif space.isinstance_w(w_vars, space.w_dict):
self._setBindVariablesByName(space, w_vars, 1, 0, 0)
else:
self._setBindVariablesByPos(space, w_vars, 1, 0, 0)
@@ -114,7 +114,7 @@
def executemany(self, space, w_stmt, w_list_of_args):
if space.is_w(w_stmt, space.w_None):
w_stmt = None
- if not space.is_true(space.isinstance(w_list_of_args, space.w_list)):
+ if not space.isinstance_w(w_list_of_args, space.w_list):
raise OperationError(
space.w_TypeError,
space.wrap("list expected"))
@@ -137,7 +137,7 @@
for i in range(numrows):
w_arguments = args_w[i]
deferred = i < numrows - 1
- if space.is_true(space.isinstance(w_arguments, space.w_dict)):
+ if space.isinstance_w(w_arguments, space.w_dict):
self._setBindVariablesByName(
space, w_arguments, numrows, i, deferred)
else:
@@ -317,7 +317,7 @@
if e.match(space, get(space).w_DatabaseError):
attrptr = lltype.malloc(rffi.CArrayPtr(roci.ub4).TO, 1, flavor='raw')
try:
- status = roci.OCIAttrGet(
+ roci.OCIAttrGet(
self.handle, roci.OCI_HTYPE_STMT,
rffi.cast(roci.dvoidp, attrptr),
lltype.nullptr(roci.Ptr(roci.ub4).TO),
@@ -603,7 +603,7 @@
def _setBindVariableHelper(self, space, w_value, origVar,
numElements, arrayPos, defer):
- valueIsVariable = space.is_true(space.isinstance(w_value, get(space).w_Variable))
+ valueIsVariable = space.isinstance_w(w_value, get(space).w_Variable)
newVar = None
# handle case where variable is already bound
@@ -859,8 +859,6 @@
def _createRow(self, space):
items_w = []
- numItems = len(self.fetchVariables)
-
# acquire the value for each item
for var in self.fetchVariables:
assert isinstance(var, interp_variable.W_Variable)
@@ -981,9 +979,9 @@
size = varType.size
# determine the number of elements to create
- if space.is_true(space.isinstance(w_value, space.w_list)):
+ if space.isinstance_w(w_value, space.w_list):
numElements = space.len_w(w_value)
- elif space.is_true(space.isinstance(w_value, space.w_int)):
+ elif space.isinstance_w(w_value, space.w_int):
numElements = space.int_w(w_value)
else:
raise OperationError(
@@ -995,7 +993,7 @@
var.makeArray(space)
# set the value, if applicable
- if space.is_true(space.isinstance(w_value, space.w_list)):
+ if space.isinstance_w(w_value, space.w_list):
var.setArrayValue(space, w_value)
return var
diff --git a/pypy/module/oracle/interp_variable.py b/pypy/module/oracle/interp_variable.py
--- a/pypy/module/oracle/interp_variable.py
+++ b/pypy/module/oracle/interp_variable.py
@@ -425,7 +425,7 @@
def setArrayValue(self, space, w_value):
# ensure we have an array to set
- if not space.is_true(space.isinstance(w_value, space.w_list)):
+ if not space.isinstance_w(w_value, space.w_list):
raise OperationError(
space.w_TypeError,
space.wrap("expecting array data"))
@@ -514,7 +514,7 @@
wantBytes = self.charsetForm == roci.SQLCS_IMPLICIT
if wantBytes:
- if space.is_true(space.isinstance(w_value, space.w_str)):
+ if space.isinstance_w(w_value, space.w_str):
buf = config.StringBuffer()
buf.fill(space, w_value)
size = buf.size
@@ -523,7 +523,7 @@
space.w_TypeError,
space.wrap("expecting string or buffer data"))
else:
- if space.is_true(space.isinstance(w_value, space.w_unicode)):
+ if space.isinstance_w(w_value, space.w_unicode):
buf = config.StringBuffer()
buf.fill_with_unicode(space, w_value)
size = buf.size
@@ -760,7 +760,7 @@
rffi.cast(roci.Ptr(roci.OCINumber), self.data),
pos)
- if space.is_true(space.isinstance(w_value, space.w_int)):
+ if space.isinstance_w(w_value, space.w_int):
integerValuePtr = lltype.malloc(roci.Ptr(lltype.Signed).TO, 1,
flavor='raw')
try:
@@ -776,7 +776,7 @@
finally:
lltype.free(integerValuePtr, flavor='raw')
return
- elif space.is_true(space.isinstance(w_value, space.w_long)):
+ elif space.isinstance_w(w_value, space.w_long):
text_buf = config.StringBuffer()
text_buf.fill(space, space.str(w_value))
format_buf = config.StringBuffer()
@@ -793,7 +793,7 @@
status, "NumberVar_SetValue(): from long")
return
# XXX The bool case was already processed above
- elif space.is_true(space.isinstance(w_value, space.w_float)):
+ elif space.isinstance_w(w_value, space.w_float):
doubleValuePtr = lltype.malloc(roci.Ptr(lltype.Float).TO, 1,
flavor='raw')
try:
@@ -808,7 +808,7 @@
finally:
lltype.free(doubleValuePtr, flavor='raw')
return
- elif space.is_true(space.isinstance(w_value, get(space).w_DecimalType)):
+ elif space.isinstance_w(w_value, get(space).w_DecimalType):
w_text, w_format = transform.DecimalToFormatAndText(self.environment, w_value)
text_buf = config.StringBuffer()
text_buf.fill(space, w_text)
@@ -856,14 +856,14 @@
dataptr = rffi.ptradd(
rffi.cast(roci.Ptr(roci.OCIDate), self.data),
pos)
- if space.is_true(space.isinstance(w_value, get(space).w_DateTimeType)):
+ if space.isinstance_w(w_value, get(space).w_DateTimeType):
year = space.int_w(space.getattr(w_value, space.wrap('year')))
month = space.int_w(space.getattr(w_value, space.wrap('month')))
day = space.int_w(space.getattr(w_value, space.wrap('day')))
hour = space.int_w(space.getattr(w_value, space.wrap('hour')))
minute = space.int_w(space.getattr(w_value, space.wrap('minute')))
second = space.int_w(space.getattr(w_value, space.wrap('second')))
- elif space.is_true(space.isinstance(w_value, get(space).w_DateType)):
+ elif space.isinstance_w(w_value, get(space).w_DateType):
year = space.int_w(space.getattr(w_value, space.wrap('year')))
month = space.int_w(space.getattr(w_value, space.wrap('month')))
day = space.int_w(space.getattr(w_value, space.wrap('day')))
@@ -933,7 +933,7 @@
def setValueProc(self, space, pos, w_value):
# make sure a timestamp is being bound
- if not space.is_true(space.isinstance(w_value, get(space).w_DateTimeType)):
+ if not space.isinstance_w(w_value, get(space).w_DateTimeType):
raise OperationError(
space.w_TypeError,
space.wrap("expecting timestamp data"))
@@ -985,8 +985,7 @@
self.environment, self.getDataptr(pos))
def setValueProc(self, space, pos, w_value):
- if not space.is_true(space.isinstance(w_value,
- get(space).w_TimedeltaType)):
+ if not space.isinstance_w(w_value, get(space).w_TimedeltaType):
raise OperationError(
space.w_TypeError,
space.wrap("expecting timedelta data"))
@@ -1208,7 +1207,7 @@
def setValueProc(self, space, pos, w_value):
from pypy.module.oracle import interp_cursor
w_CursorType = space.gettypeobject(interp_cursor.W_Cursor.typedef)
- if not space.is_true(space.isinstance(w_value, w_CursorType)):
+ if not space.isinstance_w(w_value, w_CursorType):
raise OperationError(
space.w_TypeError,
space.wrap("expecting cursor"))
@@ -1414,7 +1413,7 @@
from pypy.objspace.std.typeobject import W_TypeObject
moduledict = get(space)
- if not space.is_true(space.isinstance(w_type, space.w_type)):
+ if not space.isinstance_w(w_type, space.w_type):
raise OperationError(
space.w_TypeError,
space.wrap("Variable_TypeByPythonType(): type expected"))
@@ -1435,49 +1434,49 @@
if space.is_w(w_value, space.w_None):
return VT_String, 1, numElements
- if space.is_true(space.isinstance(w_value, space.w_str)):
+ if space.isinstance_w(w_value, space.w_str):
size = space.len_w(w_value)
if size > config.MAX_STRING_CHARS:
return VT_LongString, size, numElements
else:
return VT_String, size, numElements
- if space.is_true(space.isinstance(w_value, space.w_unicode)):
+ if space.isinstance_w(w_value, space.w_unicode):
size = space.len_w(w_value)
return VT_NationalCharString, size, numElements
- if space.is_true(space.isinstance(w_value, space.w_int)):
+ if space.isinstance_w(w_value, space.w_int):
return VT_Integer, 0, numElements
- if space.is_true(space.isinstance(w_value, space.w_long)):
+ if space.isinstance_w(w_value, space.w_long):
return VT_LongInteger, 0, numElements
- if space.is_true(space.isinstance(w_value, space.w_float)):
+ if space.isinstance_w(w_value, space.w_float):
return VT_Float, 0, numElements
# XXX cxBinary
# XXX bool
- if space.is_true(space.isinstance(w_value, get(space).w_DateTimeType)):
+ if space.isinstance_w(w_value, get(space).w_DateTimeType):
return VT_DateTime, 0, numElements
- if space.is_true(space.isinstance(w_value, get(space).w_DateType)):
+ if space.isinstance_w(w_value, get(space).w_DateType):
return VT_Date, 0, numElements
# XXX Delta
from pypy.module.oracle import interp_cursor
- if space.is_true(space.isinstance( # XXX is there an easier way?
+ if space.isinstance_w( # XXX is there an easier way?
w_value,
- space.gettypeobject(interp_cursor.W_Cursor.typedef))):
+ space.gettypeobject(interp_cursor.W_Cursor.typedef)):
return VT_Cursor, 0, numElements
- if space.is_true(space.isinstance(w_value, get(space).w_DecimalType)):
+ if space.isinstance_w(w_value, get(space).w_DecimalType):
return VT_NumberAsString, 0, numElements
# handle arrays
- if space.is_true(space.isinstance(w_value, space.w_list)):
+ if space.isinstance_w(w_value, space.w_list):
elements_w = space.listview(w_value)
for w_element in elements_w:
if not space.is_w(w_element, space.w_None):
@@ -1497,8 +1496,7 @@
space.wrap(cursor),
w_value,
space.wrap(numElements))
- if not space.is_true(space.isinstance(w_var,
- get(space).w_Variable)):
+ if not space.isinstance_w(w_var, get(space).w_Variable):
raise OperationError(
space.w_TypeError,
space.wrap("expecting variable from input type handler"))
@@ -1519,7 +1517,7 @@
if space.is_w(var, space.w_None):
varType, size, numElements = typeByValue(space, w_value, numElements)
var = varType(cursor, numElements, size)
- if space.is_true(space.isinstance(w_value, space.w_list)):
+ if space.isinstance_w(w_value, space.w_list):
var.makeArray(space)
assert isinstance(var, W_Variable)
@@ -1539,7 +1537,7 @@
def newVariableByType(space, cursor, w_value, numElements):
# passing an integer is assumed to be a string
- if space.is_true(space.isinstance(w_value, space.w_int)):
+ if space.isinstance_w(w_value, space.w_int):
size = space.int_w(w_value)
if size > config.MAX_STRING_CHARS:
varType = VT_LongString
@@ -1548,12 +1546,11 @@
return varType(cursor, numElements, size)
# passing an array of two elements define an array
- if space.is_true(space.isinstance(w_value, space.w_list)):
+ if space.isinstance_w(w_value, space.w_list):
return newArrayVariableByType(space, cursor, w_value)
# handle directly bound variables
- if space.is_true(space.isinstance(w_value,
- get(space).w_Variable)):
+ if space.isinstance_w(w_value, get(space).w_Variable):
return space.interp_w(W_Variable, w_value)
# everything else ought to be a Python type
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -1080,6 +1080,7 @@
func = declare_new_w_star(name)
globals()[name] = func
+
@unwrap_spec(fd=c_int)
def ttyname(space, fd):
try:
@@ -1087,9 +1088,10 @@
except OSError, e:
raise wrap_oserror(space, e)
+
def confname_w(space, w_name, namespace):
# XXX slightly non-nice, reuses the sysconf of the underlying os module
- if space.is_true(space.isinstance(w_name, space.w_basestring)):
+ if space.isinstance_w(w_name, space.w_basestring):
try:
num = namespace[space.str_w(w_name)]
except KeyError:
diff --git a/pypy/module/pyexpat/interp_pyexpat.py b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -796,7 +796,7 @@
Return a new XML parser object."""
if space.is_none(w_encoding):
encoding = None
- elif space.is_true(space.isinstance(w_encoding, space.w_str)):
+ elif space.isinstance_w(w_encoding, space.w_str):
encoding = space.str_w(w_encoding)
else:
type_name = space.type(w_encoding).getname(space)
@@ -807,7 +807,7 @@
if space.is_none(w_namespace_separator):
namespace_separator = 0
- elif space.is_true(space.isinstance(w_namespace_separator, space.w_str)):
+ elif space.isinstance_w(w_namespace_separator, space.w_str):
separator = space.str_w(w_namespace_separator)
if len(separator) == 0:
namespace_separator = 0
diff --git a/pypy/module/rctime/interp_time.py b/pypy/module/rctime/interp_time.py
--- a/pypy/module/rctime/interp_time.py
+++ b/pypy/module/rctime/interp_time.py
@@ -432,10 +432,10 @@
glob_buf.c_tm_zone = lltype.nullptr(rffi.CCHARP.TO)
rffi.setintfield(glob_buf, 'c_tm_gmtoff', 0)
- w_accept2dyear = _get_module_object(space, "accept2dyear")
- accept2dyear = space.int_w(w_accept2dyear)
+ if y < 1900:
+ w_accept2dyear = _get_module_object(space, "accept2dyear")
+ accept2dyear = space.int_w(w_accept2dyear)
- if y < 1900:
if not accept2dyear:
raise OperationError(space.w_ValueError,
space.wrap("year >= 1900 required"))
diff --git a/pypy/module/rctime/test/test_rctime.py b/pypy/module/rctime/test/test_rctime.py
--- a/pypy/module/rctime/test/test_rctime.py
+++ b/pypy/module/rctime/test/test_rctime.py
@@ -139,6 +139,16 @@
ltime = rctime.localtime()
assert rctime.asctime(tuple(ltime)) == rctime.asctime(ltime)
+ def test_accept2dyear_access(self):
+ import time as rctime
+
+ accept2dyear = rctime.accept2dyear
+ del rctime.accept2dyear
+ try:
More information about the pypy-commit
mailing list