Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r58115:d4d809ec6f36
Date: 2012-10-14 17:33 -0700
http://bitbucket.org/pypy/pypy/changeset/d4d809ec6f36/
Log: rework py3k's bytes workaround directly to WrappedDefault
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -852,8 +852,7 @@
def _getdefaults(self, space):
"NOT_RPYTHON"
defs_w = []
- unwrap_spec = self._code._unwrap_spec[-len(self._staticdefs):]
- for i, (name, defaultval) in enumerate(self._staticdefs):
+ for name, defaultval in self._staticdefs:
if name.startswith('w_'):
assert defaultval is None, (
"%s: default value for '%s' can only be None; "
@@ -861,11 +860,7 @@
self._code.identifier, name))
defs_w.append(None)
else:
- spec = unwrap_spec[i]
- if isinstance(defaultval, str) and spec not in [str]:
- defs_w.append(space.wrapbytes(defaultval))
- else:
- defs_w.append(space.wrap(defaultval))
+ defs_w.append(space.wrap(defaultval))
if self._code._unwrap_spec:
UNDEFINED = object()
alldefs_w = [UNDEFINED] * len(self._code.sig[0])
@@ -881,7 +876,11 @@
if isinstance(spec, tuple) and spec[0] is W_Root:
assert False, "use WrappedDefault"
if isinstance(spec, WrappedDefault):
- w_default = space.wrap(spec.default_value)
+ default_value = spec.default_value
+ if isinstance(default_value, str):
+ w_default = space.wrapbytes(default_value)
+ else:
+ w_default = space.wrap(default_value)
assert isinstance(w_default, W_Root)
assert argname.startswith('w_')
argname = argname[2:]
diff --git a/pypy/interpreter/test/test_gateway.py
b/pypy/interpreter/test/test_gateway.py
--- a/pypy/interpreter/test/test_gateway.py
+++ b/pypy/interpreter/test/test_gateway.py
@@ -611,6 +611,16 @@
never_called
py.test.raises(AssertionError, space.wrap, gateway.interp2app_temp(g))
+ def test_unwrap_spec_default_applevel_bytes(self):
+ space = self.space
+ @gateway.unwrap_spec(w_x=WrappedDefault('foo'))
+ def g(space, w_x):
+ return w_x
+ w_g = space.wrap(gateway.interp2app_temp(g))
+ args = argument.Arguments(space, [])
+ w_res = space.call_args(w_g, args)
+ assert space.eq_w(w_res, space.wrapbytes('foo'))
+
class AppTestPyTestMark:
@py.test.mark.unlikely_to_exist
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit