[pypy-commit] pypy refactor-str-types: Remove all ``@specialize.argtype(0)`` and use import_from_mixin().
Manuel Jacob
noreply at buildbot.pypy.org
Tue Aug 20 16:03:53 CEST 2013
Author: Manuel Jacob
Branch: refactor-str-types
Changeset: r66263:e75b57683b2b
Date: 2013-08-20 16:00 +0200
http://bitbucket.org/pypy/pypy/changeset/e75b57683b2b/
Log: Remove all ``@specialize.argtype(0)`` and use import_from_mixin().
diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -9,14 +9,16 @@
from pypy.objspace.std.stdtypedef import StdTypeDef
from pypy.objspace.std.stringmethods import StringMethods
from pypy.objspace.std.util import get_positive_index
-from rpython.rlib.objectmodel import newlist_hint, resizelist_hint
+from rpython.rlib.objectmodel import newlist_hint, resizelist_hint, import_from_mixin
from rpython.rlib.rstring import StringBuilder
def _make_data(s):
return [s[i] for i in range(len(s))]
-class W_BytearrayObject(W_Root, StringMethods):
+class W_BytearrayObject(W_Root):
+ import_from_mixin(StringMethods)
+
def __init__(w_self, data):
w_self.data = data
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -12,7 +12,7 @@
from pypy.objspace.std.unicodeobject import (unicode_from_string,
decode_object, unicode_from_encoded_object, _get_encoding_and_errors)
from rpython.rlib.jit import we_are_jitted
-from rpython.rlib.objectmodel import compute_hash, compute_unique_id
+from rpython.rlib.objectmodel import compute_hash, compute_unique_id, import_from_mixin
from rpython.rlib.rstring import StringBuilder, replace
@@ -424,7 +424,8 @@
pass
-class W_BytesObject(StringMethods, W_AbstractBytesObject):
+class W_BytesObject(W_AbstractBytesObject):
+ import_from_mixin(StringMethods)
_immutable_fields_ = ['_value']
def __init__(self, str):
diff --git a/pypy/objspace/std/stringmethods.py b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -9,8 +9,6 @@
class StringMethods(object):
- _mixin_ = True
-
def _sliced(self, space, s, start, stop, orig_obj):
assert start >= 0
assert stop >= 0
@@ -26,7 +24,6 @@
space, lenself, w_start, w_end, upper_bound=upper_bound)
return (value, start, end)
- @specialize.argtype(0)
def descr_eq(self, space, w_other):
try:
return space.newbool(self._val(space) == self._op_val(space, w_other))
@@ -42,7 +39,6 @@
return space.w_False
raise
- @specialize.argtype(0)
def descr_ne(self, space, w_other):
try:
return space.newbool(self._val(space) != self._op_val(space, w_other))
@@ -58,7 +54,6 @@
return space.w_True
raise
- @specialize.argtype(0)
def descr_lt(self, space, w_other):
try:
return space.newbool(self._val(space) < self._op_val(space, w_other))
@@ -66,7 +61,6 @@
if e.match(space, space.w_TypeError):
return space.w_NotImplemented
- @specialize.argtype(0)
def descr_le(self, space, w_other):
try:
return space.newbool(self._val(space) <= self._op_val(space, w_other))
@@ -74,7 +68,6 @@
if e.match(space, space.w_TypeError):
return space.w_NotImplemented
- @specialize.argtype(0)
def descr_gt(self, space, w_other):
try:
return space.newbool(self._val(space) > self._op_val(space, w_other))
@@ -82,7 +75,6 @@
if e.match(space, space.w_TypeError):
return space.w_NotImplemented
- @specialize.argtype(0)
def descr_ge(self, space, w_other):
try:
return space.newbool(self._val(space) >= self._op_val(space, w_other))
@@ -90,15 +82,12 @@
if e.match(space, space.w_TypeError):
return space.w_NotImplemented
- @specialize.argtype(0)
def descr_len(self, space):
return space.wrap(self._len())
- #@specialize.argtype(0)
#def descr_iter(self, space):
# pass
- @specialize.argtype(0)
def descr_contains(self, space, w_sub):
from pypy.objspace.std.bytearrayobject import W_BytearrayObject
if (isinstance(self, W_BytearrayObject) and
@@ -113,11 +102,9 @@
return space.w_False
return space.newbool(self._val(space).find(self._op_val(space, w_sub)) >= 0)
- @specialize.argtype(0)
def descr_add(self, space, w_other):
return self._new(self._val(space) + self._op_val(space, w_other))
- @specialize.argtype(0)
def descr_mul(self, space, w_times):
try:
times = space.getindex_w(w_times, space.w_OverflowError)
@@ -131,7 +118,6 @@
return self._new(self._val(space)[0] * times)
return self._new(self._val(space) * times)
- @specialize.argtype(0)
def descr_getitem(self, space, w_index):
if isinstance(w_index, W_SliceObject):
selfvalue = self._val(space)
@@ -160,7 +146,6 @@
#return wrapchar(space, selfvalue[index])
return self._new(selfvalue[index])
- @specialize.argtype(0)
def descr_getslice(self, space, w_start, w_stop):
selfvalue = self._val(space)
start, stop = normalize_simple_slice(space, len(selfvalue), w_start,
@@ -170,7 +155,6 @@
else:
return self._sliced(space, selfvalue, start, stop, self)
- @specialize.argtype(0)
def descr_capitalize(self, space):
value = self._val(space)
if len(value) == 0:
@@ -183,7 +167,6 @@
return self._new(builder.build())
@unwrap_spec(width=int, w_fillchar=WrappedDefault(' '))
- @specialize.argtype(0)
def descr_center(self, space, width, w_fillchar):
value = self._val(space)
fillchar = self._op_val(space, w_fillchar)
@@ -201,12 +184,10 @@
return self._new(u_centered)
- @specialize.argtype(0)
def descr_count(self, space, w_sub, w_start=None, w_end=None):
value, start, end = self._convert_idx_params(space, w_start, w_end)
return space.newint(value.count(self._op_val(space, w_sub), start, end))
- @specialize.argtype(0)
def descr_decode(self, space, w_encoding=None, w_errors=None):
from pypy.objspace.std.unicodeobject import _get_encoding_and_errors, \
unicode_from_string, decode_object
@@ -215,7 +196,6 @@
return unicode_from_string(space, self)
return decode_object(space, self, encoding, errors)
- @specialize.argtype(0)
def descr_encode(self, space, w_encoding=None, w_errors=None):
from pypy.objspace.std.unicodeobject import _get_encoding_and_errors, \
encode_object
@@ -223,7 +203,6 @@
return encode_object(space, self, encoding, errors)
@unwrap_spec(tabsize=int)
- @specialize.argtype(0)
def descr_expandtabs(self, space, tabsize=8):
value = self._val(space)
if not value:
@@ -266,19 +245,16 @@
return distance
- @specialize.argtype(0)
def descr_find(self, space, w_sub, w_start=None, w_end=None):
(value, start, end) = self._convert_idx_params(space, w_start, w_end)
res = value.find(self._op_val(space, w_sub), start, end)
return space.wrap(res)
- @specialize.argtype(0)
def descr_rfind(self, space, w_sub, w_start=None, w_end=None):
(value, start, end) = self._convert_idx_params(space, w_start, w_end)
res = value.rfind(self._op_val(space, w_sub), start, end)
return space.wrap(res)
- @specialize.argtype(0)
def descr_index(self, space, w_sub, w_start=None, w_end=None):
(value, start, end) = self._convert_idx_params(space, w_start, w_end)
res = value.find(self._op_val(space, w_sub), start, end)
@@ -288,7 +264,6 @@
return space.wrap(res)
- @specialize.argtype(0)
def descr_rindex(self, space, w_sub, w_start=None, w_end=None):
(value, start, end) = self._convert_idx_params(space, w_start, w_end)
res = value.rfind(self._op_val(space, w_sub), start, end)
@@ -318,19 +293,15 @@
return space.w_False
return space.w_True
- @specialize.argtype(0)
def descr_isalnum(self, space):
return self._is_generic(space, '_isalnum')
- @specialize.argtype(0)
def descr_isalpha(self, space):
return self._is_generic(space, '_isalpha')
- @specialize.argtype(0)
def descr_isdigit(self, space):
return self._is_generic(space, '_isdigit')
- @specialize.argtype(0)
def descr_islower(self, space):
v = self._val(space)
if len(v) == 1:
@@ -344,11 +315,9 @@
cased = True
return space.newbool(cased)
- @specialize.argtype(0)
def descr_isspace(self, space):
return self._is_generic(space, '_isspace')
- @specialize.argtype(0)
def descr_istitle(self, space):
input = self._val(space)
cased = False
@@ -370,7 +339,6 @@
return space.newbool(cased)
- @specialize.argtype(0)
def descr_isupper(self, space):
v = self._val(space)
if len(v) == 1:
@@ -384,7 +352,6 @@
cased = True
return space.newbool(cased)
- @specialize.argtype(0)
def descr_join(self, space, w_list):
from pypy.objspace.std.bytesobject import W_BytesObject
from pypy.objspace.std.unicodeobject import W_UnicodeObject
@@ -445,7 +412,6 @@
assert False, 'unreachable'
@unwrap_spec(width=int, w_fillchar=WrappedDefault(' '))
- @specialize.argtype(0)
def descr_ljust(self, space, width, w_fillchar):
value = self._val(space)
fillchar = self._op_val(space, w_fillchar)
@@ -461,7 +427,6 @@
return self._new(value)
@unwrap_spec(width=int, w_fillchar=WrappedDefault(' '))
- @specialize.argtype(0)
def descr_rjust(self, space, width, w_fillchar):
value = self._val(space)
fillchar = self._op_val(space, w_fillchar)
@@ -476,7 +441,6 @@
return self._new(value)
- @specialize.argtype(0)
def descr_lower(self, space):
value = self._val(space)
builder = self._builder(len(value))
@@ -484,7 +448,6 @@
builder.append(self._lower(value[i]))
return self._new(builder.build())
- @specialize.argtype(0)
def descr_partition(self, space, w_sub):
value = self._val(space)
sub = self._op_val(space, w_sub)
@@ -505,7 +468,6 @@
[self._sliced(space, value, 0, pos, self), w_sub,
self._sliced(space, value, pos+len(sub), len(value), self)])
- @specialize.argtype(0)
def descr_rpartition(self, space, w_sub):
value = self._val(space)
sub = self._op_val(space, w_sub)
@@ -527,7 +489,6 @@
self._sliced(space, value, pos+len(sub), len(value), self)])
@unwrap_spec(count=int)
- @specialize.argtype(0)
def descr_replace(self, space, w_old, w_new, count=-1):
input = self._val(space)
sub = self._op_val(space, w_old)
@@ -540,7 +501,6 @@
return self._new(res)
@unwrap_spec(maxsplit=int)
- @specialize.argtype(0)
def descr_split(self, space, w_sep=None, maxsplit=-1):
res = []
value = self._val(space)
@@ -581,7 +541,6 @@
return self._newlist_unwrapped(space, res)
@unwrap_spec(maxsplit=int)
- @specialize.argtype(0)
def descr_rsplit(self, space, w_sep=None, maxsplit=-1):
res = []
value = self._val(space)
@@ -625,7 +584,6 @@
return self._newlist_unwrapped(space, res)
@unwrap_spec(keepends=bool)
- @specialize.argtype(0)
def descr_splitlines(self, space, keepends=False):
value = self._val(space)
length = len(value)
@@ -647,7 +605,6 @@
strs.append(value[pos:length])
return self._newlist_unwrapped(space, strs)
- @specialize.argtype(0)
def descr_startswith(self, space, w_prefix, w_start=None, w_end=None):
(value, start, end) = self._convert_idx_params(space, w_start, w_end,
True)
@@ -658,11 +615,9 @@
return space.w_False
return space.newbool(self._startswith(space, value, w_prefix, start, end))
- @specialize.argtype(0)
def _startswith(self, space, value, w_prefix, start, end):
return startswith(value, self._op_val(space, w_prefix), start, end)
- @specialize.argtype(0)
def descr_endswith(self, space, w_suffix, w_start=None, w_end=None):
(value, start, end) = self._convert_idx_params(space, w_start,
w_end, True)
@@ -674,7 +629,6 @@
return space.w_False
return space.newbool(self._endswith(space, value, w_suffix, start, end))
- @specialize.argtype(0)
def _endswith(self, space, value, w_prefix, start, end):
return endswith(value, self._op_val(space, w_prefix), start, end)
@@ -717,25 +671,21 @@
assert rpos >= lpos # annotator hint, don't remove
return self._sliced(space, value, lpos, rpos, self)
- @specialize.argtype(0)
def descr_strip(self, space, w_chars=None):
if space.is_none(w_chars):
return self._strip_none(space, left=1, right=1)
return self._strip(space, w_chars, left=1, right=1)
- @specialize.argtype(0)
def descr_lstrip(self, space, w_chars=None):
if space.is_none(w_chars):
return self._strip_none(space, left=1, right=0)
return self._strip(space, w_chars, left=1, right=0)
- @specialize.argtype(0)
def descr_rstrip(self, space, w_chars=None):
if space.is_none(w_chars):
return self._strip_none(space, left=0, right=1)
return self._strip(space, w_chars, left=0, right=1)
- @specialize.argtype(0)
def descr_swapcase(self, space):
selfvalue = self._val(space)
builder = self._builder(len(selfvalue))
@@ -749,7 +699,6 @@
builder.append(ch)
return self._new(builder.build())
- @specialize.argtype(0)
def descr_title(self, space):
selfval = self._val(space)
if len(selfval) == 0:
@@ -770,7 +719,6 @@
# for bytes and bytearray, overridden by unicode
@unwrap_spec(w_deletechars=WrappedDefault(''))
- @specialize.argtype(0)
def descr_translate(self, space, w_table, w_deletechars):
if space.is_w(w_table, space.w_None):
table = self.DEFAULT_NOOP_TABLE
@@ -797,7 +745,6 @@
buf.append(table[ord(char)])
return self._new(buf.build())
- @specialize.argtype(0)
def descr_upper(self, space):
value = self._val(space)
builder = self._builder(len(value))
@@ -806,7 +753,6 @@
return self._new(builder.build())
@unwrap_spec(width=int)
- @specialize.argtype(0)
def descr_zfill(self, space, width):
selfval = self._val(space)
if len(selfval) == 0:
@@ -827,6 +773,5 @@
builder.append_slice(selfval, start, len(selfval))
return self._new(builder.build())
- @specialize.argtype(0)
def descr_getnewargs(self, space):
return space.newtuple([self._new(self._val(space))])
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -10,7 +10,7 @@
from pypy.objspace.std.formatting import mod_format
from pypy.objspace.std.stdtypedef import StdTypeDef
from pypy.objspace.std.stringmethods import StringMethods
-from rpython.rlib.objectmodel import compute_hash, compute_unique_id
+from rpython.rlib.objectmodel import compute_hash, compute_unique_id, import_from_mixin
from rpython.rlib.rstring import UnicodeBuilder
from rpython.rlib.runicode import (str_decode_utf_8, str_decode_ascii,
unicode_encode_utf_8, unicode_encode_ascii, make_unicode_escape_function)
@@ -20,7 +20,8 @@
'unicode_from_string', 'unicode_to_decimal_w']
-class W_UnicodeObject(W_Root, StringMethods):
+class W_UnicodeObject(W_Root):
+ import_from_mixin(StringMethods)
_immutable_fields_ = ['_value']
def __init__(w_self, unistr):
More information about the pypy-commit
mailing list