Author: Carl Friedrich Bolz <[email protected]>
Branch: space-newtext
Changeset: r88817:4c2b7177aeea
Date: 2016-12-02 13:00 +0100
http://bitbucket.org/pypy/pypy/changeset/4c2b7177aeea/
Log: fixes
diff --git a/pypy/interpreter/astcompiler/ast.py
b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -51,7 +51,7 @@
self.fields = fields
def spacebind(self, space):
- return space.newtuple([space.wrap(field) for field in self.fields])
+ return space.newtuple([space.newtext(field) for field in self.fields])
class W_AST(W_Root):
@@ -1240,7 +1240,7 @@
def to_object(self, space):
w_node = space.call_function(get(space).w_ImportFrom)
- w_module = space.newtext(self.module) # identifier
+ w_module = space.newtext_or_none(self.module) # identifier
space.setattr(w_node, space.newtext('module'), w_module)
if self.names is None:
names_w = []
@@ -3248,9 +3248,9 @@
args_w = [node.to_object(space) for node in self.args] # expr
w_args = space.newlist(args_w)
space.setattr(w_node, space.newtext('args'), w_args)
- w_vararg = space.newtext(self.vararg) # identifier
+ w_vararg = space.newtext_or_none(self.vararg) # identifier
space.setattr(w_node, space.newtext('vararg'), w_vararg)
- w_kwarg = space.newtext(self.kwarg) # identifier
+ w_kwarg = space.newtext_or_none(self.kwarg) # identifier
space.setattr(w_node, space.newtext('kwarg'), w_kwarg)
if self.defaults is None:
defaults_w = []
@@ -3323,7 +3323,7 @@
w_node = space.call_function(get(space).w_alias)
w_name = space.newtext(self.name) # identifier
space.setattr(w_node, space.newtext('name'), w_name)
- w_asname = space.newtext(self.asname) # identifier
+ w_asname = space.newtext_or_none(self.asname) # identifier
space.setattr(w_node, space.newtext('asname'), w_asname)
return w_node
diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py
b/pypy/interpreter/astcompiler/tools/asdl_py.py
--- a/pypy/interpreter/astcompiler/tools/asdl_py.py
+++ b/pypy/interpreter/astcompiler/tools/asdl_py.py
@@ -132,6 +132,8 @@
elif field.type.value == "int":
return "space.newint(%s)" % (value,)
elif field.type.value == "identifier":
+ if field.opt:
+ return "space.newtext_or_none(%s)" % (value,)
return "space.newtext(%s)" % (value,)
else:
wrapper = "%s.to_object(space)" % (value,)
diff --git a/pypy/module/cpyext/test/test_object.py
b/pypy/module/cpyext/test/test_object.py
--- a/pypy/module/cpyext/test/test_object.py
+++ b/pypy/module/cpyext/test/test_object.py
@@ -37,7 +37,7 @@
assert not hasattr_(space.w_int, 'nonexistingattr')
buf = rffi.str2charp('__len__')
- assert api.PyObject_HasAttrString(space.w_str, buf)
+ assert api.PyObject_HasAttrString(space.w_bytes, buf)
assert not api.PyObject_HasAttrString(space.w_int, buf)
rffi.free_charp(buf)
diff --git a/pypy/module/micronumpy/compile.py
b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -297,11 +297,11 @@
def index(self, w_obj):
return self.wrap(self.int_w(w_obj))
- def str_w(self, w_obj):
+ def bytes_w(self, w_obj):
if isinstance(w_obj, StringObject):
return w_obj.v
raise NotImplementedError
- text_w = str_w
+ text_w = bytes_w
def unicode_w(self, w_obj):
# XXX
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -4,7 +4,8 @@
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.objspace.std.sliceobject import W_SliceObject
from rpython.rlib.buffer import StringBuffer
-from rpython.rlib.objectmodel import instantiate, we_are_translated, specialize
+from rpython.rlib.objectmodel import (instantiate, we_are_translated,
specialize,
+ not_rpython)
from rpython.rlib.nonconst import NonConstant
from rpython.rlib.rarithmetic import r_uint, r_singlefloat
from rpython.rtyper.extregistry import ExtRegistryEntry
@@ -141,8 +142,8 @@
is_root(w_obj)
return NonConstant(False)
+ @not_rpython
def unwrap(self, w_obj):
- "NOT_RPYTHON"
raise NotImplementedError
def newdict(self, module=False, instance=False, kwargs=False,
@@ -194,8 +195,8 @@
def newbuffer(self, x):
return w_some_obj()
+ @not_rpython
def marshal_w(self, w_obj):
- "NOT_RPYTHON"
raise NotImplementedError
def newbytes(self, x):
@@ -207,7 +208,7 @@
newtext = newbytes
newtext_or_none = newbytes
- @specialize.argtype(1)
+ @not_rpython
def wrap(self, x):
if not we_are_translated():
if isinstance(x, gateway.interp2app):
@@ -219,15 +220,11 @@
if isinstance(x, list):
if x == []: # special case: it is used e.g. in sys/__init__.py
return w_some_obj()
- self._wrap_not_rpython(x)
+ raise NotImplementedError
return w_some_obj()
- def _wrap_not_rpython(self, x):
- "NOT_RPYTHON"
- raise NotImplementedError
-
+ @not_rpython
def _see_interp2app(self, interp2app):
- "NOT_RPYTHON"
activation = interp2app._code.activation
def check():
scope_w = [w_some_obj()] * NonConstant(42)
@@ -236,8 +233,8 @@
check = func_with_new_name(check, 'check__' + interp2app.name)
self._seen_extras.append(check)
+ @not_rpython
def _see_getsetproperty(self, getsetproperty):
- "NOT_RPYTHON"
space = self
def checkprop():
getsetproperty.fget(getsetproperty, space, w_some_obj())
@@ -388,7 +385,10 @@
for name in (ObjSpace.ConstantTable +
ObjSpace.ExceptionTable +
BUILTIN_TYPES):
- setattr(space, 'w_' + name, w_some_obj())
+ if name != "str":
+ setattr(space, 'w_' + name, w_some_obj())
+ space.w_bytes = w_some_obj()
+ space.w_text = w_some_obj()
space.w_type = w_some_type()
#
for (name, _, arity, _) in ObjSpace.MethodTable:
diff --git a/pypy/objspace/fake/test/test_checkmodule.py
b/pypy/objspace/fake/test/test_checkmodule.py
--- a/pypy/objspace/fake/test/test_checkmodule.py
+++ b/pypy/objspace/fake/test/test_checkmodule.py
@@ -30,7 +30,7 @@
def foobar(space, x, w_y, z):
is_root(w_y)
see()
- return space.wrap(x - z)
+ return space.newint(x - z)
space = FakeObjSpace()
space.wrap(interp2app(foobar, unwrap_spec=[ObjSpace, int, W_Root, int]))
space.translates()
@@ -89,7 +89,7 @@
space = FakeObjSpace()
def f(i):
- w_x = space.wrap(i)
+ w_x = space.newint(i)
w_type = space.type(w_x)
return len(w_type.mro_w)
diff --git a/pypy/objspace/fake/test/test_objspace.py
b/pypy/objspace/fake/test/test_objspace.py
--- a/pypy/objspace/fake/test/test_objspace.py
+++ b/pypy/objspace/fake/test/test_objspace.py
@@ -45,8 +45,8 @@
def test_wrap(self):
space = self.space
- space.translates(lambda: (space.wrap(42), space.wrap(42.5),
- space.wrap("foo")))
+ space.translates(lambda: (space.newint(42), space.newfloat(42.5),
+ space.newtext("foo")))
def test_call_args(self):
space = self.space
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit