[pypy-commit] pypy default: (alex, fijal): use isinstance_w instead of isinstance where possible
alex_gaynor
noreply at buildbot.pypy.org
Sat Mar 23 05:48:23 CET 2013
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r62684:5f5a605ccb6c
Date: 2013-03-22 21:48 -0700
http://bitbucket.org/pypy/pypy/changeset/5f5a605ccb6c/
Log: (alex, fijal): use isinstance_w instead of isinstance where possible
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
@@ -1031,9 +1031,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__
@@ -1345,7 +1342,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))
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/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
@@ -50,7 +52,7 @@
# -- 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 +131,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,
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/_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
@@ -231,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'
@@ -240,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/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/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/struct/formatiterator.py b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -83,7 +83,7 @@
def _maybe_float(self, w_obj):
space = self.space
- if space.is_true(space.isinstance(w_obj, space.w_float)):
+ if space.isinstance_w(w_obj, space.w_float):
msg = "struct: integer argument expected, got float"
else:
msg = "integer argument expected, got non-integer"
diff --git a/pypy/module/termios/interp_termios.py b/pypy/module/termios/interp_termios.py
--- a/pypy/module/termios/interp_termios.py
+++ b/pypy/module/termios/interp_termios.py
@@ -24,7 +24,7 @@
w_builtin = space.getbuiltinmodule('__builtin__')
cc = []
for w_c in space.unpackiterable(w_cc):
- if space.is_true(space.isinstance(w_c, space.w_int)):
+ if space.isinstance_w(w_c, space.w_int):
ch = space.call_function(space.getattr(w_builtin,
space.wrap('chr')), w_c)
cc.append(space.str_w(ch))
diff --git a/pypy/module/thread/os_thread.py b/pypy/module/thread/os_thread.py
--- a/pypy/module/thread/os_thread.py
+++ b/pypy/module/thread/os_thread.py
@@ -146,6 +146,7 @@
space.threadlocals.setup_threads(space)
bootstrapper.setup(space)
+
def reinit_threads(space):
"Called in the child process after a fork()"
space.threadlocals.reinit_threads(space)
@@ -167,10 +168,10 @@
when the function raises an unhandled exception; a stack trace will be
printed unless the exception is SystemExit."""
setup_threads(space)
- if not space.is_true(space.isinstance(w_args, space.w_tuple)):
+ if not space.isinstance_w(w_args, space.w_tuple):
raise OperationError(space.w_TypeError,
space.wrap("2nd arg must be a tuple"))
- if w_kwargs is not None and not space.is_true(space.isinstance(w_kwargs, space.w_dict)):
+ if w_kwargs is not None and not space.isinstance_w(w_kwargs, space.w_dict):
raise OperationError(space.w_TypeError,
space.wrap("optional 3rd arg must be a dictionary"))
if not space.is_true(space.callable(w_callable)):
diff --git a/pypy/module/unicodedata/interp_ucd.py b/pypy/module/unicodedata/interp_ucd.py
--- a/pypy/module/unicodedata/interp_ucd.py
+++ b/pypy/module/unicodedata/interp_ucd.py
@@ -33,7 +33,7 @@
if MAXUNICODE > 0xFFFF:
# Target is wide build
def unichr_to_code_w(space, w_unichr):
- if not space.is_true(space.isinstance(w_unichr, space.w_unicode)):
+ if not space.isinstance_w(w_unichr, space.w_unicode):
raise OperationError(space.w_TypeError, space.wrap(
'argument 1 must be unicode'))
@@ -53,7 +53,7 @@
else:
# Target is narrow build
def unichr_to_code_w(space, w_unichr):
- if not space.is_true(space.isinstance(w_unichr, space.w_unicode)):
+ if not space.isinstance_w(w_unichr, space.w_unicode):
raise OperationError(space.w_TypeError, space.wrap(
'argument 1 must be unicode'))
@@ -178,7 +178,7 @@
@unwrap_spec(form=str)
def normalize(self, space, form, w_unistr):
- if not space.is_true(space.isinstance(w_unistr, space.w_unicode)):
+ if not space.isinstance_w(w_unistr, space.w_unicode):
raise OperationError(space.w_TypeError, space.wrap('argument 2 must be unicode'))
if form == 'NFC':
composed = True
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -363,7 +363,7 @@
"'%s' object does not define __format__",
typename)
w_res = space.get_and_call_function(w_descr, w_obj, w_format_spec)
- if not space.is_true(space.isinstance(w_res, space.w_basestring)):
+ if not space.isinstance_w(w_res, space.w_basestring):
typename = space.type(w_obj).getname(space)
restypename = space.type(w_res).getname(space)
raise operationerrfmt(space.w_TypeError,
@@ -453,10 +453,10 @@
return w_result
elif space.is_w(w_resulttype, space.w_long):
return space.hash(w_result)
- elif space.is_true(space.isinstance(w_result, space.w_int)):
+ elif space.isinstance_w(w_result, space.w_int):
# be careful about subclasses of 'int'...
return space.wrap(space.int_w(w_result))
- elif space.is_true(space.isinstance(w_result, space.w_long)):
+ elif space.isinstance_w(w_result, space.w_long):
# be careful about subclasses of 'long'...
bigint = space.bigint_w(w_result)
return space.wrap(bigint.hash())
@@ -507,12 +507,12 @@
if w_res is None or space.is_w(w_res, space.w_None):
raise OperationError(space.w_TypeError,
space.wrap("coercion failed"))
- if (not space.is_true(space.isinstance(w_res, space.w_tuple)) or
+ if (not space.isinstance_w(w_res, space.w_tuple) or
space.len_w(w_res) != 2):
raise OperationError(space.w_TypeError,
space.wrap("coercion should return None or 2-tuple"))
w_res = space.newtuple([space.getitem(w_res, space.wrap(1)), space.getitem(w_res, space.wrap(0))])
- elif (not space.is_true(space.isinstance(w_res, space.w_tuple)) or
+ elif (not space.isinstance_w(w_res, space.w_tuple) or
space.len_w(w_res) != 2):
raise OperationError(space.w_TypeError,
space.wrap("coercion should return None or 2-tuple"))
@@ -522,8 +522,12 @@
return space._type_issubtype(w_sub, w_type)
@specialize.arg_or_var(2)
+ def isinstance_w(space, w_inst, w_type):
+ return space._type_isinstance(w_inst, w_type)
+
+ @specialize.arg_or_var(2)
def isinstance(space, w_inst, w_type):
- return space.wrap(space._type_isinstance(w_inst, w_type))
+ return space.wrap(space.isinstance_w(w_inst, w_type))
def issubtype_allow_override(space, w_sub, w_type):
w_check = space.lookup(w_type, "__subclasscheck__")
@@ -809,7 +813,7 @@
('long', '__long__', ("space.w_int", "space.w_long")),
('float', '__float__', ("space.w_float",))]:
- l = ["space.is_true(space.isinstance(w_result, %s))" % x
+ l = ["space.isinstance_w(w_result, %s)" % x
for x in checkerspec]
checker = " or ".join(l)
source = """if 1:
@@ -849,7 +853,7 @@
typename)
w_result = space.get_and_call_function(w_impl, w_obj)
- if space.is_true(space.isinstance(w_result, space.w_str)):
+ if space.isinstance_w(w_result, space.w_str):
return w_result
try:
result = space.str_w(w_result)
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -99,7 +99,6 @@
class FakeObjSpace(ObjSpace):
-
def __init__(self, config=None):
self._seen_extras = []
ObjSpace.__init__(self, config=config)
@@ -242,6 +241,11 @@
def type(self, w_obj):
return w_some_type()
+ def isinstance_w(self, w_inst, w_type):
+ is_root(w_inst)
+ is_root(w_type)
+ return NonConstant(True)
+
def unpackiterable(self, w_iterable, expected_length=-1):
is_root(w_iterable)
if expected_length < 0:
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -616,10 +616,6 @@
return True
return self.type(w_inst).issubtype(w_type)
- @specialize.arg_or_var(2)
- def isinstance_w(space, w_inst, w_type):
- return space._type_isinstance(w_inst, w_type)
-
def setup_isinstance_cache(self):
# This assumes that all classes in the stdobjspace implementing a
# particular app-level type are distinguished by a common base class.
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -1,14 +1,13 @@
+import sys
import py
-import sys
-from pypy.interpreter.error import OperationError
-from pypy.objspace.std.dictmultiobject import \
- W_DictMultiObject, setitem__DictMulti_ANY_ANY, getitem__DictMulti_ANY, \
- StringDictStrategy, ObjectDictStrategy
-class TestW_DictObject:
+from pypy.objspace.std.dictmultiobject import (W_DictMultiObject,
+ setitem__DictMulti_ANY_ANY, getitem__DictMulti_ANY, StringDictStrategy,
+ ObjectDictStrategy)
+
+class TestW_DictObject(object):
def test_empty(self):
- space = self.space
d = self.space.newdict()
assert not self.space.is_true(d)
assert type(d.strategy) is not ObjectDictStrategy
@@ -895,6 +894,7 @@
return str
return type(w_obj)
w_str = str
+
def str_w(self, string):
assert isinstance(string, str)
return string
@@ -906,8 +906,9 @@
def wrap(self, obj):
return obj
- def isinstance(self, obj, klass):
+ def isinstance_w(self, obj, klass):
return isinstance(obj, klass)
+ isinstance = isinstance_w
def newtuple(self, l):
return tuple(l)
diff --git a/pypy/tool/pytest/appsupport.py b/pypy/tool/pytest/appsupport.py
--- a/pypy/tool/pytest/appsupport.py
+++ b/pypy/tool/pytest/appsupport.py
@@ -206,7 +206,7 @@
self.type, self.value, self.traceback = sys.exc_info()
return _ExceptionInfo
-""")
+""")
try:
return space.call_function(space._w_ExceptionInfo)
finally:
@@ -215,7 +215,7 @@
def pypyraises(space, w_ExpectedException, w_expr, __args__):
"""A built-in function providing the equivalent of py.test.raises()."""
args_w, kwds_w = __args__.unpack()
- if space.is_true(space.isinstance(w_expr, space.w_str)):
+ if space.isinstance_w(w_expr, space.w_str):
if args_w:
raise OperationError(space.w_TypeError,
space.wrap("raises() takes no argument "
More information about the pypy-commit
mailing list