[pypy-commit] pypy kill-someobject: try to use more consistently space.is_none
fijal
noreply at buildbot.pypy.org
Wed Oct 10 17:38:02 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: kill-someobject
Changeset: r57977:56e41853186e
Date: 2012-10-10 17:37 +0200
http://bitbucket.org/pypy/pypy/changeset/56e41853186e/
Log: try to use more consistently space.is_none
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -719,8 +719,16 @@
# done by a method call on w_two (and not on w_one, because of the
# expected programming style where we say "if x is None" or
# "if x is object").
+ assert w_two is not None
+ assert w_one is not None
return w_two.is_w(self, w_one)
+ def is_none(self, w_obj):
+ """ mostly for checking inputargs that have unwrap_spec and
+ can accept both w_None and None
+ """
+ return w_obj is None or self.is_w(w_obj, self.w_None)
+
def id(self, w_obj):
w_result = w_obj.immutable_unique_id(self)
if w_result is None:
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -96,9 +96,6 @@
return name
-def is_none(space, w_obj):
- return w_obj is None or space.is_w(w_obj, space.w_None)
-
#________________________________________________________________
diff --git a/pypy/module/__pypy__/interp_identitydict.py b/pypy/module/__pypy__/interp_identitydict.py
--- a/pypy/module/__pypy__/interp_identitydict.py
+++ b/pypy/module/__pypy__/interp_identitydict.py
@@ -34,6 +34,8 @@
raise OperationError(space.w_KeyError, w_key)
def get(self, space, w_key, w_default=None):
+ if w_default is None:
+ w_default = space.w_None
return self.dict.get(w_key, w_default)
def keys(self, space):
diff --git a/pypy/module/_cffi_backend/ccallback.py b/pypy/module/_cffi_backend/ccallback.py
--- a/pypy/module/_cffi_backend/ccallback.py
+++ b/pypy/module/_cffi_backend/ccallback.py
@@ -31,7 +31,6 @@
"expected a callable object, not %s",
space.type(w_callable).getname(space))
self.w_callable = w_callable
- self.w_error = w_error
#
fresult = self.getfunctype().ctitem
size = fresult.size
@@ -40,7 +39,7 @@
size = SIZE_OF_FFI_ARG
self.ll_error = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw',
zero=True)
- if not space.is_w(w_error, space.w_None):
+ if not space.is_none(w_error):
convert_from_object_fficallback(fresult, self.ll_error, w_error)
#
self.unique_id = compute_unique_id(self)
diff --git a/pypy/module/_cffi_backend/func.py b/pypy/module/_cffi_backend/func.py
--- a/pypy/module/_cffi_backend/func.py
+++ b/pypy/module/_cffi_backend/func.py
@@ -1,15 +1,12 @@
from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.rpython.lltypesystem import lltype, rffi
-
+from pypy.interpreter.gateway import unwrap_spec, W_Root
from pypy.module._cffi_backend import ctypeobj, cdataobj
# ____________________________________________________________
- at unwrap_spec(ctype=ctypeobj.W_CType)
-def newp(space, ctype, w_init=None):
+ at unwrap_spec(ctype=ctypeobj.W_CType, w_init=(W_Root, 'space.w_None'))
+def newp(space, ctype, w_init):
return ctype.newp(w_init)
# ____________________________________________________________
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
@@ -267,7 +267,7 @@
@unwrap_spec(errors=str)
-def encode(space, w_obj, w_encoding=NoneNotWrapped, errors='strict'):
+def encode(space, w_obj, w_encoding=None, errors='strict'):
"""encode(obj, [encoding[,errors]]) -> object
Encodes obj using the codec registered for encoding. encoding defaults
@@ -290,7 +290,7 @@
return space.newtuple([space.wrap(s), space.wrap(len(s))])
@unwrap_spec(errors=str)
-def decode(space, w_obj, w_encoding=NoneNotWrapped, errors='strict'):
+def decode(space, w_obj, w_encoding=None, errors='strict'):
"""decode(obj, [encoding[,errors]]) -> object
Decodes obj using the codec registered for encoding. encoding defaults
@@ -598,15 +598,14 @@
raise OperationError(space.w_TypeError, space.wrap("invalid mapping"))
- at unwrap_spec(string=str, errors='str_or_None',
- w_mapping = (W_Root, 'space.w_None'))
+ at unwrap_spec(string=str, errors='str_or_None')
def charmap_decode(space, string, errors="strict", w_mapping=None):
if errors is None:
errors = 'strict'
if len(string) == 0:
return space.newtuple([space.wrap(u''), space.wrap(0)])
- if space.is_w(w_mapping, space.w_None):
+ if space.is_none(w_mapping):
mapping = None
else:
mapping = Charmap_Decode(space, w_mapping)
@@ -618,12 +617,11 @@
final, state.decode_error_handler, mapping)
return space.newtuple([space.wrap(result), space.wrap(consumed)])
- at unwrap_spec(uni=unicode, errors='str_or_None',
- w_mapping = (W_Root, 'space.w_None'))
+ at unwrap_spec(uni=unicode, errors='str_or_None')
def charmap_encode(space, uni, errors="strict", w_mapping=None):
if errors is None:
errors = 'strict'
- if space.is_w(w_mapping, space.w_None):
+ if space.is_none(w_mapping):
mapping = None
else:
mapping = Charmap_Encode(space, w_mapping)
diff --git a/pypy/module/_ffi/interp_struct.py b/pypy/module/_ffi/interp_struct.py
--- a/pypy/module/_ffi/interp_struct.py
+++ b/pypy/module/_ffi/interp_struct.py
@@ -115,7 +115,7 @@
@unwrap_spec(name=str)
def descr_new_structdescr(space, w_type, name, w_fields=None):
descr = W__StructDescr(name)
- if w_fields is not space.w_None:
+ if not space.is_none(w_fields):
descr.define_fields(space, w_fields)
return descr
diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -239,7 +239,7 @@
def direct_truncate(self, w_size=None): # note: a wrapped size!
stream = self.getstream()
space = self.space
- if w_size is None or space.is_w(w_size, space.w_None):
+ if space.is_none(w_size):
size = stream.tell()
else:
size = space.r_longlong_w(w_size)
diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -1,7 +1,7 @@
from __future__ import with_statement
from pypy.interpreter.typedef import (
TypeDef, GetSetProperty, generic_new_descr, interp_attrproperty_w)
-from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.gateway import interp2app, unwrap_spec, W_Root
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.buffer import RWBuffer
from pypy.rlib.rstring import StringBuilder
@@ -387,7 +387,8 @@
self._check_init(space)
return space.call_method(self.w_raw, "fileno")
- def truncate_w(self, space, w_size=None):
+ @unwrap_spec(w_size = (W_Root, 'space.w_None'))
+ def truncate_w(self, space, w_size):
self._check_init(space)
with self.lock:
if self.writable:
diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -27,7 +27,7 @@
self.string_size = 0
self.pos = 0
- if not space.is_w(w_initial_bytes, space.w_None):
+ if not space.is_none(w_initial_bytes):
self.write_w(space, w_initial_bytes)
self.pos = 0
@@ -108,7 +108,7 @@
def truncate_w(self, space, w_size=None):
self._check_closed(space)
- if space.is_w(w_size, space.w_None):
+ if space.is_none(w_size):
size = self.pos
else:
size = space.r_longlong_w(w_size)
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -410,7 +410,7 @@
def truncate_w(self, space, w_size=None):
self._check_closed(space)
self._check_writable(space)
- if space.is_w(w_size, space.w_None):
+ if space.is_none(w_size):
w_size = self.tell_w(space)
try:
diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -11,7 +11,7 @@
DEFAULT_BUFFER_SIZE = 8192
def convert_size(space, w_size):
- if space.is_w(w_size, space.w_None):
+ if space.is_none(w_size):
return -1
else:
return space.int_w(w_size)
diff --git a/pypy/module/_io/interp_stringio.py b/pypy/module/_io/interp_stringio.py
--- a/pypy/module/_io/interp_stringio.py
+++ b/pypy/module/_io/interp_stringio.py
@@ -1,6 +1,6 @@
from pypy.interpreter.typedef import (
TypeDef, generic_new_descr, GetSetProperty)
-from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.gateway import interp2app, unwrap_spec, W_Root
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.module._io.interp_textio import W_TextIOBase, W_IncrementalNewlineDecoder
from pypy.module._io.interp_iobase import convert_size
@@ -12,7 +12,8 @@
self.buf = []
self.pos = 0
- def descr_init(self, space, w_initvalue=None, w_newline="\n"):
+ @unwrap_spec(w_newline = (W_Root, 'space.wrap("\\n")'))
+ def descr_init(self, space, w_initvalue=None, w_newline=None):
# In case __init__ is called multiple times
self.buf = []
self.pos = 0
@@ -47,7 +48,7 @@
space.wrap(int(self.readtranslate))
)
- if not space.is_w(w_initvalue, space.w_None):
+ if not space.is_none(w_initvalue):
self.write_w(space, w_initvalue)
self.pos = 0
@@ -225,7 +226,7 @@
def truncate_w(self, space, w_size=None):
self._check_closed(space)
- if space.is_w(w_size, space.w_None):
+ if space.is_none(w_size):
size = self.pos
else:
size = space.int_w(w_size)
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
@@ -48,7 +48,7 @@
def setlocale(space, category, w_locale=None):
"(integer,string=None) -> string. Activates/queries locale processing."
- if w_locale is None or space.is_w(w_locale, space.w_None):
+ if space.is_none(w_locale):
locale = None
else:
locale = space.str_w(w_locale)
diff --git a/pypy/module/_multiprocessing/interp_semaphore.py b/pypy/module/_multiprocessing/interp_semaphore.py
--- a/pypy/module/_multiprocessing/interp_semaphore.py
+++ b/pypy/module/_multiprocessing/interp_semaphore.py
@@ -225,7 +225,7 @@
def semlock_acquire(self, space, block, w_timeout):
if not block:
full_msecs = 0
- elif space.is_w(w_timeout, space.w_None):
+ elif space.is_none(w_timeout):
full_msecs = rwin32.INFINITE
else:
timeout = space.float_w(w_timeout)
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
@@ -3,7 +3,7 @@
to app-level with apropriate interface
"""
-from pypy.interpreter.gateway import interp2app, unwrap_spec, is_none
+from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef, GetSetProperty, interp_attrproperty
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.interpreter.error import OperationError
@@ -13,7 +13,7 @@
from pypy.module._rawffi.interp_rawffi import TYPEMAP
from pypy.module._rawffi.interp_rawffi import size_alignment
from pypy.module._rawffi.interp_rawffi import unpack_shape_with_length
-from pypy.rlib.rarithmetic import intmask, r_uint
+from pypy.rlib.rarithmetic import r_uint
def push_elem(ll_array, pos, value):
TP = lltype.typeOf(value)
@@ -48,7 +48,7 @@
@unwrap_spec(length=int, autofree=bool)
def descr_call(self, space, length, w_items=None, autofree=False):
result = self.allocate(space, length, autofree)
- if is_none(space, w_items):
+ if not space.is_none(w_items):
items_w = space.unpackiterable(w_items)
iterlength = len(items_w)
if iterlength > length:
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -645,23 +645,23 @@
sock_fd = space.int_w(space.call_method(w_sock, "fileno"))
w_timeout = space.call_method(w_sock, "gettimeout")
- if space.is_w(w_timeout, space.w_None):
+ if space.is_none(w_timeout):
has_timeout = False
else:
has_timeout = True
- if space.is_w(w_key_file, space.w_None):
+ if space.is_none(w_key_file):
key_file = None
else:
key_file = space.str_w(w_key_file)
- if space.is_w(w_cert_file, space.w_None):
+ if space.is_none(w_cert_file):
cert_file = None
else:
cert_file = space.str_w(w_cert_file)
- if space.is_w(w_cacerts_file, space.w_None):
+ if space.is_none(w_cacerts_file):
cacerts_file = None
else:
cacerts_file = space.str_w(w_cacerts_file)
- if space.is_w(w_ciphers, space.w_None):
+ if space.is_none(w_ciphers):
ciphers = None
else:
ciphers = space.str_w(w_ciphers)
diff --git a/pypy/module/_warnings/interp_warnings.py b/pypy/module/_warnings/interp_warnings.py
--- a/pypy/module/_warnings/interp_warnings.py
+++ b/pypy/module/_warnings/interp_warnings.py
@@ -311,7 +311,7 @@
def get_source_line(space, w_globals, lineno):
- if space.is_w(w_globals, space.w_None):
+ if space.is_none(w_globals):
return None
# Check/get the requisite pieces needed for the loader.
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
@@ -254,7 +254,7 @@
if __args__.arguments_w:
raise OperationError(space.w_TypeError, space.wrap(
"__new__ expected at most 2 arguments"))
- if space.is_w(w_callable, space.w_None):
+ if space.is_none(w_callable):
return get_or_make_weakref(space, w_subtype, w_obj)
else:
return make_weakref_with_callback(space, w_subtype, w_obj, w_callable)
@@ -326,7 +326,7 @@
"""Create a proxy object that weakly references 'obj'.
'callback', if given, is called with the proxy as an argument when 'obj'
is about to be finalized."""
- if space.is_w(w_callable, space.w_None):
+ if space.is_none(w_callable):
return get_or_make_proxy(space, w_obj)
else:
return make_proxy_with_callback(space, w_obj, w_callable)
diff --git a/pypy/module/cStringIO/interp_stringio.py b/pypy/module/cStringIO/interp_stringio.py
--- a/pypy/module/cStringIO/interp_stringio.py
+++ b/pypy/module/cStringIO/interp_stringio.py
@@ -165,10 +165,10 @@
self.seek(i)
return ''.join(bigbuffer[p:i])
- def descr_truncate(self, w_size=None): # note: a wrapped size!
+ def descr_truncate(self, w_size=None):
self.check_closed()
space = self.space
- if w_size is None or space.is_w(w_size, space.w_None):
+ if space.is_none(w_size):
size = self.tell()
else:
size = space.int_w(w_size)
@@ -249,7 +249,7 @@
# ____________________________________________________________
def StringIO(space, w_string=None):
- if space.is_w(w_string, space.w_None):
+ if space.is_none(w_string):
return space.wrap(W_OutputType(space))
else:
string = space.bufferstr_w(w_string)
diff --git a/pypy/module/cpyext/methodobject.py b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -188,7 +188,7 @@
return ret
def cmethod_descr_get(space, w_function, w_obj, w_cls=None):
- asking_for_bound = (space.is_w(w_cls, space.w_None) or
+ asking_for_bound = (space.is_none(w_cls) or
not space.is_w(w_obj, space.w_None) or
space.is_w(w_cls, space.type(space.w_None)))
if asking_for_bound:
diff --git a/pypy/module/itertools/interp_itertools.py b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -884,8 +884,10 @@
def __init__(self, space, w_iterable, w_fun):
self.space = space
self.w_iterable = self.space.iter(w_iterable)
- self.identity_fun = self.space.is_w(w_fun, self.space.w_None)
- self.w_fun = w_fun
+ if space.is_none(w_fun):
+ self.w_fun = None
+ else:
+ self.w_fun = w_fun
self.index = 0
self.lookahead = False
self.exhausted = False
@@ -915,7 +917,7 @@
raise
else:
self.w_lookahead = w_obj
- if self.identity_fun:
+ if self.w_fun is None:
self.w_key = w_obj
else:
self.w_key = self.space.call_function(self.w_fun, w_obj)
@@ -952,7 +954,7 @@
else:
raise
else:
- if self.identity_fun:
+ if self.w_fun is None:
w_new_key = w_obj
else:
w_new_key = self.space.call_function(self.w_fun, w_obj)
@@ -966,8 +968,7 @@
self.new_group = True #new group
raise StopIteration
- at unwrap_spec(w_key = (W_Root, 'space.w_None'))
-def W_GroupBy___new__(space, w_subtype, w_iterable, w_key):
+def W_GroupBy___new__(space, w_subtype, w_iterable, w_key=None):
r = space.allocate_instance(W_GroupBy, w_subtype)
r.__init__(space, w_iterable, w_key)
return space.wrap(r)
@@ -1337,10 +1338,9 @@
self.stopped = True
return w_result
- at unwrap_spec(w_r = (W_Root, 'space.w_None'))
-def W_Permutations__new__(space, w_subtype, w_iterable, w_r):
+def W_Permutations__new__(space, w_subtype, w_iterable, w_r=None):
pool_w = space.fixedview(w_iterable)
- if space.is_w(w_r, space.w_None):
+ if space.is_none(w_r):
r = len(pool_w)
else:
r = space.gateway_nonnegint_w(w_r)
diff --git a/pypy/module/micronumpy/interp_arrayops.py b/pypy/module/micronumpy/interp_arrayops.py
--- a/pypy/module/micronumpy/interp_arrayops.py
+++ b/pypy/module/micronumpy/interp_arrayops.py
@@ -4,10 +4,9 @@
from pypy.module.micronumpy.iter import Chunk, Chunks
from pypy.module.micronumpy.strides import shape_agreement
from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import unwrap_spec, is_none, W_Root
+from pypy.interpreter.gateway import unwrap_spec
- at unwrap_spec(w_x = (W_Root, 'space.w_None'), w_y = (W_Root, 'space.w_None'))
-def where(space, w_arr, w_x, w_y):
+def where(space, w_arr, w_x=None, w_y=None):
"""where(condition, [x, y])
Return elements, either from `x` or `y`, depending on `condition`.
@@ -67,12 +66,15 @@
NOTE: support for not passing x and y is unsupported
"""
- if space.is_w(w_y, space.w_None):
- if space.is_w(w_x, space.w_None):
+ if space.is_none(w_y):
+ if space.is_none(w_x):
raise OperationError(space.w_NotImplementedError, space.wrap(
"1-arg where unsupported right now"))
raise OperationError(space.w_ValueError, space.wrap(
"Where should be called with either 1 or 3 arguments"))
+ if space.is_none(w_x):
+ raise OperationError(space.w_ValueError, space.wrap(
+ "Where should be called with either 1 or 3 arguments"))
arr = convert_to_array(space, w_arr)
x = convert_to_array(space, w_x)
y = convert_to_array(space, w_y)
@@ -128,7 +130,7 @@
@unwrap_spec(repeats=int)
def repeat(space, w_arr, repeats, w_axis=None):
arr = convert_to_array(space, w_arr)
- if is_none(space, w_axis):
+ if space.is_none(w_axis):
arr = arr.descr_flatten(space)
orig_size = arr.get_shape()[0]
shape = [arr.get_shape()[0] * repeats]
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -1,8 +1,7 @@
from pypy.interpreter.error import operationerrfmt, OperationError
from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.interpreter.gateway import interp2app, unwrap_spec, is_none,\
- W_Root
+from pypy.interpreter.gateway import interp2app, unwrap_spec, W_Root
from pypy.module.micronumpy.base import W_NDimArray, convert_to_array,\
ArrayArgumentException
from pypy.module.micronumpy import interp_dtype, interp_ufuncs, interp_boxes
@@ -19,7 +18,7 @@
from pypy.rlib.rstring import StringBuilder
def _find_shape(space, w_size):
- if is_none(space, w_size):
+ if space.is_none(w_size):
return []
if space.isinstance_w(w_size, space.w_int):
return [space.int_w(w_size)]
@@ -296,7 +295,7 @@
return space.newlist(l_w)
def descr_ravel(self, space, w_order=None):
- if is_none(space, w_order):
+ if space.is_none(w_order):
order = 'C'
else:
order = space.str_w(w_order)
@@ -309,16 +308,16 @@
# if w_axis is None and w_out is Nont this is an equivalent to
# fancy indexing
raise Exception("unsupported for now")
- if not is_none(space, w_axis):
+ if not space.is_none(w_axis):
raise OperationError(space.w_NotImplementedError,
space.wrap("axis unsupported for take"))
- if not is_none(space, w_out):
+ if not space.is_none(w_out):
raise OperationError(space.w_NotImplementedError,
space.wrap("out unsupported for take"))
return self.getitem_int(space, convert_to_array(space, w_obj))
def descr_compress(self, space, w_obj, w_axis=None):
- if not is_none(space, w_axis):
+ if not space.is_none(w_axis):
raise OperationError(space.w_NotImplementedError,
space.wrap("axis unsupported for compress"))
index = convert_to_array(space, w_obj)
@@ -347,7 +346,7 @@
return coords
def descr_item(self, space, w_arg=None):
- if is_none(space, w_arg):
+ if space.is_none(w_arg):
if self.is_scalar():
return self.get_scalar_value().item(space)
if self.get_size() == 1:
@@ -493,7 +492,7 @@
def _reduce_ufunc_impl(ufunc_name, promote_to_largest=False):
def impl(self, space, w_axis=None, w_out=None, w_dtype=None):
- if is_none(space, w_out):
+ if space.is_none(w_out):
out = None
elif not isinstance(w_out, W_NDimArray):
raise OperationError(space.w_TypeError, space.wrap(
@@ -514,7 +513,7 @@
descr_any = _reduce_ufunc_impl('logical_or')
def descr_mean(self, space, w_axis=None, w_out=None):
- if is_none(space, w_axis):
+ if space.is_none(w_axis):
w_denom = space.wrap(self.get_size())
else:
axis = unwrap_axis_arg(space, len(self.get_shape()), w_axis)
@@ -536,9 +535,8 @@
@unwrap_spec(offset=int)
def descr_new_array(space, w_subtype, w_shape, w_dtype=None, w_buffer=None,
offset=0, w_strides=None, w_order=None):
- if (offset != 0 or is_none(space, w_strides) or
- not is_none(space, w_order) or
- not is_none(space, w_buffer)):
+ if (offset != 0 or space.is_none(w_strides) or not space.is_none(w_order) or
+ not space.is_none(w_buffer)):
raise OperationError(space.w_NotImplementedError,
space.wrap("unsupported param"))
dtype = space.interp_w(interp_dtype.W_Dtype,
@@ -649,12 +647,12 @@
def array(space, w_object, w_dtype=None, copy=True, w_order=None, subok=False,
ndmin=0):
if not space.issequence_w(w_object):
- if is_none(space, w_dtype):
+ if space.is_none(w_dtype):
w_dtype = interp_ufuncs.find_dtype_for_scalar(space, w_object)
dtype = space.interp_w(interp_dtype.W_Dtype,
space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
return W_NDimArray.new_scalar(space, dtype, w_object)
- if is_none(space, w_order):
+ if space.is_none(w_order):
order = 'C'
else:
order = space.str_w(w_order)
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -1,7 +1,6 @@
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import interp2app, unwrap_spec,\
- is_none
+from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef, GetSetProperty, interp_attrproperty
from pypy.module.micronumpy import interp_boxes, interp_dtype, loop
from pypy.rlib import jit
@@ -131,7 +130,7 @@
from pypy.module.micronumpy.interp_numarray import W_NDimArray
if w_axis is None:
w_axis = space.wrap(0)
- if is_none(space, w_out):
+ if space.is_none(w_out):
out = None
elif not isinstance(w_out, W_NDimArray):
raise OperationError(space.w_TypeError, space.wrap(
@@ -299,7 +298,7 @@
promote_bools=self.promote_bools,
allow_complex=self.allow_complex,
)
- if is_none(space, w_out):
+ if space.is_none(w_out):
out = None
elif not isinstance(w_out, W_NDimArray):
raise OperationError(space.w_TypeError, space.wrap(
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
@@ -164,7 +164,7 @@
@unwrap_spec(name=str)
def callfunc(self, space, name, w_returnType, w_parameters=None):
retvar = interp_variable.newVariableByType(space, self, w_returnType, 1)
- if space.is_w(w_parameters, space.w_None):
+ if space.is_none(w_parameters):
w_parameters = None
self._call(space, name, retvar, w_parameters)
@@ -174,7 +174,7 @@
@unwrap_spec(name=str)
def callproc(self, space, name, w_parameters=None):
- if space.is_w(w_parameters, space.w_None):
+ if space.is_none(w_parameters):
w_parameters = None
self._call(space, name, None, w_parameters)
@@ -763,7 +763,7 @@
return space.w_None
- def fetchmany(self, space, w_numRows=NoneNotWrapped):
+ def fetchmany(self, space, w_numRows=None):
if w_numRows is not None:
numRows = space.int_w(w_numRows)
else:
@@ -957,7 +957,7 @@
@unwrap_spec(size=int)
def var(self, space, w_type, size=0, w_arraysize=None,
w_inconverter=None, w_outconverter=None):
- if space.is_w(w_arraysize, space.w_None):
+ if space.is_none(w_arraysize):
arraySize = self.bindArraySize
else:
arraySize = space.int_w(w_arraysize)
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
@@ -1,7 +1,6 @@
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.interpreter.gateway import NoneNotWrapped
-from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.gateway import interp2app, unwrap_spec, W_Root
from pypy.interpreter.error import OperationError
from pypy.rlib import rgc
from pypy.rpython.lltypesystem import rffi, lltype
@@ -643,7 +642,7 @@
else:
context = space.str_w(w_context)
- if space.is_w(w_encoding, space.w_None):
+ if space.is_none(w_encoding):
encoding = None
else:
encoding = space.str_w(w_encoding)
@@ -774,10 +773,10 @@
)
def ParserCreate(space, w_encoding=None, w_namespace_separator=None,
- w_intern=NoneNotWrapped):
+ w_intern=None):
"""ParserCreate([encoding[, namespace_separator]]) -> parser
Return a new XML parser object."""
- if space.is_w(w_encoding, space.w_None):
+ if space.is_none(w_encoding):
encoding = None
elif space.is_true(space.isinstance(w_encoding, space.w_str)):
encoding = space.str_w(w_encoding)
@@ -788,7 +787,7 @@
space.wrap('ParserCreate() argument 1 must be string or None,'
' not %s' % (type_name,)))
- if space.is_w(w_namespace_separator, space.w_None):
+ if space.is_none(w_namespace_separator):
namespace_separator = 0
elif space.is_true(space.isinstance(w_namespace_separator, space.w_str)):
separator = space.str_w(w_namespace_separator)
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
@@ -354,7 +354,7 @@
def _get_inttime(space, w_seconds):
# w_seconds can be a wrapped None (it will be automatically wrapped
# in the callers, so we never get a real None here).
- if space.is_w(w_seconds, space.w_None):
+ if space.is_none(w_seconds):
seconds = pytime.time()
else:
seconds = space.float_w(w_seconds)
@@ -385,7 +385,10 @@
return space.call_function(w_struct_time, w_time_tuple)
def _gettmarg(space, w_tup, allowNone=True):
- if allowNone and space.is_w(w_tup, space.w_None):
+ if space.is_none(w_tup):
+ if not allowNone:
+ raise OperationError(space.w_TypeError,
+ space.wrap("tuple expected"))
# default to the current local time
tt = rffi.r_time_t(int(pytime.time()))
t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw')
diff --git a/pypy/objspace/std/typetype.py b/pypy/objspace/std/typetype.py
--- a/pypy/objspace/std/typetype.py
+++ b/pypy/objspace/std/typetype.py
@@ -6,8 +6,7 @@
from pypy.objspace.std.stdtypedef import StdTypeDef
-def descr__new__(space, w_typetype, w_name, w_bases=gateway.NoneNotWrapped,
- w_dict=gateway.NoneNotWrapped):
+def descr__new__(space, w_typetype, w_name, w_bases=None, w_dict=None):
"This is used to create user-defined classes only."
# XXX check types
diff --git a/pypy/objspace/std/unicodetype.py b/pypy/objspace/std/unicodetype.py
--- a/pypy/objspace/std/unicodetype.py
+++ b/pypy/objspace/std/unicodetype.py
@@ -216,11 +216,11 @@
return space.sys.defaultencoding
def _get_encoding_and_errors(space, w_encoding, w_errors):
- if space.is_w(w_encoding, space.w_None):
+ if space.is_none(w_encoding):
encoding = None
else:
encoding = space.str_w(w_encoding)
- if space.is_w(w_errors, space.w_None):
+ if space.is_none(w_errors):
errors = None
else:
errors = space.str_w(w_errors)
@@ -335,10 +335,8 @@
w_encoding, w_errors)
- at unwrap_spec(w_string = (W_Root, 'space.wrap("")'),
- w_encoding = (W_Root, 'space.w_None'),
- w_errors = (W_Root, 'space.w_None'))
-def descr_new_(space, w_unicodetype, w_string, w_encoding, w_errors):
+ at unwrap_spec(w_string = (W_Root, 'space.wrap("")'))
+def descr_new_(space, w_unicodetype, w_string, w_encoding=None, w_errors=None):
# NB. the default value of w_obj is really a *wrapped* empty string:
# there is gateway magic at work
from pypy.objspace.std.unicodeobject import W_UnicodeObject
More information about the pypy-commit
mailing list