[pypy-commit] pypy py3.5: hg merge py3k
arigo
pypy.commits at gmail.com
Sat Aug 27 13:16:21 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r86613:58fe0ad0ec9d
Date: 2016-08-27 19:15 +0200
http://bitbucket.org/pypy/pypy/changeset/58fe0ad0ec9d/
Log: hg merge py3k
diff --git a/pypy/module/marshal/interp_marshal.py b/pypy/module/marshal/interp_marshal.py
--- a/pypy/module/marshal/interp_marshal.py
+++ b/pypy/module/marshal/interp_marshal.py
@@ -233,15 +233,6 @@
def dump_w_obj(self, w_obj):
space = self.space
- if space.type(w_obj).is_heaptype():
- try:
- buf = space.readbuf_w(w_obj)
- except OperationError as e:
- if not e.match(space, space.w_TypeError):
- raise
- self.raise_exc("unmarshallable object")
- else:
- w_obj = space.newbuffer(buf)
try:
self.put_w_obj(w_obj)
except rstackovf.StackOverflow:
diff --git a/pypy/module/marshal/test/test_marshal.py b/pypy/module/marshal/test/test_marshal.py
--- a/pypy/module/marshal/test/test_marshal.py
+++ b/pypy/module/marshal/test/test_marshal.py
@@ -186,6 +186,8 @@
assert str(exc.value) == 'unmarshallable object'
exc = raises(ValueError, marshal.dumps, subtype())
assert str(exc.value) == 'unmarshallable object'
+ exc = raises(ValueError, marshal.dumps, (subtype(),))
+ assert str(exc.value) == 'unmarshallable object'
def test_valid_subtypes(self):
import marshal
diff --git a/pypy/objspace/std/marshal_impl.py b/pypy/objspace/std/marshal_impl.py
--- a/pypy/objspace/std/marshal_impl.py
+++ b/pypy/objspace/std/marshal_impl.py
@@ -64,10 +64,13 @@
def marshal(space, w_obj, m):
# _marshallers_unroll is defined at the end of the file
- for type, func in _marshallers_unroll:
- if isinstance(w_obj, type):
- func(space, w_obj, m)
- return
+ # NOTE that if w_obj is a heap type, like an instance of a
+ # user-defined subclass, then we skip that part completely!
+ if not space.type(w_obj).is_heaptype():
+ for type, func in _marshallers_unroll:
+ if isinstance(w_obj, type):
+ func(space, w_obj, m)
+ return
# any unknown object implementing the buffer protocol is
# accepted and encoded as a plain string
diff --git a/pypy/objspace/std/test/test_random_attr.py b/pypy/objspace/std/test/test_random_attr.py
--- a/pypy/objspace/std/test/test_random_attr.py
+++ b/pypy/objspace/std/test/test_random_attr.py
@@ -2,6 +2,12 @@
import sys
from pypy.tool.pytest.objspace import gettestobjspace
try:
+ import __pypy__
+except ImportError:
+ pass
+else:
+ pytest.skip("makes no sense under pypy!")
+try:
from hypothesis import given, strategies, settings
except ImportError:
pytest.skip("requires hypothesis")
@@ -18,26 +24,25 @@
attrnames = strategies.sampled_from(["a", "b", "c"])
@strategies.composite
+def class_attr(draw):
+ what = draw(strategies.sampled_from(["value", "method", "property"]))
+ if what == "value":
+ val = draw(strategies.integers())
+ return val, str(val)
+ if what == "method":
+ val = draw(strategies.integers())
+ return (lambda self, val=val: val,
+ "lambda self: %d" % val)
+ if what == "property":
+ val = draw(strategies.integers())
+ return (property(lambda self, val=val: val,
+ lambda self, val: None,
+ lambda self: None),
+ "property(lambda self: %d, lambda self, val: None, lambda self: None)" % val)
+
+ at strategies.composite
def make_code(draw):
- # now here we can do this kind of thing:
baseclass, initargs, hasdict = draw(base_initargs)
- # and with arbitrary strategies
-
- def class_attr():
- what = draw(strategies.sampled_from(["value", "method", "property"]))
- if what == "value":
- val = draw(strategies.integers())
- return val, str(val)
- if what == "method":
- val = draw(strategies.integers())
- return (lambda self, val=val: val,
- "lambda self: %d" % val)
- if what == "property":
- val = draw(strategies.integers())
- return (property(lambda self, val=val: val,
- lambda self, val: None,
- lambda self: None),
- "property(lambda self: %d, lambda self, val: None, lambda self: None)" % val)
code = ["import sys", "class OldBase:pass", "class NewBase(object):pass", "class A(%s):" % baseclass]
dct = {}
@@ -50,7 +55,7 @@
for name in ["a", "b", "c"]:
if not draw(strategies.booleans()):
continue
- dct[name], codeval = class_attr()
+ dct[name], codeval = draw(class_attr())
code.append(" %s = %s" % (name, codeval))
class OldBase: pass
class NewBase(object): pass
@@ -94,11 +99,11 @@
else:
code.append("a.%s = lambda : %s" % (attr, val))
elif op == "writeclass":
- val, codeval = class_attr()
+ val, codeval = draw(class_attr())
setattr(cls, attr, val)
code.append("A.%s = %s" % (attr, codeval))
elif op == "writebase":
- val, codeval = class_attr()
+ val, codeval = draw(class_attr())
setattr(OldBase, attr, val)
setattr(NewBase, attr, val)
code.append("OldBase.%s = NewBase.%s = %s" % (attr, attr , codeval))
@@ -119,16 +124,9 @@
return "\n ".join(code)
- at given(make_code())
+ at given(code=make_code())
#@settings(max_examples=5000)
-def test_random_attrs(code):
- try:
- import __pypy__
- except ImportError:
- pass
- else:
- pytest.skip("makes no sense under pypy!")
- space = gettestobjspace()
+def test_random_attrs(code, space):
print code
exec "if 1:\n " + code
space.appexec([], "():\n " + code)
More information about the pypy-commit
mailing list