[pypy-commit] pypy default: Issue #2820

2018-05-12 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r94526:a91492fa1e35
Date: 2018-05-12 09:14 +0200
http://bitbucket.org/pypy/pypy/changeset/a91492fa1e35/

Log:Issue #2820

Implement Py_ReprEnter() and Py_ReprLeave()

diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -11,6 +11,7 @@
 from pypy.module.cpyext.pyerrors import PyErr_NoMemory, PyErr_BadInternalCall
 from pypy.objspace.std.typeobject import W_TypeObject
 from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.executioncontext import ExecutionContext
 import pypy.module.__builtin__.operation as operation
 
 
@@ -411,3 +412,27 @@
 def _PyPyGC_AddMemoryPressure(space, report):
 from rpython.rlib import rgc
 rgc.add_memory_pressure(report)
+
+
+ExecutionContext.cpyext_recursive_repr = None
+
+@cpython_api([PyObject], rffi.INT_real, error=-1)
+def Py_ReprEnter(space, w_obj):
+ec = space.getexecutioncontext()
+d = ec.cpyext_recursive_repr
+if d is None:
+d = ec.cpyext_recursive_repr = {}
+if w_obj in d:
+return 1
+d[w_obj] = None
+return 0
+
+@cpython_api([PyObject], lltype.Void)
+def Py_ReprLeave(space, w_obj):
+ec = space.getexecutioncontext()
+d = ec.cpyext_recursive_repr
+if d is not None:
+try:
+del d[w_obj]
+except KeyError:
+pass
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
@@ -403,6 +403,47 @@
 module.foo(35000)
 assert self.cur_memory_pressure() == 65536 + 8 + 7
 
+def test_repr_enter_leave(self):
+module = self.import_extension('foo', [
+("enter", "METH_O",
+"""
+return PyInt_FromLong(Py_ReprEnter(args));
+"""),
+("leave", "METH_O",
+"""
+Py_ReprLeave(args);
+Py_INCREF(Py_None);
+return Py_None;
+""")])
+obj1 = [42]
+obj2 = [42]   # another list
+
+n = module.enter(obj1)
+assert n == 0
+module.leave(obj1)
+
+n = module.enter(obj1)
+assert n == 0
+n = module.enter(obj1)
+assert n == 1
+n = module.enter(obj1)
+assert n == 1
+module.leave(obj1)
+
+n = module.enter(obj1)
+assert n == 0
+n = module.enter(obj2)
+assert n == 0
+n = module.enter(obj1)
+assert n == 1
+n = module.enter(obj2)
+assert n == 1
+module.leave(obj1)
+n = module.enter(obj2)
+assert n == 1
+module.leave(obj2)
+
+
 class AppTestPyBuffer_FillInfo(AppTestCpythonExtensionBase):
 """
 PyBuffer_FillInfo populates the fields of a Py_buffer from its arguments.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Issue #2823

2018-05-12 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r94527:d18c31e806d6
Date: 2018-05-12 09:47 +0200
http://bitbucket.org/pypy/pypy/changeset/d18c31e806d6/

Log:Issue #2823

Implement PyMarshal_ReadObjectFromString and
PyMarshal_WriteObjectToString

diff --git a/pypy/module/cpyext/__init__.py b/pypy/module/cpyext/__init__.py
--- a/pypy/module/cpyext/__init__.py
+++ b/pypy/module/cpyext/__init__.py
@@ -77,6 +77,7 @@
 import pypy.module.cpyext.pystrtod
 import pypy.module.cpyext.pytraceback
 import pypy.module.cpyext.methodobject
+import pypy.module.cpyext.marshal
 
 # now that all rffi_platform.Struct types are registered, configure them
 api.configure_types()
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -60,7 +60,7 @@
 
 configure_eci = ExternalCompilationInfo(
 include_dirs=include_dirs,
-includes=['Python.h', 'stdarg.h', 'structmember.h'],
+includes=['Python.h', 'stdarg.h', 'structmember.h', 'marshal.h'],
 compile_extra=['-DPy_BUILD_CORE'])
 
 class CConfig:
@@ -118,6 +118,7 @@
 pypy_decl = 'pypy_decl.h'
 udir.join(pypy_decl).write("/* Will be filled later */\n")
 udir.join('pypy_structmember_decl.h').write("/* Will be filled later */\n")
+udir.join('pypy_marshal_decl.h').write("/* Will be filled later */\n")
 udir.join('pypy_macros.h').write("/* Will be filled later */\n")
 
 constant_names = """
@@ -1221,14 +1222,11 @@
 global_objects.append('PyTypeObject _PyExc_%s;' % name)
 global_code = '\n'.join(global_objects)
 
-prologue = ("#include \n"
-"#include \n"
+prologue = ("#include \n" +
+"#include \n" +
+"#include \n" +
+("#include \n" if use_micronumpy else "") +
 "#include \n")
-if use_micronumpy:
-prologue = ("#include \n"
-"#include \n"
-"#include \n"
-"#include \n")
 code = (prologue +
 struct_declaration_code +
 global_code +
diff --git a/pypy/module/cpyext/include/marshal.h 
b/pypy/module/cpyext/include/marshal.h
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/include/marshal.h
@@ -0,0 +1,13 @@
+#ifndef Py_MARSHAL_H
+#define Py_MARSHAL_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define Py_MARSHAL_VERSION 2
+#include "pypy_marshal_decl.h"
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_MARSHAL_H */
diff --git a/pypy/module/cpyext/marshal.py b/pypy/module/cpyext/marshal.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/marshal.py
@@ -0,0 +1,17 @@
+from rpython.rtyper.lltypesystem import rffi, lltype
+from pypy.module.cpyext.api import cpython_api, Py_ssize_t
+from pypy.module.cpyext.pyobject import PyObject
+
+
+_HEADER = 'pypy_marshal_decl.h'
+
+@cpython_api([rffi.CCHARP, Py_ssize_t], PyObject, header=_HEADER)
+def PyMarshal_ReadObjectFromString(space, p, size):
+from pypy.module.marshal.interp_marshal import loads
+s = rffi.charpsize2str(p, size)
+return loads(space, space.newbytes(s))
+
+@cpython_api([PyObject, rffi.INT_real], PyObject, header=_HEADER)
+def PyMarshal_WriteObjectToString(space, w_x, version):
+from pypy.module.marshal.interp_marshal import dumps
+return dumps(space, w_x, space.newint(version))
diff --git a/pypy/module/cpyext/test/test_marshal.py 
b/pypy/module/cpyext/test/test_marshal.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/test/test_marshal.py
@@ -0,0 +1,33 @@
+from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
+
+
+class AppTestMarshal(AppTestCpythonExtensionBase):
+def test_PyMarshal_ReadObjectFromString(self):
+module = self.import_extension('foo', [
+("mloads", "METH_O",
+ """
+ char *input = PyString_AsString(args);
+ Py_ssize_t length = PyString_Size(args);
+ return PyMarshal_ReadObjectFromString(input, length);
+ """)],
+prologue='#include ')
+import marshal
+assert module.mloads(marshal.dumps(42.5)) == 42.5
+x = [None, True, (4, 5), b"adkj", u"\u1234"]
+assert module.mloads(marshal.dumps(x)) == x
+
+def test_PyMarshal_WriteObjectToString(self):
+module = self.import_extension('foo', [
+("mdumps", "METH_VARARGS",
+ """
+ PyObject *obj;
+ int version;
+ if (!PyArg_ParseTuple(args, "Oi", &obj, &version))
+ return NULL;
+ return PyMarshal_WriteObjectToString(obj, version);
+ """)],
+prologue='#include ')
+import marshal
+for x in [42, b"foo", u"\u2345", (4, None, False)]:
+for version in [0, 1, 2]:
+assert module.mdumps(x, version) == marshal.dumps(x, version)
___
pypy-commit mailing list
py

[pypy-commit] pypy py3.6: implement the new way the __class__ closure is filled (via type.__new__ and the

2018-05-12 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: py3.6
Changeset: r94528:92cfcd232b4f
Date: 2018-05-12 16:26 +0200
http://bitbucket.org/pypy/pypy/changeset/92cfcd232b4f/

Log:implement the new way the __class__ closure is filled (via
type.__new__ and the new __classcell__ element in the class body
dict)

diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -1826,6 +1826,8 @@
 if scope == symtable.SCOPE_CELL_CLASS:
 # Return the cell where to store __class__
 self.emit_op_arg(ops.LOAD_CLOSURE, self.cell_vars["__class__"])
+self.emit_op(ops.DUP_TOP)
+self.name_op("__classcell__", ast.Store)
 else:
 # This happens when nobody references the cell
 self.load_const(self.space.w_None)
diff --git a/pypy/interpreter/test/test_compiler.py 
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -1109,6 +1109,74 @@
 assert f() == (4, 3, 2, 1), repr(f())
 """
 
+def test_classcell(self):
+"""
+test_class = None
+class Meta(type):
+def __new__(cls, name, bases, namespace):
+nonlocal test_class
+self = super().__new__(cls, name, bases, namespace)
+test_class = self.f()
+return self
+class A(metaclass=Meta):
+@staticmethod
+def f():
+return __class__
+assert test_class is A
+"""
+
+def test_classcell_missing(self):
+"""
+# Some metaclasses may not pass the original namespace to type.__new__
+# We test that case here by forcibly deleting __classcell__
+class Meta(type):
+def __new__(cls, name, bases, namespace):
+namespace.pop('__classcell__', None)
+return super().__new__(cls, name, bases, namespace)
+
+class WithClassRef(metaclass=Meta):
+def f(self):
+return __class__
+
+# Check __class__ still gets set despite the warning
+assert WithClassRef().f() is WithClassRef
+"""
+
+def test_classcell_overwrite(self):
+"""
+# Overwriting __classcell__ with nonsense is explicitly prohibited
+class Meta(type):
+def __new__(cls, name, bases, namespace, cell):
+namespace['__classcell__'] = cell
+return super().__new__(cls, name, bases, namespace)
+
+raises(TypeError, '''if 1:
+class A(metaclass=Meta, cell=object()):
+pass
+''')
+"""
+
+def test_classcell_wrong_cell(self):
+"""
+# Pointing the cell reference at the wrong class is prohibited
+class Meta(type):
+def __new__(cls, name, bases, namespace):
+cls = super().__new__(cls, name, bases, namespace)
+B = type("B", (), namespace)
+return cls
+
+# works, no __class__
+class A(metaclass=Meta):
+pass
+
+raises(TypeError, '''if 1:
+class A(metaclass=Meta):
+def f(self):
+return __class__
+''')
+
+"""
+
 
 class AppTestOptimizer(object):
 def setup_class(cls):
@@ -1438,3 +1506,5 @@
 assert eval(code) == u'\xc2\u20ac'
 code = b'u"""\\\n# -*- coding: ascii -*-\n\xc2\xa4"""\n'
 assert eval(code) == u'# -*- coding: ascii -*-\n\xa4'
+
+
diff --git a/pypy/module/__builtin__/compiling.py 
b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -93,6 +93,8 @@
 frame.exec_(w_prog, w_globals, w_locals)
 
 def build_class(space, w_func, w_name, __args__):
+from pypy.objspace.std.typeobject import _calculate_metaclass, W_TypeObject
+from pypy.interpreter.nestedscope import Cell
 if not isinstance(w_func, Function):
 raise oefmt(space.w_TypeError, "__build_class__: func must be a 
function")
 bases_w, kwds_w = __args__.unpack()
@@ -109,7 +111,6 @@
 if isclass:
 # w_meta is really a class, so check for a more derived
 # metaclass, or possible metaclass conflicts
-from pypy.objspace.std.typeobject import _calculate_metaclass
 w_meta = _calculate_metaclass(space, w_meta, bases_w)
 
 try:
@@ -135,6 +136,22 @@
  keywords=keywords,
  keywords_w=kwds_w.values())
 w_class = space.call_args(w_meta, args)
-if isinstance(w_cell, Cell):
-w_cell.set(w_class)
+if isinstance(w_cell, Cell) and isinstance(w_class, W_TypeObject):
+if w_cell.empty():
+# will become an error in Python 3.7
+space.warn(space.newtext(
+  

[pypy-commit] pypy py3.6: fix translation?

2018-05-12 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: py3.6
Changeset: r94529:54d322f20c77
Date: 2018-05-12 16:30 +0200
http://bitbucket.org/pypy/pypy/changeset/54d322f20c77/

Log:fix translation?

diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -807,7 +807,7 @@
   dict_w, is_heaptype=True)
 
 # store the w_type in __classcell__
-w_classcell = dict_w.get("__classcell__")
+w_classcell = dict_w.get("__classcell__", None)
 if w_classcell:
 _store_type_in_classcell(space, w_type, w_classcell, dict_w)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.6: fix another problem

2018-05-12 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: py3.6
Changeset: r94530:b557b77bd013
Date: 2018-05-12 17:29 +0200
http://bitbucket.org/pypy/pypy/changeset/b557b77bd013/

Log:fix another problem

diff --git a/pypy/module/__builtin__/compiling.py 
b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -152,6 +152,6 @@
 if not space.is_w(w_class, w_class_from_cell):
 raise oefmt(
 space.w_TypeError,
-"__class__ set to %s defining %s as %s",
+"__class__ set to %S defining %S as %S",
 w_class_from_cell, w_name, w_class)
 return w_class
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: rpython support for dict.get(key) (ie without giving a default)

2018-05-12 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: 
Changeset: r94531:85d7ccafed44
Date: 2018-05-12 16:47 +0200
http://bitbucket.org/pypy/pypy/changeset/85d7ccafed44/

Log:rpython support for dict.get(key) (ie without giving a default)

diff --git a/rpython/annotator/test/test_annrpython.py 
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -688,6 +688,16 @@
 assert isinstance(dictvalue(s), annmodel.SomeInteger)
 assert not dictvalue(s).nonneg
 
+def test_dict_get(self):
+def f1(i, j):
+d = {i: ''}
+return d.get(j)
+a = self.RPythonAnnotator()
+s = a.build_types(f1, [int, int])
+assert isinstance(s, annmodel.SomeString)
+assert s.can_be_None
+
+
 def test_exception_deduction(self):
 a = self.RPythonAnnotator()
 s = a.build_types(snippet.exception_deduction, [])
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -496,7 +496,7 @@
 return SomeTuple((s_key, s_Int))
 raise ValueError(variant)
 
-def method_get(self, key, dfl):
+def method_get(self, key, dfl=s_None):
 position = getbookkeeper().position_key
 self.dictdef.generalize_key(key)
 self.dictdef.generalize_value(dfl)
diff --git a/rpython/rtyper/lltypesystem/rordereddict.py 
b/rpython/rtyper/lltypesystem/rordereddict.py
--- a/rpython/rtyper/lltypesystem/rordereddict.py
+++ b/rpython/rtyper/lltypesystem/rordereddict.py
@@ -283,8 +283,12 @@
 return DictIteratorRepr(self, *variant)
 
 def rtype_method_get(self, hop):
-v_dict, v_key, v_default = hop.inputargs(self, self.key_repr,
- self.value_repr)
+if hop.nb_args == 3:
+v_dict, v_key, v_default = hop.inputargs(self, self.key_repr,
+ self.value_repr)
+else:
+v_dict, v_key = hop.inputargs(self, self.key_repr)
+v_default = hop.inputconst(self.value_repr, None)
 hop.exception_cannot_occur()
 v_res = hop.gendirectcall(ll_dict_get, v_dict, v_key, v_default)
 return self.recast_value(hop.llops, v_res)
diff --git a/rpython/rtyper/test/test_rdict.py 
b/rpython/rtyper/test/test_rdict.py
--- a/rpython/rtyper/test/test_rdict.py
+++ b/rpython/rtyper/test/test_rdict.py
@@ -208,6 +208,16 @@
 res = self.interpret(func, ())
 assert res == 421
 
+def test_dict_get_no_second_arg(self):
+def func():
+dic = self.newdict()
+x1 = dic.get('hi', 'a')
+x2 = dic.get('blah')
+return (x1 == 'a') * 10 + (x2 is None)
+return x1 * 10 + x2
+res = self.interpret(func, ())
+assert res == 11
+
 def test_dict_get_empty(self):
 def func():
 # this time without writing to the dict
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: backport a couple cosmetic changes from branch unicode-utf8

2018-05-12 Thread rlamy
Author: Ronan Lamy 
Branch: 
Changeset: r94532:0a8401a58e9f
Date: 2018-05-12 18:04 +0100
http://bitbucket.org/pypy/pypy/changeset/0a8401a58e9f/

Log:backport a couple cosmetic changes from branch unicode-utf8

diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -499,6 +499,7 @@
 def visit_truncatedint_w(self, typ):
 self.unwrap.append("space.truncatedint_w(%s)" % (self.nextarg(),))
 
+@staticmethod
 def make_fastfunc(unwrap_spec, func):
 unwrap_info = UnwrapSpec_FastFunc_Unwrap()
 unwrap_info.apply_over(unwrap_spec)
@@ -529,7 +530,6 @@
 exec compile2(source) in unwrap_info.miniglobals, d
 fastfunc = d['fastfunc_%s_%d' % (func.__name__.replace('-', '_'), 
narg)]
 return narg, fastfunc
-make_fastfunc = staticmethod(make_fastfunc)
 
 
 def int_unwrapping_space_method(typ):
diff --git a/pypy/module/__builtin__/operation.py 
b/pypy/module/__builtin__/operation.py
--- a/pypy/module/__builtin__/operation.py
+++ b/pypy/module/__builtin__/operation.py
@@ -27,11 +27,9 @@
 @unwrap_spec(code=int)
 def unichr(space, code):
 "Return a Unicode string of one character with the given ordinal."
-# XXX range checking!
-try:
-c = UNICHR(code)
-except ValueError:
+if code < 0 or code > 0x10:
 raise oefmt(space.w_ValueError, "unichr() arg out of range")
+c = UNICHR(code)
 return space.newunicode(c)
 
 def len(space, w_obj):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.6: fix

2018-05-12 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: py3.6
Changeset: r94533:6846408f5ccc
Date: 2018-05-12 18:36 +0200
http://bitbucket.org/pypy/pypy/changeset/6846408f5ccc/

Log:fix

diff --git a/lib-python/3/test/test_inspect.py 
b/lib-python/3/test/test_inspect.py
--- a/lib-python/3/test/test_inspect.py
+++ b/lib-python/3/test/test_inspect.py
@@ -768,7 +768,7 @@
 @unittest.skipIf(MISSING_C_DOCSTRINGS,
  "Signature information for builtins requires docstrings")
 def test_getfullargspec_builtin_methods(self):
-if check_impl_detail():
+if support.check_impl_detail():
 self.assertFullArgSpecEquals(_pickle.Pickler.dump,
 args_e=['self', 'obj'], 
formatted='(self, obj)')
 
@@ -2012,7 +2012,7 @@
 
 # normal method
 # (PyMethodDescr_Type, "method_descriptor")
-if check_impl_detail():
+if support.check_impl_detail():
 test_unbound_method(_pickle.Pickler.dump)
 d = _pickle.Pickler(io.StringIO())
 test_callable(d.dump)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.6: fill the classcell even earlier

2018-05-12 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: py3.6
Changeset: r94534:4ea0853cd59f
Date: 2018-05-12 19:09 +0200
http://bitbucket.org/pypy/pypy/changeset/4ea0853cd59f/

Log:fill the classcell even earlier

diff --git a/pypy/interpreter/test/test_compiler.py 
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -1109,6 +1109,8 @@
 assert f() == (4, 3, 2, 1), repr(f())
 """
 
+# the following couple of tests are from test_super.py in the stdlib
+
 def test_classcell(self):
 """
 test_class = None
@@ -1177,6 +1179,24 @@
 
 """
 
+def test_class_mro(self):
+"""
+test_class = None
+
+class Meta(type):
+def mro(self):
+# self.f() doesn't work yet...
+self.__dict__["f"]()
+return super().mro()
+
+class A(metaclass=Meta):
+def f():
+nonlocal test_class
+test_class = __class__
+
+assert test_class is A
+"""
+
 
 class AppTestOptimizer(object):
 def setup_class(cls):
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -803,14 +803,16 @@
 key = space.text_w(w_key)
 dict_w[key] = space.getitem(w_dict, w_key)
 w_type = space.allocate_instance(W_TypeObject, w_typetype)
-W_TypeObject.__init__(w_type, space, name, bases_w or [space.w_object],
-  dict_w, is_heaptype=True)
 
 # store the w_type in __classcell__
 w_classcell = dict_w.get("__classcell__", None)
 if w_classcell:
 _store_type_in_classcell(space, w_type, w_classcell, dict_w)
 
+W_TypeObject.__init__(w_type, space, name, bases_w or [space.w_object],
+  dict_w, is_heaptype=True)
+
+
 w_type.ready()
 
 _set_names(space, w_type)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.6: can't use the one-argument form of type.__new__ for subclasses of type

2018-05-12 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: py3.6
Changeset: r94535:7c4bb9c6272f
Date: 2018-05-12 19:19 +0200
http://bitbucket.org/pypy/pypy/changeset/7c4bb9c6272f/

Log:can't use the one-argument form of type.__new__ for subclasses of
type

diff --git a/pypy/objspace/std/test/test_typeobject.py 
b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -1607,3 +1607,9 @@
 
 assert Y.kwargs == dict(a=1, b=2)
 """)
+
+def test_onearg_type_only_for_type(self):
+class Meta(type):
+pass
+
+raises(TypeError, Meta, 5)
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -759,10 +759,14 @@
 
 w_typetype = _precheck_for_new(space, w_typetype)
 
-# special case for type(x)
-if (space.is_w(space.type(w_typetype), space.w_type) and
-len(__args__.arguments_w) == 1):
-return space.type(w_name)
+# special case for type(x), but not Metaclass(x)
+if len(__args__.arguments_w) == 1:
+if space.is_w(w_typetype, space.w_type):
+return space.type(w_name)
+else:
+raise oefmt(space.w_TypeError,
+"%N.__new__() takes 3 arguments (1 given)",
+w_typetype)
 w_bases = __args__.arguments_w[1]
 w_dict = __args__.arguments_w[2]
 return _create_new_type(space, w_typetype, w_name, w_bases, w_dict, 
__args__)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.6: missing space in error message

2018-05-12 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: py3.6
Changeset: r94536:2341c48345f8
Date: 2018-05-12 19:23 +0200
http://bitbucket.org/pypy/pypy/changeset/2341c48345f8/

Log:missing space in error message

diff --git a/pypy/module/__builtin__/compiling.py 
b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -140,7 +140,7 @@
 if w_cell.empty():
 # will become an error in Python 3.7
 space.warn(space.newtext(
-"__class__ not set defining %s as %s ."
+"__class__ not set defining %s as %s . "
 "Was __classcell__ propagated to type.__new__?" % (
 space.text_w(w_name),
 space.text_w(space.str(w_class))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.6: bump magic because of classcell changes

2018-05-12 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: py3.6
Changeset: r94537:ba88f1c25694
Date: 2018-05-12 19:36 +0200
http://bitbucket.org/pypy/pypy/changeset/ba88f1c25694/

Log:bump magic because of classcell changes

diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -39,7 +39,7 @@
 # time you make pyc files incompatible.  This value ends up in the frozen
 # importlib, via MAGIC_NUMBER in module/_frozen_importlib/__init__.
 
-pypy_incremental_magic = 112 # bump it by 16
+pypy_incremental_magic = 128 # bump it by 16
 assert pypy_incremental_magic % 16 == 0
 assert pypy_incremental_magic < 3000 # the magic number of Python 3. There are
  # no known magic numbers below this value
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: merge default into py3.5

2018-05-12 Thread mattip
Author: Matti Picus 
Branch: py3.5
Changeset: r94538:5f017005bd26
Date: 2018-05-12 21:01 +0300
http://bitbucket.org/pypy/pypy/changeset/5f017005bd26/

Log:merge default into py3.5

diff --git a/pypy/doc/config/objspace.usemodules._cppyy.txt 
b/pypy/doc/config/objspace.usemodules._cppyy.txt
new file mode 100644
--- /dev/null
+++ b/pypy/doc/config/objspace.usemodules._cppyy.txt
@@ -0,0 +1,1 @@
+The internal backend for cppyy
diff --git a/pypy/doc/config/objspace.usemodules._rawffi.txt 
b/pypy/doc/config/objspace.usemodules._rawffi.txt
--- a/pypy/doc/config/objspace.usemodules._rawffi.txt
+++ b/pypy/doc/config/objspace.usemodules._rawffi.txt
@@ -1,3 +1,3 @@
-An experimental module providing very low-level interface to
+A module providing very low-level interface to
 C-level libraries, for use when implementing ctypes, not
-intended for a direct use at all.
\ No newline at end of file
+intended for a direct use at all.
diff --git a/pypy/doc/config/objspace.usemodules.cpyext.txt 
b/pypy/doc/config/objspace.usemodules.cpyext.txt
--- a/pypy/doc/config/objspace.usemodules.cpyext.txt
+++ b/pypy/doc/config/objspace.usemodules.cpyext.txt
@@ -1,1 +1,1 @@
-Use (experimental) cpyext module, that tries to load and run CPython extension 
modules
+Use cpyext module to load and run CPython extension modules
diff --git a/pypy/doc/contributing.rst b/pypy/doc/contributing.rst
--- a/pypy/doc/contributing.rst
+++ b/pypy/doc/contributing.rst
@@ -293,7 +293,8 @@
 
 You will need the `build requirements`_ to run tests successfully, since many 
of
 them compile little pieces of PyPy and then run the tests inside that minimal
-interpreter
+interpreter. The `cpyext` tests also require `pycparser`, and many tests build
+cases with `hypothesis`.
 
 Now on to running some tests.  PyPy has many different test directories
 and you can use shell completion to point at directories or files::
@@ -325,6 +326,24 @@
 .. _py.test usage and invocations: http://pytest.org/latest/usage.html#usage
 .. _`build requirements`: build.html#install-build-time-dependencies
 
+Testing After Translation
+^
+
+While the usual invocation of `pytest` translates a piece of RPython code and
+runs it, we have a test extension to run tests without translation, directly
+on the host python. This is very convenient for modules such as `cpyext`, to
+compare and contrast test results between CPython and PyPy. Untranslated tests
+are invoked by using the `-A` or `--runappdirect` option to `pytest`::
+
+python2 pytest.py -A pypy/module/cpyext/test
+
+where `python2` can be either `python2` or `pypy2`. On the `py3` branch, the
+collection phase must be run with `python2` so untranslated tests are run
+with::
+
+cpython2 pytest.py -A pypy/module/cpyext/test --python=path/to/pypy3
+
+
 Tooling & Utilities
 ^^^
 
diff --git a/pypy/doc/index.rst b/pypy/doc/index.rst
--- a/pypy/doc/index.rst
+++ b/pypy/doc/index.rst
@@ -41,7 +41,7 @@
 --
 
 .. toctree::
-  :maxdepth: 1
+  :maxdepth: 2
 
   cpython_differences
   extending
@@ -56,7 +56,7 @@
 ---
 
 .. toctree::
-  :maxdepth: 1
+  :maxdepth: 2
 
   contributing
   architecture
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -529,7 +529,8 @@
 
 def visit_kwonly(self, typ):
 raise FastFuncNotSupported
-
+
+@staticmethod
 def make_fastfunc(unwrap_spec, func):
 unwrap_info = UnwrapSpec_FastFunc_Unwrap()
 unwrap_info.apply_over(unwrap_spec)
@@ -560,7 +561,6 @@
 exec compile2(source) in unwrap_info.miniglobals, d
 fastfunc = d['fastfunc_%s_%d' % (func.__name__.replace('-', '_'), 
narg)]
 return narg, fastfunc
-make_fastfunc = staticmethod(make_fastfunc)
 
 
 def int_unwrapping_space_method(typ):
diff --git a/pypy/module/__builtin__/operation.py 
b/pypy/module/__builtin__/operation.py
--- a/pypy/module/__builtin__/operation.py
+++ b/pypy/module/__builtin__/operation.py
@@ -27,10 +27,9 @@
 @unwrap_spec(code=int)
 def chr(space, code):
 "Return a Unicode string of one character with the given ordinal."
-try:
-c = UNICHR(code)
-except ValueError:
+if code < 0 or code > 0x10:
 raise oefmt(space.w_ValueError, "chr() arg out of range")
+c = UNICHR(code)
 return space.newunicode(c)
 
 def len(space, w_obj):
diff --git a/pypy/module/cpyext/__init__.py b/pypy/module/cpyext/__init__.py
--- a/pypy/module/cpyext/__init__.py
+++ b/pypy/module/cpyext/__init__.py
@@ -76,6 +76,7 @@
 import pypy.module.cpyext.pytraceback
 import pypy.module.cpyext.methodobject
 import pypy.module.cpyext.dictproxyobject
+import pypy.module.cpyext.marshal
 import pypy.module.cpyext.genobject
 import pypy.module.cpyext.namespaceobject
 
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -61,7 +61,7 @@
 
 config