[pypy-commit] pypy py3k-fix-strategies: progress
pjenvey
noreply at buildbot.pypy.org
Fri Apr 18 02:43:14 CEST 2014
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k-fix-strategies
Changeset: r70739:2caa57866049
Date: 2014-04-17 17:41 -0700
http://bitbucket.org/pypy/pypy/changeset/2caa57866049/
Log: progress
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1192,13 +1192,13 @@
w_ann = None
if num_annotations:
names_w = space.fixedview(self.popvalue())
- w_ann = space.newdict(strdict=True) # XXX: strdict??
+ w_ann = space.newdict(strdict=True)
for i in range(len(names_w) - 1, -1, -1):
space.setitem(w_ann, names_w[i], self.popvalue())
defaultarguments = self.popvalues(posdefaults)
w_kw_defs = None
if kwdefaults:
- w_kw_defs = space.newdict(strdict=True) # XXX:
+ w_kw_defs = space.newdict(strdict=True)
for i in range(kwdefaults - 1, -1, -1):
w_name = self.popvalue()
w_def = self.popvalue()
diff --git a/pypy/module/__pypy__/test/test_special.py b/pypy/module/__pypy__/test/test_special.py
--- a/pypy/module/__pypy__/test/test_special.py
+++ b/pypy/module/__pypy__/test/test_special.py
@@ -75,21 +75,18 @@
assert x == 42
def test_list_strategy(self):
- py3k_skip("XXX: strategies are currently broken")
from __pypy__ import list_strategy
l = [1, 2, 3]
assert list_strategy(l) == "int"
+ l = list(range(1, 2))
+ assert list_strategy(l) == "int"
l = [b"a", b"b", b"c"]
assert list_strategy(l) == "bytes"
l = ["a", "b", "c"]
assert list_strategy(l) == "unicode"
l = [1.1, 2.2, 3.3]
assert list_strategy(l) == "float"
- l = range(3)
- assert list_strategy(l) == "simple_range"
- l = range(1, 2)
- assert list_strategy(l) == "range"
l = [1, "b", 3]
assert list_strategy(l) == "object"
l = []
diff --git a/pypy/module/_cffi_backend/test/test_fastpath.py b/pypy/module/_cffi_backend/test/test_fastpath.py
--- a/pypy/module/_cffi_backend/test/test_fastpath.py
+++ b/pypy/module/_cffi_backend/test/test_fastpath.py
@@ -16,7 +16,6 @@
W_CType.pack_list_of_items = self._original
def test_fast_init_from_list(self):
- py3k_skip('XXX: strategies are currently broken')
import _cffi_backend
LONG = _cffi_backend.new_primitive_type('long')
P_LONG = _cffi_backend.new_pointer_type(LONG)
@@ -37,7 +36,6 @@
assert buf[2] == 3.3
def test_fast_init_short_from_list(self):
- py3k_skip('XXX: strategies are currently broken')
import _cffi_backend
SHORT = _cffi_backend.new_primitive_type('short')
P_SHORT = _cffi_backend.new_pointer_type(SHORT)
@@ -50,7 +48,6 @@
raises(OverflowError, _cffi_backend.newp, SHORT_ARRAY, [-40000])
def test_fast_init_longlong_from_list(self):
- py3k_skip('XXX: strategies are currently broken')
import _cffi_backend
import sys
large_int = 2 ** (50 if sys.maxsize > 2**31 - 1 else 30)
@@ -64,7 +61,6 @@
assert buf[3] == large_int
def test_fast_init_ushort_from_list(self):
- py3k_skip('XXX: strategies are currently broken')
import _cffi_backend
USHORT = _cffi_backend.new_primitive_type('unsigned short')
P_USHORT = _cffi_backend.new_pointer_type(USHORT)
@@ -77,18 +73,17 @@
raises(OverflowError, _cffi_backend.newp, USHORT_ARRAY, [-1])
def test_fast_init_ulong_from_list(self):
- py3k_skip('XXX: strategies are currently broken')
import sys
import _cffi_backend
ULONG = _cffi_backend.new_primitive_type('unsigned long')
P_ULONG = _cffi_backend.new_pointer_type(ULONG)
ULONG_ARRAY = _cffi_backend.new_array_type(P_ULONG, None)
- buf = _cffi_backend.newp(ULONG_ARRAY, [1, 2, sys.maxint])
+ buf = _cffi_backend.newp(ULONG_ARRAY, [1, 2, sys.maxsize])
assert buf[0] == 1
assert buf[1] == 2
- assert buf[2] == sys.maxint
+ assert buf[2] == sys.maxsize
raises(OverflowError, _cffi_backend.newp, ULONG_ARRAY, [-1])
- raises(OverflowError, _cffi_backend.newp, ULONG_ARRAY, [-sys.maxint])
+ raises(OverflowError, _cffi_backend.newp, ULONG_ARRAY, [-sys.maxsize])
def test_fast_init_cfloat_from_list(self):
import _cffi_backend
@@ -109,7 +104,6 @@
assert float(buf[1]) == -3.5
def test_fast_init_bool_from_list(self):
- py3k_skip('XXX: strategies are currently broken')
import _cffi_backend
BOOL = _cffi_backend.new_primitive_type('_Bool')
P_BOOL = _cffi_backend.new_pointer_type(BOOL)
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
@@ -621,8 +621,8 @@
l = space.listview_bytes(w_list)
if l is not None:
if len(l) == 1:
- return space.wrap(l[0])
- return space.wrap(self._val(space).join(l))
+ return space.wrapbytes(l[0])
+ return space.wrapbytes(self._val(space).join(l))
return self._StringMethods_descr_join(space, w_list)
def _join_return_one(self, space, w_obj):
diff --git a/pypy/objspace/std/celldict.py b/pypy/objspace/std/celldict.py
--- a/pypy/objspace/std/celldict.py
+++ b/pypy/objspace/std/celldict.py
@@ -30,7 +30,7 @@
def _wrapkey(space, key):
- return space.wrap(key)
+ return space.wrap(key.decode('utf-8'))
class ModuleDictStrategy(DictStrategy):
diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -824,8 +824,7 @@
return self.space.wrap(unwrapped)
def unwrap(self, wrapped):
- # XXX: bytes_w
- return self.space.str_w(wrapped)
+ return self.space.bytes_w(wrapped)
def is_correct_type(self, w_obj):
space = self.space
@@ -843,15 +842,13 @@
## assert key is not None
## self.unerase(w_dict.dstorage)[key] = w_value
- """
- def getitem(self, w_dict, w_key):
- space = self.space
- # -- This is called extremely often. Hack for performance --
- if type(w_key) is space.StringObjectCls:
- return self.unerase(w_dict.dstorage).get(self.unwrap(w_key), None)
- # -- End of performance hack --
- return AbstractTypedStrategy.getitem(self, w_dict, w_key)
- """
+ ##def getitem(self, w_dict, w_key):
+ ## space = self.space
+ ## # -- This is called extremely often. Hack for performance --
+ ## if type(w_key) is space.StringObjectCls:
+ ## return self.unerase(w_dict.dstorage).get(self.unwrap(w_key), None)
+ ## # -- End of performance hack --
+ ## return AbstractTypedStrategy.getitem(self, w_dict, w_key)
##def getitem_str(self, w_dict, key):
## assert key is not None
@@ -866,19 +863,19 @@
def wrapkey(space, key):
return space.wrapbytes(key)
- @jit.look_inside_iff(lambda self, w_dict:
- w_dict_unrolling_heuristic(w_dict))
- def view_as_kwargs(self, w_dict):
- return (None, None) # XXX: fix me to return unicode keys
- d = self.unerase(w_dict.dstorage)
- l = len(d)
- keys, values = [None] * l, [None] * l
- i = 0
- for key, val in d.iteritems():
- keys[i] = key
- values[i] = val
- i += 1
- return keys, values
+ ##@jit.look_inside_iff(lambda self, w_dict:
+ ## w_dict_unrolling_heuristic(w_dict))
+ ##def view_as_kwargs(self, w_dict):
+ ## return (None, None) # XXX: fix me to return unicode keys
+ ## d = self.unerase(w_dict.dstorage)
+ ## l = len(d)
+ ## keys, values = [None] * l, [None] * l
+ ## i = 0
+ ## for key, val in d.iteritems():
+ ## keys[i] = key
+ ## values[i] = val
+ ## i += 1
+ ## return keys, values
create_iterator_classes(BytesDictStrategy)
@@ -916,17 +913,6 @@
space = self.space
# -- This is called extremely often. Hack for performance --
if type(w_key) is space.UnicodeObjectCls:
- #return self.getitem_str(w_dict, w_key.unwrap(space))
- # XXX:
- #key = w_key.unwrap(space) # XXX:
- #return self.unerase(w_dict.dstorage).get(key, None)
- # XXX: triggers failure because s.unwrapped isn't set o_O
-
- #assert type(self) is UnicodeDictStrategy
- #key = self.unwrap(w_key)
- #assert key is not None
- #return self.unerase(w_dict.dstorage).get(key, None)
- #return self.unerase(w_dict.dstorage).get(self.unwrap(w_key), None)
return self.unerase(w_dict.dstorage).get(w_key.unwrap(space), None)
# -- End of performance hack --
return AbstractTypedStrategy.getitem(self, w_dict, w_key)
@@ -938,9 +924,8 @@
def listview_unicode(self, w_dict):
return self.unerase(w_dict.dstorage).keys()
- #def w_keys(self, w_dict):
- # # XXX: we can completely kill w_keys on py3k
- # return self.space.newlist_str(self.listview_str(w_dict))
+ def w_keys(self, w_dict):
+ return self.space.newlist_unicode(self.listview_unicode(w_dict))
def wrapkey(space, key):
return space.wrap(key)
@@ -977,8 +962,6 @@
def is_correct_type(self, w_obj):
from pypy.objspace.std.intobject import W_IntObject
- #space = self.space
- #return space.is_w(space.type(w_obj), space.w_int)
return type(w_obj) is W_IntObject
def _never_equal_to(self, w_lookup_type):
diff --git a/pypy/objspace/std/kwargsdict.py b/pypy/objspace/std/kwargsdict.py
--- a/pypy/objspace/std/kwargsdict.py
+++ b/pypy/objspace/std/kwargsdict.py
@@ -40,7 +40,6 @@
def is_correct_type(self, w_obj):
space = self.space
return space.is_w(space.type(w_obj), space.w_unicode)
- #return type(w_obj) is space.UnicodeObjectCls
def _never_equal_to(self, w_lookup_type):
return False
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -80,7 +80,6 @@
return space.fromcache(IntegerListStrategy)
# check for strings
- # XXX: StringListStrategy is currently broken
for w_obj in list_w:
if not type(w_obj) is W_BytesObject:
break
diff --git a/pypy/objspace/std/test/test_celldict.py b/pypy/objspace/std/test/test_celldict.py
--- a/pypy/objspace/std/test/test_celldict.py
+++ b/pypy/objspace/std/test/test_celldict.py
@@ -1,3 +1,4 @@
+# encoding: utf-8
import py
from pypy.objspace.std.celldict import ModuleDictStrategy
@@ -70,7 +71,6 @@
assert "ModuleDictStrategy" in __pypy__.internal_repr(obj)
def test_check_module_uses_module_dict(self):
- #py3k_skip("ModuleDictStrategy is immediately turned into ObjectDictStrategy because we use unicode keys now")
m = type(__builtins__)("abc")
self.impl_used(m.__dict__)
@@ -133,9 +133,12 @@
def setup_class(cls):
if cls.runappdirect:
py.test.skip("__repr__ doesn't work on appdirect")
- strategy = ModuleDictStrategy(cls.space)
+
+ def setup_method(self, method):
+ space = self.space
+ strategy = ModuleDictStrategy(space)
storage = strategy.get_empty_storage()
- cls.w_d = W_DictMultiObject(cls.space, strategy, storage)
+ self.w_d = W_DictMultiObject(space, strategy, storage)
def test_popitem(self):
import __pypy__
@@ -148,7 +151,6 @@
assert x == ("a", 3)
def test_degenerate(self):
- #py3k_skip("ModuleDictStrategy is immediately turned into ObjectDictStrategy because we use unicode keys now")
import __pypy__
d = self.d
@@ -157,3 +159,23 @@
del d["a"]
d[object()] = 5
assert list(d.values()) == [5]
+
+ def test_unicode(self):
+ import __pypy__
+
+ d = self.d
+ assert "ModuleDict" in __pypy__.internal_repr(d)
+ d['λ'] = True
+ assert "ModuleDict" in __pypy__.internal_repr(d)
+ assert list(d) == ['λ']
+ assert next(iter(d)) == 'λ'
+ assert "ModuleDict" in __pypy__.internal_repr(d)
+
+ d['foo'] = 'bar'
+ assert sorted(d) == ['foo', 'λ']
+ assert "ModuleDict" in __pypy__.internal_repr(d)
+
+ o = object()
+ d[o] = 'baz'
+ assert set(d) == set(['foo', 'λ', o])
+ assert "ObjectDictStrategy" in __pypy__.internal_repr(d)
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
@@ -125,7 +125,6 @@
assert self.space.eq_w(space.call_function(get, w("33"), w(44)), w(44))
def test_fromkeys_fastpath(self):
- py.test.py3k_skip("XXX: list strategies are currently broken")
space = self.space
w = space.wrap
wb = space.wrapbytes
@@ -175,8 +174,7 @@
w_d.initialize_content([(wb("a"), w(1)), (wb("b"), w(6))])
w_k = self.space.call_method(w_d, "keys")
w_l = self.space.call_function(self.space.w_list, w_k)
- #XXX: py.test.py3k_skip("XXX: list strategies are currently broken")
- #assert sorted(self.space.listview_bytes(w_l)) == ["a", "b"]
+ assert sorted(self.space.listview_bytes(w_l)) == ["a", "b"]
# XXX: it would be nice if the test passed without monkeypatch.undo(),
# but we need space.newlist_unicode for it
@@ -1018,8 +1016,10 @@
#raises(RuntimeError, list, it)
-class FakeWrapper(object):
+class FakeString(str):
+
hash_count = 0
+
def unwrap(self, space):
self.unwrapped = True
return str(self)
@@ -1028,13 +1028,13 @@
self.hash_count += 1
return str.__hash__(self)
-class FakeString(FakeWrapper, str):
+class FakeUnicode(unicode):
- def __hash__(self):
- self.hash_count += 1
- return str.__hash__(self)
+ hash_count = 0
-class FakeUnicode(FakeWrapper, unicode):
+ def unwrap(self, space):
+ self.unwrapped = True
+ return unicode(self)
def __hash__(self):
self.hash_count += 1
@@ -1168,7 +1168,7 @@
class BaseTestRDictImplementation:
FakeString = FakeUnicode
- allows__str = False # XXX: this is maybe not necessary, just add tests to unicode to ensure we're allowing utf-8?
+ _str_devolves = False
def setup_method(self,method):
self.fakespace = FakeSpace()
@@ -1177,8 +1177,6 @@
self.impl = self.get_impl()
def wrapstrorunicode(self, obj):
- # XXX: blargh this is all screwed. its referencing FakeString
- # and using regular strings to setitem.
return self.fakespace.wrap(obj)
def get_impl(self):
@@ -1208,7 +1206,7 @@
else:
assert a == self.string2
assert b == 2000
- if self.allows__str:
+ if not self._str_devolves:
result = self.impl.getitem_str(self.string)
else:
result = self.impl.getitem(self.string)
@@ -1219,7 +1217,7 @@
self.impl.setitem(self.string, 1000)
assert self.impl.length() == 1
assert self.impl.getitem(self.string) == 1000
- if self.allows__str:
+ if not self._str_devolves:
result = self.impl.getitem_str(self.string)
else:
result = self.impl.getitem(self.string)
@@ -1329,8 +1327,6 @@
class TestUnicodeDictImplementation(BaseTestRDictImplementation):
StrategyClass = UnicodeDictStrategy
- FakeString = FakeUnicode
- allows__str = True
def test_str_shortcut(self):
self.fill_impl()
@@ -1352,6 +1348,7 @@
class TestBytesDictImplementation(BaseTestRDictImplementation):
StrategyClass = BytesDictStrategy
FakeString = FakeString
+ _str_devolves = True
def wrapstrorunicode(self, obj):
return self.fakespace.wrapbytes(obj)
diff --git a/pypy/objspace/std/test/test_identitydict.py b/pypy/objspace/std/test/test_identitydict.py
--- a/pypy/objspace/std/test/test_identitydict.py
+++ b/pypy/objspace/std/test/test_identitydict.py
@@ -1,8 +1,6 @@
import py
from pypy.interpreter.gateway import interp2app
-py.test.py3k_skip("XXX: strategies are currently broken")
-
class AppTestComparesByIdentity:
spaceconfig = {"objspace.std.withidentitydict": True}
diff --git a/pypy/objspace/std/test/test_kwargsdict.py b/pypy/objspace/std/test/test_kwargsdict.py
--- a/pypy/objspace/std/test/test_kwargsdict.py
+++ b/pypy/objspace/std/test/test_kwargsdict.py
@@ -167,6 +167,7 @@
d = f(λ=True)
assert list(d) == ['λ']
+ assert next(iter(d)) == 'λ'
assert "KwargsDictStrategy" in self.get_strategy(d)
d['foo'] = 'bar'
diff --git a/pypy/objspace/std/test/test_listobject.py b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -402,7 +402,6 @@
self.space.w_True)
def test_sizehint(self):
- py.test.py3k_skip("XXX: strategies are currently broken")
space = self.space
w_l = space.newlist([], sizehint=10)
assert isinstance(w_l.strategy, SizeListStrategy)
@@ -419,7 +418,6 @@
assert w_lst.strategy.sizehint == 13
def test_find_fast_on_intlist(self, monkeypatch):
- py.test.py3k_skip("XXX: strategies are currently broken")
monkeypatch.setattr(self.space, "eq_w", None)
w = self.space.wrap
intlist = W_ListObject(self.space, [w(1),w(2),w(3),w(4),w(5),w(6),w(7)])
diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -1,4 +1,3 @@
-import py
import sys
from pypy.objspace.std.listobject import (
W_ListObject, EmptyListStrategy, ObjectListStrategy, IntegerListStrategy,
@@ -7,7 +6,6 @@
from pypy.objspace.std import listobject
from pypy.objspace.std.test.test_listobject import TestW_ListObject
-#py.test.py3k_skip("XXX: strategies are currently broken")
class TestW_ListStrategies(TestW_ListObject):
def test_check_strategy(self):
@@ -580,9 +578,11 @@
assert not self.space.eq_w(l1, l2)
def test_weird_rangelist_bug(self):
- l = make_range_list(self.space, 1, 1, 3)
+ space = self.space
+ l = make_range_list(space, 1, 1, 3)
# should not raise
- assert l.descr_getslice(self.space, self.space.wrap(15), self.space.wrap(2222)).strategy == self.space.fromcache(EmptyListStrategy)
+ w_slice = space.newslice(space.wrap(15), space.wrap(2222), space.wrap(1))
+ assert l.descr_getitem(space, w_slice).strategy == space.fromcache(EmptyListStrategy)
def test_add_to_rangelist(self):
l1 = make_range_list(self.space, 1, 1, 3)
@@ -681,8 +681,6 @@
assert space.unwrap(w_res) == 3
def test_create_list_from_set(self):
- # this test fails because of the "w_set.iter = None" line below
- py.test.py3k_skip("missing the correct list strategy")
from pypy.objspace.std.setobject import W_SetObject
from pypy.objspace.std.setobject import _initialize_set
diff --git a/pypy/objspace/std/test/test_setobject.py b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -84,7 +84,6 @@
assert space.is_true(self.space.eq(result, W_SetObject(space, self.space.wrap(""))))
def test_create_set_from_list(self):
- py.test.py3k_skip("XXX: strategies are currently broken")
from pypy.interpreter.baseobjspace import W_Root
from pypy.objspace.std.setobject import BytesSetStrategy, ObjectSetStrategy, UnicodeSetStrategy
from pypy.objspace.std.floatobject import W_FloatObject
@@ -131,11 +130,11 @@
intstr.get_storage_from_list = tmp_func
def test_listview_bytes_int_on_set(self):
- py.test.py3k_skip("XXX: strategies are currently broken")
w = self.space.wrap
+ wb = self.space.wrapbytes
w_a = W_SetObject(self.space)
- _initialize_set(self.space, w_a, w("abcdefg"))
+ _initialize_set(self.space, w_a, wb("abcdefg"))
assert sorted(self.space.listview_bytes(w_a)) == list("abcdefg")
assert self.space.listview_int(w_a) is None
diff --git a/pypy/objspace/std/test/test_setstrategies.py b/pypy/objspace/std/test/test_setstrategies.py
--- a/pypy/objspace/std/test/test_setstrategies.py
+++ b/pypy/objspace/std/test/test_setstrategies.py
@@ -5,9 +5,6 @@
UnicodeIteratorImplementation, UnicodeSetStrategy)
from pypy.objspace.std.listobject import W_ListObject
-import py
-py.test.py3k_skip("XXX: strategies are currently broken")
-
class TestW_SetStrategies:
def wrapped(self, l, bytes=False):
More information about the pypy-commit
mailing list