[pypy-commit] pypy py3.5: DeprecationWarning when opening in 'U' mode

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89505:623575878821
Date: 2017-01-12 14:53 +0100
http://bitbucket.org/pypy/pypy/changeset/623575878821/

Log:DeprecationWarning when opening in 'U' mode

diff --git a/pypy/module/_io/interp_io.py b/pypy/module/_io/interp_io.py
--- a/pypy/module/_io/interp_io.py
+++ b/pypy/module/_io/interp_io.py
@@ -67,8 +67,13 @@
 if updating:
 rawmode += "+"
 
-if universal and (writing or appending):
-raise oefmt(space.w_ValueError, "can't use U and writing mode at once")
+if universal:
+if writing or appending:
+raise oefmt(space.w_ValueError,
+"can't use U and writing mode at once")
+space.warn(space.wrap("'U' mode is deprecated ('r' has the same "
+  "effect in Python 3.x)"),
+   space.w_DeprecationWarning)
 if text and binary:
 raise oefmt(space.w_ValueError,
 "can't have text and binary mode at once")
diff --git a/pypy/module/_io/test/test_io.py b/pypy/module/_io/test/test_io.py
--- a/pypy/module/_io/test/test_io.py
+++ b/pypy/module/_io/test/test_io.py
@@ -225,17 +225,21 @@
 
 def test_attributes(self):
 import _io
+import warnings
 
 with _io.open(self.tmpfile, "wb", buffering=0) as f:
 assert f.mode == "wb"
 
-with _io.open(self.tmpfile, "U") as f:
-assert f.name == self.tmpfile
-assert f.buffer.name == self.tmpfile
-assert f.buffer.raw.name == self.tmpfile
-assert f.mode == "U"
-assert f.buffer.mode == "rb"
-assert f.buffer.raw.mode == "rb"
+with warnings.catch_warnings(record=True) as l:
+warnings.simplefilter("always")
+with _io.open(self.tmpfile, "U") as f:
+assert f.name == self.tmpfile
+assert f.buffer.name == self.tmpfile
+assert f.buffer.raw.name == self.tmpfile
+assert f.mode == "U"
+assert f.buffer.mode == "rb"
+assert f.buffer.raw.mode == "rb"
+assert isinstance(l[0].message, DeprecationWarning)
 
 with _io.open(self.tmpfile, "w+") as f:
 assert f.mode == "w+"
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Detect null bytes in unicode or byte strings for the OS functions

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89506:6e3116ffd73c
Date: 2017-01-12 15:17 +0100
http://bitbucket.org/pypy/pypy/changeset/6e3116ffd73c/

Log:Detect null bytes in unicode or byte strings for the OS functions

diff --git a/pypy/interpreter/test/test_fsencode.py 
b/pypy/interpreter/test/test_fsencode.py
--- a/pypy/interpreter/test/test_fsencode.py
+++ b/pypy/interpreter/test/test_fsencode.py
@@ -78,3 +78,8 @@
 
 assert space.fsencode_w(w_enc) == space.bytes_w(w_enc)
 assert space.eq_w(space.wrap_fsdecoded(space.bytes_w(w_enc)), 
w_st2)
+
+def test_null_byte(self):
+space = self.space
+w_u = space.newunicode(u'abc\x00def')
+space.raises_w(space.w_ValueError, space.fsencode, w_u)
diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -1,5 +1,5 @@
 import sys
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib import runicode
 from pypy.module._codecs import interp_codecs
@@ -104,6 +104,8 @@
 from pypy.module._codecs.locale import (
 unicode_encode_locale_surrogateescape)
 uni = space.unicode_w(w_uni)
+if u'\x00' in uni:
+raise oefmt(space.w_ValueError, "embedded null character")
 bytes = unicode_encode_locale_surrogateescape(
 uni, errorhandler=encode_error_handler(space))
 else:
diff --git a/pypy/module/posix/interp_posix.py 
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -148,11 +148,15 @@
 try:
 path_b = space.fsencode_w(w_value)
 return Path(-1, path_b, None, w_value)
-except OperationError:
+except OperationError as e:
+if not e.match(space, space.w_TypeError):
+raise
 if allow_fd:
 fd = unwrap_fd(space, w_value, "string, bytes or integer")
 return Path(fd, None, None, w_value)
-raise oefmt(space.w_TypeError, "illegal type for path parameter")
+raise oefmt(space.w_TypeError,
+"illegal type for path parameter (expected "
+"string or bytes, got %T)", w_value)
 
 class _PathOrFd(Unwrapper):
 def unwrap(self, space, w_value):
diff --git a/pypy/module/posix/test/test_posix2.py 
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -202,6 +202,8 @@
 excinfo = raises(TypeError, self.posix.stat, 2.)
 assert "should be string, bytes or integer, not float" in 
str(excinfo.value)
 raises(ValueError, self.posix.stat, -1)
+raises(ValueError, self.posix.stat, b"abc\x00def")
+raises(ValueError, self.posix.stat, u"abc\x00def")
 
 if hasattr(__import__(os.name), "statvfs"):
 def test_statvfs(self):
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Skip a test that cannot pass on PyPy

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89511:b84e248dea00
Date: 2017-01-12 15:26 +0100
http://bitbucket.org/pypy/pypy/changeset/b84e248dea00/

Log:Skip a test that cannot pass on PyPy

diff --git a/lib-python/3/test/test_module.py b/lib-python/3/test/test_module.py
--- a/lib-python/3/test/test_module.py
+++ b/lib-python/3/test/test_module.py
@@ -2,7 +2,7 @@
 import unittest
 import weakref
 from test.support import gc_collect
-from test.support import check_impl_detail
+from test.support import check_impl_detail, impl_detail
 from test.support.script_helper import assert_python_ok
 
 import sys
@@ -217,6 +217,7 @@
 self.assertEqual(r[-len(ends_with):], ends_with,
  '{!r} does not end with {!r}'.format(r, ends_with))
 
+@impl_detail(pypy=False)   # __del__ is typically not called at shutdown
 def test_module_finalization_at_shutdown(self):
 # Module globals and builtins should still be available during shutdown
 rc, out, err = assert_python_ok("-c", "from test import final_a")
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: fix test

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89512:833aad96c408
Date: 2017-01-12 15:40 +0100
http://bitbucket.org/pypy/pypy/changeset/833aad96c408/

Log:fix test

diff --git a/pypy/interpreter/test/test_fsencode.py 
b/pypy/interpreter/test/test_fsencode.py
--- a/pypy/interpreter/test/test_fsencode.py
+++ b/pypy/interpreter/test/test_fsencode.py
@@ -82,4 +82,8 @@
 def test_null_byte(self):
 space = self.space
 w_u = space.newunicode(u'abc\x00def')
-space.raises_w(space.w_ValueError, space.fsencode, w_u)
+# this can behave in two different ways depending on how
+# much initialized the space is: space.fsencode() can raise
+# ValueError directly, or return a wrapped bytes with the 0
+# embedded---and then space.fsencode_w() should raise ValueError.
+space.raises_w(space.w_ValueError, space.fsencode_w, w_u)
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy rffi-parser-2: Add missing declarations needed by PyTypeObject

2017-01-12 Thread rlamy
Author: Ronan Lamy 
Branch: rffi-parser-2
Changeset: r89509:7b3731d591e4
Date: 2016-12-18 03:40 +
http://bitbucket.org/pypy/pypy/changeset/7b3731d591e4/

Log:Add missing declarations needed by PyTypeObject

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
@@ -840,11 +840,47 @@
releasebufferproc bf_releasebuffer;
 } PyBufferProcs;
 
+/* from descrobject.h */
+typedef PyObject *(*getter)(PyObject *, void *);
+typedef int (*setter)(PyObject *, PyObject *, void *);
+
+typedef struct PyGetSetDef {
+   char *name;
+   getter get;
+   setter set;
+   char *doc;
+   void *closure;
+} PyGetSetDef;
+
+/* from methodobject.h */
+typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
+typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
+ PyObject *);
+typedef PyObject *(*PyNoArgsFunction)(PyObject *);
+
+struct PyMethodDef {
+const char  *ml_name;   /* The name of the built-in function/method */
+PyCFunction  ml_meth;   /* The C function that implements it */
+int  ml_flags;  /* Combination of METH_xxx flags, which mostly
+   describe the args expected by the C func */
+const char  *ml_doc;/* The __doc__ attribute, or NULL */
+};
+typedef struct PyMethodDef PyMethodDef;
+
+/* from structmember.h */
+typedef struct PyMemberDef {
+/* Current version, use this */
+char *name;
+int type;
+Py_ssize_t offset;
+int flags;
+char *doc;
+} PyMemberDef;
 
 
 typedef struct _typeobject {
PyObject_VAR_HEAD
-   const char *tp_name; /* For printing, in format "." */
+   /* const */ char *tp_name; /* For printing, in format "." 
*/
Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
 
/* Methods to implement standard operations */
@@ -876,7 +912,7 @@
/* Flags to define presence of optional/expanded features */
long tp_flags;
 
-   const char *tp_doc; /* Documentation string */
+   /*const*/ char *tp_doc; /* Documentation string */
 
/* Assigned meaning in release 2.0 */
/* call function for all accessible objects */
@@ -923,7 +959,7 @@
 
 } PyTypeObject;
 
-""")
+""", configure_now=True)
 
 Py_ssize_t = object_h.gettype('Py_ssize_t')
 Py_ssize_tP = object_h.gettype('Py_ssize_t *')
diff --git a/pypy/module/cpyext/methodobject.py 
b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -11,23 +11,15 @@
 CONST_STRING, METH_CLASS, METH_COEXIST, METH_KEYWORDS, METH_NOARGS, METH_O,
 METH_STATIC, METH_VARARGS, PyObject, PyObjectFields, bootstrap_function,
 build_type_checkers, cpython_api, cpython_struct, generic_cpy_call,
-PyTypeObjectPtr, slot_function)
+PyTypeObjectPtr, slot_function, object_h)
 from pypy.module.cpyext.pyobject import (
 Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
 
 PyCFunction_typedef = rffi.COpaquePtr(typedef='PyCFunction')
-PyCFunction = lltype.Ptr(lltype.FuncType([PyObject, PyObject], PyObject))
-PyCFunctionKwArgs = lltype.Ptr(lltype.FuncType([PyObject, PyObject, PyObject],
-   PyObject))
 
-PyMethodDef = cpython_struct(
-'PyMethodDef',
-[('ml_name', rffi.CONST_CCHARP),
- ('ml_meth', PyCFunction_typedef),
- ('ml_flags', rffi.INT_real),
- ('ml_doc', rffi.CONST_CCHARP),
- ])
-
+PyMethodDef = object_h.gettype('PyMethodDef')
+PyCFunction = object_h.gettype('PyCFunction')
+PyCFunctionKwArgs = object_h.gettype('PyCFunctionWithKeywords')
 PyCFunctionObjectStruct = cpython_struct(
 'PyCFunctionObject',
 PyObjectFields + (
diff --git a/pypy/module/cpyext/modsupport.py b/pypy/module/cpyext/modsupport.py
--- a/pypy/module/cpyext/modsupport.py
+++ b/pypy/module/cpyext/modsupport.py
@@ -50,7 +50,7 @@
 cache.  CPython includes some extra checking here to make sure the module
 being initialized lines up with what's expected, but we don't.
 """
-from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr
+from pypy.module.cpyext.api import PyTypeObjectPtr
 modname = rffi.charp2str(name)
 state = space.fromcache(State)
 f_name, f_path = state.package_context
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -7,9 +7,9 @@
 from rpython.rlib import rgc # Force registration of gc.collect
 from pypy.module.cpyext.api import (
 slot_function, generic_cpy_call, PyObject, Py_ssize_t, 
Py_TPFLAGS_CHECKTYPES,
-pypy_decl, Py_buffer, Py_bufferP)
+pypy_decl, Py_buffer, Py_bufferP, PyTypeObjectPtr)
 from pypy.module.cpyext.typeobjectdefs import (
-unaryfunc, ternaryfunc, PyTypeObjectPtr, binaryfunc,
+unaryfunc, ternaryfunc, binaryfunc,
 getattrfunc, getattrofunc, setattrofunc, 

[pypy-commit] pypy rffi-parser-2: Complete the declaration of PyTypeObject

2017-01-12 Thread rlamy
Author: Ronan Lamy 
Branch: rffi-parser-2
Changeset: r89508:5897cf94242d
Date: 2016-12-18 02:07 +
http://bitbucket.org/pypy/pypy/changeset/5897cf94242d/

Log:Complete the declaration of PyTypeObject

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
@@ -671,7 +671,7 @@
PyObject_VAR_HEAD
 } PyVarObject;
 
-typedef struct _typeobject PyTypeObject;
+struct _typeobject;
 
 typedef void (*freefunc)(void *);
 typedef void (*destructor)(PyObject *);
@@ -751,6 +751,178 @@
 typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
 /* end Py3k buffer interface */
 
+typedef int (*objobjproc)(PyObject *, PyObject *);
+typedef int (*visitproc)(PyObject *, void *);
+typedef int (*traverseproc)(PyObject *, visitproc, void *);
+
+typedef struct {
+   /* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all
+  arguments are guaranteed to be of the object's type (modulo
+  coercion hacks -- i.e. if the type's coercion function
+  returns other types, then these are allowed as well).  Numbers that
+  have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both*
+  arguments for proper type and implement the necessary conversions
+  in the slot functions themselves. */
+
+   binaryfunc nb_add;
+   binaryfunc nb_subtract;
+   binaryfunc nb_multiply;
+   binaryfunc nb_divide;
+   binaryfunc nb_remainder;
+   binaryfunc nb_divmod;
+   ternaryfunc nb_power;
+   unaryfunc nb_negative;
+   unaryfunc nb_positive;
+   unaryfunc nb_absolute;
+   inquiry nb_nonzero;
+   unaryfunc nb_invert;
+   binaryfunc nb_lshift;
+   binaryfunc nb_rshift;
+   binaryfunc nb_and;
+   binaryfunc nb_xor;
+   binaryfunc nb_or;
+   coercion nb_coerce;
+   unaryfunc nb_int;
+   unaryfunc nb_long;
+   unaryfunc nb_float;
+   unaryfunc nb_oct;
+   unaryfunc nb_hex;
+   /* Added in release 2.0 */
+   binaryfunc nb_inplace_add;
+   binaryfunc nb_inplace_subtract;
+   binaryfunc nb_inplace_multiply;
+   binaryfunc nb_inplace_divide;
+   binaryfunc nb_inplace_remainder;
+   ternaryfunc nb_inplace_power;
+   binaryfunc nb_inplace_lshift;
+   binaryfunc nb_inplace_rshift;
+   binaryfunc nb_inplace_and;
+   binaryfunc nb_inplace_xor;
+   binaryfunc nb_inplace_or;
+
+   /* Added in release 2.2 */
+   /* The following require the Py_TPFLAGS_HAVE_CLASS flag */
+   binaryfunc nb_floor_divide;
+   binaryfunc nb_true_divide;
+   binaryfunc nb_inplace_floor_divide;
+   binaryfunc nb_inplace_true_divide;
+
+   /* Added in release 2.5 */
+   unaryfunc nb_index;
+} PyNumberMethods;
+
+typedef struct {
+   lenfunc sq_length;
+   binaryfunc sq_concat;
+   ssizeargfunc sq_repeat;
+   ssizeargfunc sq_item;
+   ssizessizeargfunc sq_slice;
+   ssizeobjargproc sq_ass_item;
+   ssizessizeobjargproc sq_ass_slice;
+   objobjproc sq_contains;
+   /* Added in release 2.0 */
+   binaryfunc sq_inplace_concat;
+   ssizeargfunc sq_inplace_repeat;
+} PySequenceMethods;
+
+typedef struct {
+   lenfunc mp_length;
+   binaryfunc mp_subscript;
+   objobjargproc mp_ass_subscript;
+} PyMappingMethods;
+
+typedef struct {
+   readbufferproc bf_getreadbuffer;
+   writebufferproc bf_getwritebuffer;
+   segcountproc bf_getsegcount;
+   charbufferproc bf_getcharbuffer;
+   getbufferproc bf_getbuffer;
+   releasebufferproc bf_releasebuffer;
+} PyBufferProcs;
+
+
+
+typedef struct _typeobject {
+   PyObject_VAR_HEAD
+   const char *tp_name; /* For printing, in format "." */
+   Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
+
+   /* Methods to implement standard operations */
+
+   destructor tp_dealloc;
+   printfunc tp_print;
+   getattrfunc tp_getattr;
+   setattrfunc tp_setattr;
+   cmpfunc tp_compare;
+   reprfunc tp_repr;
+
+   /* Method suites for standard classes */
+
+   PyNumberMethods *tp_as_number;
+   PySequenceMethods *tp_as_sequence;
+   PyMappingMethods *tp_as_mapping;
+
+   /* More standard operations (here for binary compatibility) */
+
+   hashfunc tp_hash;
+   ternaryfunc tp_call;
+   reprfunc tp_str;
+   getattrofunc tp_getattro;
+   setattrofunc tp_setattro;
+
+   /* Functions to access object as input/output buffer */
+   PyBufferProcs *tp_as_buffer;
+
+   /* Flags to define presence of optional/expanded features */
+   long tp_flags;
+
+   const char *tp_doc; /* Documentation string */
+
+   /* Assigned meaning in release 2.0 */
+   /* call function for all accessible objects */
+   traverseproc tp_traverse;
+
+   /* delete references to contained objects */
+   inquiry tp_clear;
+
+   /* Assigned meaning in release 2.1 */
+   /* rich com

[pypy-commit] pypy rffi-parser-2: hg merge default

2017-01-12 Thread rlamy
Author: Ronan Lamy 
Branch: rffi-parser-2
Changeset: r89510:421ea2f68c13
Date: 2017-01-12 14:34 +
http://bitbucket.org/pypy/pypy/changeset/421ea2f68c13/

Log:hg merge default

diff too long, truncating to 2000 out of 2826 lines

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -97,3 +97,7 @@
 
 Fix a test failure introduced by strbuf-as-buffer
 
+.. branch: cpyext-FromBuffer
+
+Do not recreate the object in PyMemoryView_FromBuffer, rather pass it to
+the returned PyMemoryViewObject, to take ownership of it. Fixes a ref leak.
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -8,6 +8,7 @@
 
 from rpython.rlib.jit import promote
 from rpython.rlib.objectmodel import compute_identity_hash, specialize
+from rpython.rlib.objectmodel import instantiate
 from rpython.tool.sourcetools import compile2, func_with_new_name
 
 
@@ -221,10 +222,6 @@
 exec source.compile() in miniglobals
 return miniglobals['descr_typecheck_%s' % func.__name__]
 
-def unknown_objclass_getter(space):
-# NB. this is an AttributeError to make inspect.py happy
-raise oefmt(space.w_AttributeError, "generic property has no __objclass__")
-
 @specialize.arg(0)
 def make_objclass_getter(tag, func, cls):
 if func and hasattr(func, 'im_func'):
@@ -235,7 +232,7 @@
 @specialize.memo()
 def _make_objclass_getter(cls):
 if not cls:
-return unknown_objclass_getter, cls
+return None, cls
 miniglobals = {}
 if isinstance(cls, str):
 assert cls.startswith('<'), "pythontype typecheck should begin with <"
@@ -254,6 +251,8 @@
 
 class GetSetProperty(W_Root):
 _immutable_fields_ = ["fget", "fset", "fdel"]
+name = ''
+w_objclass = None
 
 @specialize.arg(7)
 def __init__(self, fget, fset=None, fdel=None, doc=None,
@@ -265,15 +264,25 @@
 cls=cls, use_closure=use_closure)
 fdel = make_descr_typecheck_wrapper((tag, 2), fdel,
 cls=cls, use_closure=use_closure)
+self._init(fget, fset, fdel, doc, cls, objclass_getter, use_closure)
+
+def _init(self, fget, fset, fdel, doc, cls, objclass_getter, use_closure):
 self.fget = fget
 self.fset = fset
 self.fdel = fdel
 self.doc = doc
 self.reqcls = cls
-self.name = ''
 self.objclass_getter = objclass_getter
 self.use_closure = use_closure
 
+def copy_for_type(self, w_objclass):
+new = instantiate(GetSetProperty)
+new._init(self.fget, self.fset, self.fdel, self.doc, self.reqcls,
+  None, self.use_closure)
+new.name = self.name
+new.w_objclass = w_objclass
+return new
+
 @unwrap_spec(w_cls = WrappedDefault(None))
 def descr_property_get(self, space, w_obj, w_cls=None):
 """property.__get__(obj[, type]) -> value
@@ -322,7 +331,14 @@
space.wrap(self.name)]))
 
 def descr_get_objclass(space, property):
-return property.objclass_getter(space)
+if property.w_objclass is not None:
+return property.w_objclass
+if property.objclass_getter is not None:
+return property.objclass_getter(space)
+# NB. this is an AttributeError to make inspect.py happy
+raise oefmt(space.w_AttributeError,
+"generic property has no __objclass__")
+
 
 def interp_attrproperty(name, cls, doc=None):
 "NOT_RPYTHON: initialization-time only"
@@ -467,7 +483,7 @@
 return lifeline.get_any_weakref(space)
 
 dict_descr = GetSetProperty(descr_get_dict, descr_set_dict, descr_del_dict,
-doc="dictionary for instance variables (if 
defined)")
+doc="dictionary for instance variables")
 dict_descr.name = '__dict__'
 
 
@@ -499,7 +515,7 @@
 return space.newtuple([w_docstring])
 
 weakref_descr = GetSetProperty(descr_get_weakref,
-doc="list of weak references to the object (if defined)")
+   doc="list of weak references to the object")
 weakref_descr.name = '__weakref__'
 
 def make_weakref_descr(cls):
diff --git a/pypy/module/cppyy/test/conftest.py 
b/pypy/module/cppyy/test/conftest.py
--- a/pypy/module/cppyy/test/conftest.py
+++ b/pypy/module/cppyy/test/conftest.py
@@ -23,6 +23,10 @@
 def pytest_ignore_collect(path, config):
 if py.path.local.sysfind('genreflex') is None and 
config.option.runappdirect:
 return True  # "can't run dummy tests in -A"
+if disabled:
+return True
+
+disabled = None
 
 def pytest_configure(config):
 if py.path.local.sysfind('genreflex') is None:
@@ -37,7 +41,7 @@
 # build dummy backend (which has reflex info and calls hard-wired)
 impor

[pypy-commit] pypy py3.5: Delay adding __package__, __loader__ and __spec__ in a new module's dict

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89513:47871510f0e3
Date: 2017-01-12 15:45 +0100
http://bitbucket.org/pypy/pypy/changeset/47871510f0e3/

Log:Delay adding __package__, __loader__ and __spec__ in a new module's
dict to the actual call of __init__()

diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -14,7 +14,7 @@
 
 _frozen = False
 
-def __init__(self, space, w_name, w_dict=None, add_package=True):
+def __init__(self, space, w_name, w_dict=None):
 self.space = space
 if w_dict is None:
 w_dict = space.newdict(module=True)
@@ -22,9 +22,6 @@
 self.w_name = w_name
 if w_name is not None:
 space.setitem(w_dict, space.new_interned_str('__name__'), w_name)
-# add these three attributes always ('add_package' is no longer used)
-for extra in ['__package__', '__loader__', '__spec__']:
-space.setitem(w_dict, space.new_interned_str(extra), space.w_None)
 self.startup_called = False
 
 def _cleanup_(self):
@@ -76,7 +73,7 @@
 
 def descr_module__new__(space, w_subtype, __args__):
 module = space.allocate_instance(Module, w_subtype)
-Module.__init__(module, space, None, add_package=False)
+Module.__init__(module, space, None)
 return space.wrap(module)
 
 def descr_module__init__(self, w_name, w_doc=None):
@@ -84,8 +81,10 @@
 self.w_name = w_name
 if w_doc is None:
 w_doc = space.w_None
-space.setitem(self.w_dict, space.new_interned_str('__name__'), w_name)
-space.setitem(self.w_dict, space.new_interned_str('__doc__'), w_doc)
+w_dict = self.w_dict
+space.setitem(w_dict, space.new_interned_str('__name__'), w_name)
+space.setitem(w_dict, space.new_interned_str('__doc__'), w_doc)
+init_extra_module_attrs(space, space.wrap(self))
 
 def descr__reduce__(self, space):
 w_name = space.finditem(self.w_dict, space.wrap('__name__'))
@@ -143,3 +142,12 @@
 raise oefmt(space.w_TypeError, "%N.__dict__ is not a dictionary",
 self)
 return space.call_function(space.w_list, w_dict)
+
+
+def init_extra_module_attrs(space, w_mod):
+w_dict = w_mod.getdict(space)
+if w_dict is None:
+return
+for extra in ['__package__', '__loader__', '__spec__']:
+w_attr = space.new_interned_str(extra)
+space.call_method(w_dict, 'setdefault', w_attr, space.w_None)
diff --git a/pypy/interpreter/test/test_module.py 
b/pypy/interpreter/test/test_module.py
--- a/pypy/interpreter/test/test_module.py
+++ b/pypy/interpreter/test/test_module.py
@@ -215,3 +215,8 @@
   '__package__': None,
   '__loader__': None,
   '__spec__': None}
+
+def test_module_new_makes_empty_dict(self):
+import sys
+m = type(sys).__new__(type(sys))
+assert not m.__dict__
diff --git a/pypy/module/_pickle_support/maker.py 
b/pypy/module/_pickle_support/maker.py
--- a/pypy/module/_pickle_support/maker.py
+++ b/pypy/module/_pickle_support/maker.py
@@ -27,7 +27,7 @@
 return space.wrap(fu)
 
 def module_new(space, w_name, w_dict):
-new_mod = Module(space, w_name, w_dict, add_package=False)
+new_mod = Module(space, w_name, w_dict)
 return space.wrap(new_mod)
 
 def method_new(space, __args__):
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -4,7 +4,7 @@
 
 import sys, os, stat
 
-from pypy.interpreter.module import Module
+from pypy.interpreter.module import Module, init_extra_module_attrs
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, generic_new_descr
 from pypy.interpreter.error import OperationError, oefmt
@@ -113,11 +113,13 @@
 space.setattr(w_mod, w('__doc__'), space.w_None)
 if pkgdir is not None:
 space.setattr(w_mod, w('__path__'), space.newlist([w(pkgdir)]))
+init_extra_module_attrs(space, w_mod)
 
 def add_module(space, w_name):
 w_mod = check_sys_modules(space, w_name)
 if w_mod is None:
 w_mod = space.wrap(Module(space, w_name))
+init_extra_module_attrs(space, w_mod)
 space.sys.setmodule(w_mod)
 return w_mod
 
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy rffi-parser-2: Expand pseudo-header

2017-01-12 Thread rlamy
Author: Ronan Lamy 
Branch: rffi-parser-2
Changeset: r89507:02d7b8efbcaa
Date: 2016-12-18 01:38 +
http://bitbucket.org/pypy/pypy/changeset/02d7b8efbcaa/

Log:Expand pseudo-header

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
@@ -674,6 +674,51 @@
 typedef struct _typeobject PyTypeObject;
 
 typedef void (*freefunc)(void *);
+typedef void (*destructor)(PyObject *);
+typedef int (*printfunc)(PyObject *, FILE *, int);
+typedef PyObject *(*getattrfunc)(PyObject *, char *);
+typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
+typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
+typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
+typedef int (*cmpfunc)(PyObject *, PyObject *);
+typedef PyObject *(*reprfunc)(PyObject *);
+typedef long (*hashfunc)(PyObject *);
+typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
+typedef PyObject *(*getiterfunc) (PyObject *);
+typedef PyObject *(*iternextfunc) (PyObject *);
+typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);
+typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);
+typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
+typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
+typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
+
+typedef PyObject * (*unaryfunc)(PyObject *);
+typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
+typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
+typedef int (*inquiry)(PyObject *);
+typedef Py_ssize_t (*lenfunc)(PyObject *);
+typedef int (*coercion)(PyObject **, PyObject **);
+typedef PyObject *(*intargfunc)(PyObject *, int);
+typedef PyObject *(*intintargfunc)(PyObject *, int, int);
+typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
+typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
+typedef int(*intobjargproc)(PyObject *, int, PyObject *);
+typedef int(*intintobjargproc)(PyObject *, int, int, PyObject *);
+typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
+typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, 
PyObject *);
+typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
+
+
+/* int-based buffer interface */
+typedef int (*getreadbufferproc)(PyObject *, int, void **);
+typedef int (*getwritebufferproc)(PyObject *, int, void **);
+typedef int (*getsegcountproc)(PyObject *, int *);
+typedef int (*getcharbufferproc)(PyObject *, int, char **);
+/* ssize_t-based buffer interface */
+typedef Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **);
+typedef Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **);
+typedef Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *);
+typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, char **);
 
 /* Py3k buffer interface, adapted for PyPy */
 #define Py_MAX_NDIMS 32
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: - Skip a test that cannot pass on PyPy

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89514:c217aa239223
Date: 2017-01-12 16:08 +0100
http://bitbucket.org/pypy/pypy/changeset/c217aa239223/

Log:- Skip a test that cannot pass on PyPy

- Update a test with its content in the latest 3.5.x version,
because neither PyPy nor 3.5.2+ passes it

diff --git a/lib-python/3/test/test_traceback.py 
b/lib-python/3/test/test_traceback.py
--- a/lib-python/3/test/test_traceback.py
+++ b/lib-python/3/test/test_traceback.py
@@ -8,6 +8,7 @@
 import re
 from test import support
 from test.support import TESTFN, Error, captured_output, unlink, cpython_only
+from test.support import impl_detail
 from test.support.script_helper import assert_python_ok
 import textwrap
 
@@ -179,6 +180,7 @@
 # Issue #18960: coding spec should has no effect
 do_test("0\n# coding: GBK\n", "h\xe9 ho", 'utf-8', 5)
 
+@impl_detail(pypy=False)   # __del__ is typically not called at shutdown
 def test_print_traceback_at_exit(self):
 # Issue #22599: Ensure that it is possible to use the traceback module
 # to display an exception at Python exit
@@ -681,8 +683,12 @@
 class TestStack(unittest.TestCase):
 
 def test_walk_stack(self):
-s = list(traceback.walk_stack(None))
-self.assertGreater(len(s), 10)
+def deeper():
+return list(traceback.walk_stack(None))
+s1 = list(traceback.walk_stack(None))
+s2 = deeper()
+self.assertEqual(len(s2) - len(s1), 1)
+self.assertEqual(s2[1:], s1)
 
 def test_walk_tb(self):
 try:
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: generalize the expected error messages

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89515:511e7a4e706b
Date: 2017-01-12 16:13 +0100
http://bitbucket.org/pypy/pypy/changeset/511e7a4e706b/

Log:generalize the expected error messages

diff --git a/lib-python/3/test/test_syntax.py b/lib-python/3/test/test_syntax.py
--- a/lib-python/3/test/test_syntax.py
+++ b/lib-python/3/test/test_syntax.py
@@ -31,9 +31,9 @@
 Traceback (most recent call last):
 SyntaxError: invalid syntax
 
->>> None = 1
+>>> None = 1 # doctest: +ELLIPSIS
 Traceback (most recent call last):
-SyntaxError: can't assign to keyword
+SyntaxError: can't assign to ...
 
 It's a syntax error to assign to the empty tuple.  Why isn't it an
 error to assign to the empty list?  It will always raise some error at
@@ -234,9 +234,9 @@
 >>> (x for x in x) += 1
 Traceback (most recent call last):
 SyntaxError: can't assign to generator expression
->>> None += 1
+>>> None += 1  # doctest: +ELLIPSIS
 Traceback (most recent call last):
-SyntaxError: can't assign to keyword
+SyntaxError: can't assign to ...
 >>> f() += 1
 Traceback (most recent call last):
 SyntaxError: can't assign to function call
@@ -501,17 +501,17 @@
 
 Corner-cases that used to fail to raise the correct error:
 
->>> def f(*, x=lambda __debug__:0): pass
+>>> def f(*, x=lambda __debug__:0): pass  # doctest: +ELLIPSIS
 Traceback (most recent call last):
-SyntaxError: assignment to keyword
+SyntaxError: ...assign... to ...
 
->>> def f(*args:(lambda __debug__:0)): pass
+>>> def f(*args:(lambda __debug__:0)): pass   # doctest: +ELLIPSIS
 Traceback (most recent call last):
-SyntaxError: assignment to keyword
+SyntaxError: ...assign... to ...
 
->>> def f(**kwargs:(lambda __debug__:0)): pass
+>>> def f(**kwargs:(lambda __debug__:0)): pass# doctest: +ELLIPSIS
 Traceback (most recent call last):
-SyntaxError: assignment to keyword
+SyntaxError: ...assign... to ...
 
 >>> with (lambda *:0): pass
 Traceback (most recent call last):
@@ -519,13 +519,13 @@
 
 Corner-cases that used to crash:
 
->>> def f(**__debug__): pass
+>>> def f(**__debug__): pass  # doctest: +ELLIPSIS
 Traceback (most recent call last):
-SyntaxError: assignment to keyword
+SyntaxError: ...assign... to ...
 
->>> def f(*xx, __debug__): pass
+>>> def f(*xx, __debug__): pass   # doctest: +ELLIPSIS
 Traceback (most recent call last):
-SyntaxError: assignment to keyword
+SyntaxError: ...assign... to ...
 
 """
 
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fix the warnings in audioop, introduced in a recent cffi version

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r89516:532396b48a7f
Date: 2017-01-12 16:26 +0100
http://bitbucket.org/pypy/pypy/changeset/532396b48a7f/

Log:Fix the warnings in audioop, introduced in a recent cffi version

diff --git a/lib_pypy/audioop.py b/lib_pypy/audioop.py
--- a/lib_pypy/audioop.py
+++ b/lib_pypy/audioop.py
@@ -374,7 +374,7 @@
 
 sample_count = _sample_count(cp, size)
 
-rv = ffi.new("unsigned char[]", len(cp) * 2)
+rv = ffi.new("char[]", len(cp) * 2)
 lib.tostereo(rv, cp, len(cp), size, fac1, fac2)
 return ffi.buffer(rv)[:]
 
@@ -385,7 +385,7 @@
 if len(cp1) != len(cp2):
 raise error("Lengths should be the same")
 
-rv = ffi.new("unsigned char[]", len(cp1))
+rv = ffi.new("char[]", len(cp1))
 lib.add(rv, cp1, cp2, len(cp1), size)
 return ffi.buffer(rv)[:]
 
@@ -488,7 +488,7 @@
 ceiling = (q + 1) * outrate
 nbytes = ceiling * bytes_per_frame
 
-rv = ffi.new("unsigned char[]", nbytes)
+rv = ffi.new("char[]", nbytes)
 trim_index = lib.ratecv(rv, cp, frame_count, size,
 nchannels, inrate, outrate,
 state_d, prev_i, cur_i,
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Fix the hack: it's possible to call subprocess.Popen() with

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89517:8b095830ab66
Date: 2017-01-12 16:30 +0100
http://bitbucket.org/pypy/pypy/changeset/8b095830ab66/

Log:Fix the hack: it's possible to call subprocess.Popen() with a
generator or other lazy object as 'args'

diff --git a/lib-python/3/subprocess.py b/lib-python/3/subprocess.py
--- a/lib-python/3/subprocess.py
+++ b/lib-python/3/subprocess.py
@@ -849,7 +849,7 @@
 
 # --- PyPy hack, see _pypy_install_libs_after_virtualenv() ---
 # match arguments passed by different versions of virtualenv
-if args[1:] in (
+if type(args) is list and args[1:] in (
 ['-c', 'import sys; print(sys.prefix)'],# 1.6 10ba3f3c
 ['-c', "\nimport sys\nprefix = sys.prefix\n"# 1.7 0e9342ce
  "if sys.version_info[0] == 3:\n"
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: All the tests give a sensible result on PyPy too (tested manually in

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89518:51b0c8f1d834
Date: 2017-01-12 16:55 +0100
http://bitbucket.org/pypy/pypy/changeset/51b0c8f1d834/

Log:All the tests give a sensible result on PyPy too (tested manually in
py3.5, revision e0ba73be669b, by setting maxDiff=None in the class).
The details of the outputs differ too much to make it easy to
generalize the tests to accept both CPython's and PyPy's style. For
now let's skip the tests on PyPy.

diff --git a/lib-python/3/test/test_faulthandler.py 
b/lib-python/3/test/test_faulthandler.py
--- a/lib-python/3/test/test_faulthandler.py
+++ b/lib-python/3/test/test_faulthandler.py
@@ -41,6 +41,12 @@
 finally:
 support.unlink(filename)
 
+# NOTE: all the tests give a sensible result on PyPy too (tested
+# manually in py3.5, revision e0ba73be669b, by setting maxDiff=None in
+# the class).  The details of the outputs differ too much to make it
+# easy to generalize the tests to accept both CPython's and PyPy's
+# style.  For now let's skip the tests on PyPy.
[email protected]_only
 class FaultHandlerTests(unittest.TestCase):
 def get_output(self, code, filename=None, fd=None):
 """
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: call int() on ffi.cast("intptr_t", ...) to ensure string formating does not throw

2017-01-12 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5
Changeset: r89519:a372a26b6ec0
Date: 2017-01-12 17:33 +0100
http://bitbucket.org/pypy/pypy/changeset/a372a26b6ec0/

Log:call int() on ffi.cast("intptr_t", ...) to ensure string formating
does not throw

diff --git a/lib_pypy/_tkinter/tclobj.py b/lib_pypy/_tkinter/tclobj.py
--- a/lib_pypy/_tkinter/tclobj.py
+++ b/lib_pypy/_tkinter/tclobj.py
@@ -185,7 +185,7 @@
 
 def __repr__(self):
 return "<%s object at 0x%x>" % (
-self.typename, tkffi.cast("intptr_t", self._value))
+self.typename, int(tkffi.cast("intptr_t", self._value)))
 
 def __eq__(self, other):
 if not isinstance(other, Tcl_Obj):
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy rffi-parser-2: Add a way to create API functions using C declarations; try to use it

2017-01-12 Thread rlamy
Author: Ronan Lamy 
Branch: rffi-parser-2
Changeset: r89520:05b94a8b7e3d
Date: 2017-01-12 16:40 +
http://bitbucket.org/pypy/pypy/changeset/05b94a8b7e3d/

Log:Add a way to create API functions using C declarations; try to use
it

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
@@ -246,13 +246,15 @@
 
 class ApiFunction(object):
 def __init__(self, argtypes, restype, callable, error=CANNOT_FAIL,
- c_name=None, gil=None, result_borrowed=False, 
result_is_ll=False):
+ c_name=None, cdecl=None, gil=None,
+ result_borrowed=False, result_is_ll=False):
 self.argtypes = argtypes
 self.restype = restype
 self.functype = lltype.Ptr(lltype.FuncType(argtypes, restype))
 self.callable = callable
 self.error_value = error
 self.c_name = c_name
+self.cdecl = cdecl
 
 # extract the signature from the (CPython-level) code object
 from pypy.interpreter import pycode
@@ -371,6 +373,8 @@
 return unwrapper
 
 def get_c_restype(self, c_writer):
+if self.cdecl:
+return self.cdecl.split(self.c_name)[0].strip()
 return c_writer.gettype(self.restype).replace('@', '').strip()
 
 def get_c_args(self, c_writer):
@@ -470,6 +474,20 @@
 return unwrapper
 return decorate
 
+def api_decl(cdecl, cts, error=_NOT_SPECIFIED, header=DEFAULT_HEADER):
+def decorate(func):
+func._always_inline_ = 'try'
+name, FUNC = cts.parse_func(cdecl)
+api_function = ApiFunction(
+FUNC.ARGS, FUNC.RESULT, func,
+error=_compute_error(error, FUNC.RESULT), cdecl=cdecl)
+FUNCTIONS_BY_HEADER[header][name] = api_function
+unwrapper = api_function.get_unwrapper()
+unwrapper.func = func
+unwrapper.api_func = api_function
+return unwrapper
+return decorate
+
 def slot_function(argtypes, restype, error=_NOT_SPECIFIED):
 def decorate(func):
 func._always_inline_ = 'try'
diff --git a/pypy/module/cpyext/methodobject.py 
b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -11,12 +11,10 @@
 CONST_STRING, METH_CLASS, METH_COEXIST, METH_KEYWORDS, METH_NOARGS, METH_O,
 METH_STATIC, METH_VARARGS, PyObject, PyObjectFields, bootstrap_function,
 build_type_checkers, cpython_api, cpython_struct, generic_cpy_call,
-PyTypeObjectPtr, slot_function, object_h)
+PyTypeObjectPtr, slot_function, object_h, api_decl)
 from pypy.module.cpyext.pyobject import (
 Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
 
-PyCFunction_typedef = rffi.COpaquePtr(typedef='PyCFunction')
-
 PyMethodDef = object_h.gettype('PyMethodDef')
 PyCFunction = object_h.gettype('PyCFunction')
 PyCFunctionKwArgs = object_h.gettype('PyCFunctionWithKeywords')
@@ -284,7 +282,7 @@
 def PyCFunction_NewEx(space, ml, w_self, w_name):
 return space.wrap(W_PyCFunctionObject(space, ml, w_self, w_name))
 
-@cpython_api([PyObject], PyCFunction_typedef)
+@api_decl("PyCFunction PyCFunction_GetFunction(PyObject *)", object_h)
 def PyCFunction_GetFunction(space, w_obj):
 try:
 cfunction = space.interp_w(W_PyCFunctionObject, w_obj)
diff --git a/pypy/module/cpyext/test/test_methodobject.py 
b/pypy/module/cpyext/test/test_methodobject.py
--- a/pypy/module/cpyext/test/test_methodobject.py
+++ b/pypy/module/cpyext/test/test_methodobject.py
@@ -4,7 +4,7 @@
 from pypy.module.cpyext.api import ApiFunction
 from pypy.module.cpyext.pyobject import PyObject, make_ref, Py_DecRef
 from pypy.module.cpyext.methodobject import (
-PyDescr_NewMethod, PyCFunction_typedef)
+PyDescr_NewMethod, PyCFunction)
 from rpython.rtyper.lltypesystem import rffi, lltype
 
 class AppTestMethodObject(AppTestCpythonExtensionBase):
@@ -67,7 +67,7 @@
  '''
  PyCFunction ptr = PyCFunction_GetFunction(args);
  if (!ptr) return NULL;
- if (ptr == MyModule_getarg_O)
+ if (ptr == (PyCFunction)MyModule_getarg_O)
  Py_RETURN_TRUE;
  else
  Py_RETURN_FALSE;
@@ -105,8 +105,7 @@
 ml = lltype.malloc(PyMethodDef, flavor='raw', zero=True)
 namebuf = rffi.cast(rffi.CONST_CCHARP, rffi.str2charp('func'))
 ml.c_ml_name = namebuf
-ml.c_ml_meth = rffi.cast(PyCFunction_typedef,
- c_func.get_llhelper(space))
+ml.c_ml_meth = rffi.cast(PyCFunction, c_func.get_llhelper(space))
 
 method = api.PyDescr_NewMethod(space.w_str, ml)
 assert repr(method).startswith(
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -19,7 +19,7 @@
 Py_TPFLAGS_HAVE_NEWBUFFER, Py_TPFLAGS_CHECKTYPES,
 Py_TPFLAGS_HAVE_I

[pypy-commit] pypy py3.5: add failing test from stdlib for memoryview

2017-01-12 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5
Changeset: r89521:de8975b7947d
Date: 2017-01-12 18:13 +0100
http://bitbucket.org/pypy/pypy/changeset/de8975b7947d/

Log:add failing test from stdlib for memoryview

diff --git a/pypy/objspace/std/test/test_memoryobject.py 
b/pypy/objspace/std/test/test_memoryobject.py
--- a/pypy/objspace/std/test/test_memoryobject.py
+++ b/pypy/objspace/std/test/test_memoryobject.py
@@ -193,6 +193,12 @@
 def test_hex(self):
 assert memoryview(b"abc").hex() == u'616263'
 
+def test_hex_long(self):
+x = b'0' * 20
+m1 = memoryview(x)
+m2 = m1[::-1]
+assert m2.hex() == '30' * 20
+
 def test_memoryview_cast(self):
 m1 = memoryview(b'abcdefgh')
 m2 = m1.cast('I')
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: replace commenting-out-some-lines with check_impl_detail()

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r89523:4b05cf3a2baf
Date: 2017-01-12 18:15 +0100
http://bitbucket.org/pypy/pypy/changeset/4b05cf3a2baf/

Log:replace commenting-out-some-lines with check_impl_detail()

diff --git a/lib-python/2.7/test/test_multiprocessing.py 
b/lib-python/2.7/test/test_multiprocessing.py
--- a/lib-python/2.7/test/test_multiprocessing.py
+++ b/lib-python/2.7/test/test_multiprocessing.py
@@ -1969,9 +1969,10 @@
 if not gc.isenabled():
 gc.enable()
 self.addCleanup(gc.disable)
-#thresholds = gc.get_threshold()
-#self.addCleanup(gc.set_threshold, *thresholds)
-#gc.set_threshold(10)
+if test_support.check_impl_detail(cpython=True):
+thresholds = gc.get_threshold()
+self.addCleanup(gc.set_threshold, *thresholds)
+gc.set_threshold(10)
 
 # perform numerous block allocations, with cyclic references to make
 # sure objects are collected asynchronously by the gc
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: The T_XXX assignments now do range checking and raise a warning

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89525:f7ca99898732
Date: 2017-01-12 19:01 +0100
http://bitbucket.org/pypy/pypy/changeset/f7ca99898732/

Log:The T_XXX assignments now do range checking and raise a warning

diff --git a/pypy/module/cpyext/structmember.py 
b/pypy/module/cpyext/structmember.py
--- a/pypy/module/cpyext/structmember.py
+++ b/pypy/module/cpyext/structmember.py
@@ -20,21 +20,21 @@
 return True
 raise oefmt(space.w_TypeError, "attribute value type must be bool")
 
-integer_converters = unrolling_iterable([
-(T_SHORT,  rffi.SHORT,  PyLong_AsLong),
-(T_INT,rffi.INT,PyLong_AsLong),
-(T_LONG,   rffi.LONG,   PyLong_AsLong),
-(T_USHORT, rffi.USHORT, PyLong_AsUnsignedLong),
-(T_UINT,   rffi.UINT,   PyLong_AsUnsignedLong),
-(T_ULONG,  rffi.ULONG,  PyLong_AsUnsignedLong),
-(T_BYTE,   rffi.SIGNEDCHAR, PyLong_AsLong),
-(T_UBYTE,  rffi.UCHAR,  PyLong_AsUnsignedLong),
-(T_BOOL,   rffi.UCHAR,  convert_bool),
-(T_FLOAT,  rffi.FLOAT,  PyFloat_AsDouble),
-(T_DOUBLE, rffi.DOUBLE, PyFloat_AsDouble),
-(T_LONGLONG,  rffi.LONGLONG,  PyLong_AsLongLong),
-(T_ULONGLONG, rffi.ULONGLONG, PyLong_AsUnsignedLongLong),
-(T_PYSSIZET, rffi.SSIZE_T, PyLong_AsSsize_t),
+integer_converters = unrolling_iterable([ # range checking
+(T_SHORT,  rffi.SHORT,  PyLong_AsLong,True),
+(T_INT,rffi.INT,PyLong_AsLong,True),
+(T_LONG,   rffi.LONG,   PyLong_AsLong,False),
+(T_USHORT, rffi.USHORT, PyLong_AsUnsignedLong,True),
+(T_UINT,   rffi.UINT,   PyLong_AsUnsignedLong,True),
+(T_ULONG,  rffi.ULONG,  PyLong_AsUnsignedLong,False),
+(T_BYTE,   rffi.SIGNEDCHAR, PyLong_AsLong,True),
+(T_UBYTE,  rffi.UCHAR,  PyLong_AsUnsignedLong,True),
+(T_BOOL,   rffi.UCHAR,  convert_bool, False),
+(T_FLOAT,  rffi.FLOAT,  PyFloat_AsDouble, False),
+(T_DOUBLE, rffi.DOUBLE, PyFloat_AsDouble, False),
+(T_LONGLONG,  rffi.LONGLONG,  PyLong_AsLongLong,  False),
+(T_ULONGLONG, rffi.ULONGLONG, PyLong_AsUnsignedLongLong,  False),
+(T_PYSSIZET, rffi.SSIZE_T, PyLong_AsSsize_t,  False),
 ])
 
 _HEADER = 'pypy_structmember_decl.h'
@@ -47,7 +47,7 @@
 
 member_type = rffi.cast(lltype.Signed, w_member.c_type)
 for converter in integer_converters:
-typ, lltyp, _ = converter
+typ, lltyp, _, _ = converter
 if typ == member_type:
 result = rffi.cast(rffi.CArrayPtr(lltyp), addr)
 if lltyp is rffi.FLOAT:
@@ -112,11 +112,16 @@
 "can't delete numeric/char attribute")
 
 for converter in integer_converters:
-typ, lltyp, getter = converter
+typ, lltyp, getter, range_checking = converter
 if typ == member_type:
 value = getter(space, w_value)
 array = rffi.cast(rffi.CArrayPtr(lltyp), addr)
-array[0] = rffi.cast(lltyp, value)
+casted = rffi.cast(lltyp, value)
+if range_checking:
+if rffi.cast(lltype.typeOf(value), casted) != value:
+space.warn(space.wrap("structmember: truncation of value"),
+   space.w_RuntimeWarning)
+array[0] = casted
 return 0
 
 if member_type == T_CHAR:
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: merge heads

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89527:daf8de0e7dab
Date: 2017-01-12 19:25 +0100
http://bitbucket.org/pypy/pypy/changeset/daf8de0e7dab/

Log:merge heads

diff --git a/lib_pypy/_tkinter/tclobj.py b/lib_pypy/_tkinter/tclobj.py
--- a/lib_pypy/_tkinter/tclobj.py
+++ b/lib_pypy/_tkinter/tclobj.py
@@ -185,7 +185,7 @@
 
 def __repr__(self):
 return "<%s object at 0x%x>" % (
-self.typename, tkffi.cast("intptr_t", self._value))
+self.typename, int(tkffi.cast("intptr_t", self._value)))
 
 def __eq__(self, other):
 if not isinstance(other, Tcl_Obj):
diff --git a/pypy/objspace/std/test/test_memoryobject.py 
b/pypy/objspace/std/test/test_memoryobject.py
--- a/pypy/objspace/std/test/test_memoryobject.py
+++ b/pypy/objspace/std/test/test_memoryobject.py
@@ -193,6 +193,12 @@
 def test_hex(self):
 assert memoryview(b"abc").hex() == u'616263'
 
+def test_hex_long(self):
+x = b'0' * 20
+m1 = memoryview(x)
+m2 = m1[::-1]
+assert m2.hex() == '30' * 20
+
 def test_memoryview_cast(self):
 m1 = memoryview(b'abcdefgh')
 m2 = m1.cast('I')
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Fix (without test, because there doesn't seem to be any test for the

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89524:24048a09826f
Date: 2017-01-12 18:26 +0100
http://bitbucket.org/pypy/pypy/changeset/24048a09826f/

Log:Fix (without test, because there doesn't seem to be any test for the
whole module; relying here on lib-
python/3/test/test_structmembers.py)

diff --git a/pypy/module/cpyext/structmember.py 
b/pypy/module/cpyext/structmember.py
--- a/pypy/module/cpyext/structmember.py
+++ b/pypy/module/cpyext/structmember.py
@@ -13,6 +13,13 @@
 from pypy.module.cpyext.typeobjectdefs import PyMemberDef
 from rpython.rlib.unroll import unrolling_iterable
 
+def convert_bool(space, w_obj):
+if space.is_w(w_obj, space.w_False):
+return False
+if space.is_w(w_obj, space.w_True):
+return True
+raise oefmt(space.w_TypeError, "attribute value type must be bool")
+
 integer_converters = unrolling_iterable([
 (T_SHORT,  rffi.SHORT,  PyLong_AsLong),
 (T_INT,rffi.INT,PyLong_AsLong),
@@ -22,7 +29,7 @@
 (T_ULONG,  rffi.ULONG,  PyLong_AsUnsignedLong),
 (T_BYTE,   rffi.SIGNEDCHAR, PyLong_AsLong),
 (T_UBYTE,  rffi.UCHAR,  PyLong_AsUnsignedLong),
-(T_BOOL,   rffi.UCHAR,  PyLong_AsLong),
+(T_BOOL,   rffi.UCHAR,  convert_bool),
 (T_FLOAT,  rffi.FLOAT,  PyFloat_AsDouble),
 (T_DOUBLE, rffi.DOUBLE, PyFloat_AsDouble),
 (T_LONGLONG,  rffi.LONGLONG,  PyLong_AsLongLong),
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: obscure fixes for test___all__.py

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89522:048d4b329858
Date: 2017-01-12 18:07 +0100
http://bitbucket.org/pypy/pypy/changeset/048d4b329858/

Log:obscure fixes for test___all__.py

diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -220,4 +220,9 @@
 for constant in dir(os):
 value = getattr(os, constant)
 if constant.isupper() and type(value) is int:
+if constant in ['SEEK_SET', 'SEEK_CUR', 'SEEK_END',
+'P_NOWAIT', 'P_NOWAITO', 'P_WAIT']:
+# obscure, but these names are not in CPython's posix module
+# and if we put it here then they end up twice in 'os.__all__'
+continue
 Module.interpleveldefs[constant] = "space.wrap(%s)" % value
diff --git a/pypy/module/token/__init__.py b/pypy/module/token/__init__.py
--- a/pypy/module/token/__init__.py
+++ b/pypy/module/token/__init__.py
@@ -22,6 +22,11 @@
 Module.interpleveldefs["tok_name"] = "space.wrap(%r)" % (tok_name,)
 Module.interpleveldefs["N_TOKENS"] = "space.wrap(%d)" % len(tok_name)
 all_names = Module.interpleveldefs.keys()
+# obscure, but these names are not in CPython's token module
+# so we remove them from 'token.__all__' otherwise they end up
+# twice in 'tokenize.__all__'
+all_names.remove('COMMENT')
+all_names.remove('NL')
 Module.interpleveldefs["__all__"] = "space.wrap(%r)" % (all_names,)
 
 _init_tokens()
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Update the version numbers to 3.5.2, after 215771f42f81

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89526:dbe5313227fc
Date: 2017-01-12 19:19 +0100
http://bitbucket.org/pypy/pypy/changeset/dbe5313227fc/

Log:Update the version numbers to 3.5.2, after 215771f42f81

diff --git a/pypy/module/cpyext/include/patchlevel.h 
b/pypy/module/cpyext/include/patchlevel.h
--- a/pypy/module/cpyext/include/patchlevel.h
+++ b/pypy/module/cpyext/include/patchlevel.h
@@ -21,12 +21,12 @@
 /* Version parsed out into numeric values */
 #define PY_MAJOR_VERSION   3
 #define PY_MINOR_VERSION   5
-#define PY_MICRO_VERSION   1
+#define PY_MICRO_VERSION   2
 #define PY_RELEASE_LEVEL   PY_RELEASE_LEVEL_FINAL
 #define PY_RELEASE_SERIAL  0
 
 /* Version as a string */
-#define PY_VERSION "3.5.1"
+#define PY_VERSION "3.5.2"
 
 /* PyPy version as a string */
 #define PYPY_VERSION "5.6.0-alpha0"
diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py
--- a/pypy/module/sys/version.py
+++ b/pypy/module/sys/version.py
@@ -6,7 +6,7 @@
 from pypy.interpreter import gateway
 
 #XXX # the release serial 42 is not in range(16)
-CPYTHON_VERSION= (3, 5, 1, "final", 0)
+CPYTHON_VERSION= (3, 5, 2, "final", 0)
 #XXX # sync CPYTHON_VERSION with patchlevel.h, package.py
 CPYTHON_API_VERSION= 1013   #XXX # sync with include/modsupport.h
 
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy rffi-parser-2: Skip part of the test when untranslated (because something something ctypes).

2017-01-12 Thread rlamy
Author: Ronan Lamy 
Branch: rffi-parser-2
Changeset: r89528:ccc4bbdd1a66
Date: 2017-01-12 19:10 +
http://bitbucket.org/pypy/pypy/changeset/ccc4bbdd1a66/

Log:Skip part of the test when untranslated (because something something
ctypes).

diff --git a/pypy/module/cpyext/methodobject.py 
b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -67,7 +67,7 @@
 raise oefmt(space.w_TypeError,
 "%s() takes no keyword arguments", self.name)
 
-func = rffi.cast(PyCFunction, self.ml.c_ml_meth)
+func = self.ml.c_ml_meth
 length = space.int_w(space.len(w_args))
 if flags & METH_KEYWORDS:
 func = rffi.cast(PyCFunctionKwArgs, self.ml.c_ml_meth)
@@ -337,4 +337,3 @@
 if name == "__methods__":
 return space.newlist(method_list_w)
 raise OperationError(space.w_AttributeError, space.wrap(name))
-
diff --git a/pypy/module/cpyext/test/test_methodobject.py 
b/pypy/module/cpyext/test/test_methodobject.py
--- a/pypy/module/cpyext/test/test_methodobject.py
+++ b/pypy/module/cpyext/test/test_methodobject.py
@@ -89,7 +89,8 @@
 
 assert mod.isCFunction(mod.getarg_O) == "getarg_O"
 assert mod.getModule(mod.getarg_O) == 'MyModule'
-assert mod.isSameFunction(mod.getarg_O)
+if self.runappdirect:  # XXX: fails untranslated
+assert mod.isSameFunction(mod.getarg_O)
 raises(SystemError, mod.isSameFunction, 1)
 
 class TestPyCMethodObject(BaseApiTest):
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Skip this cElementTree test like all others in this file.

2017-01-12 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r89529:056552e32143
Date: 2016-12-07 16:36 +
http://bitbucket.org/pypy/pypy/changeset/056552e32143/

Log:Skip this cElementTree test like all others in this file.

diff --git a/lib-python/3/test/test_xml_etree_c.py 
b/lib-python/3/test/test_xml_etree_c.py
--- a/lib-python/3/test/test_xml_etree_c.py
+++ b/lib-python/3/test/test_xml_etree_c.py
@@ -11,6 +11,7 @@
 fresh=['_elementtree', 'xml.etree'])
 
 
[email protected](cET, 'requires _elementtree')
 class MiscTests(unittest.TestCase):
 # Issue #8651.
 @support.bigmemtest(size=support._2G + 100, memuse=1, dry_run=False)
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: This is how CPython reports all assignments to reserved names.

2017-01-12 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r89530:a1c35f4c589a
Date: 2017-01-12 22:16 +0100
http://bitbucket.org/pypy/pypy/changeset/a1c35f4c589a/

Log:This is how CPython reports all assignments to reserved names. (see
test_syntax.py)

diff --git a/pypy/interpreter/astcompiler/astbuilder.py 
b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -126,7 +126,7 @@
 try:
 misc.check_forbidden_name(name)
 except misc.ForbiddenNameAssignment as e:
-self.error("cannot assign to %s" % (e.name,), node)
+self.error("assignment to keyword", node)
 
 def new_identifier(self, name):
 return misc.new_identifier(self.space, name)
@@ -138,7 +138,7 @@
 except ast.UnacceptableExpressionContext as e:
 self.error_ast(e.msg, e.node)
 except misc.ForbiddenNameAssignment as e:
-self.error_ast("cannot assign to %s" % (e.name,), e.node)
+self.error_ast("assignment to keyword", e.node)
 
 def handle_del_stmt(self, del_node):
 targets = self.handle_exprlist(del_node.get_child(1), ast.Del)
diff --git a/pypy/interpreter/astcompiler/asthelpers.py 
b/pypy/interpreter/astcompiler/asthelpers.py
--- a/pypy/interpreter/astcompiler/asthelpers.py
+++ b/pypy/interpreter/astcompiler/asthelpers.py
@@ -182,5 +182,5 @@
 
 class __extend__(ast.NameConstant):
 
-_description = "name constant"
+_description = "keyword"
 constant = True
diff --git a/pypy/interpreter/astcompiler/test/test_astbuilder.py 
b/pypy/interpreter/astcompiler/test/test_astbuilder.py
--- a/pypy/interpreter/astcompiler/test/test_astbuilder.py
+++ b/pypy/interpreter/astcompiler/test/test_astbuilder.py
@@ -812,7 +812,7 @@
 for template in invalid:
 input = template % (name,)
 exc = py.test.raises(SyntaxError, self.get_ast, input).value
-assert exc.msg == "cannot assign to %s" % (name,)
+assert exc.msg == "assignment to keyword"
 
 def test_lambda(self):
 lam = self.get_first_expr("lambda x: expr")
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: pyclbr analyses the source code, and does not return aliased and renamed items.

2017-01-12 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r89531:da0283b19e53
Date: 2017-01-12 22:06 +0100
http://bitbucket.org/pypy/pypy/changeset/da0283b19e53/

Log:pyclbr analyses the source code, and does not return aliased and
renamed items. This happens for pickle.py, when the _pickle module
is not available.

diff --git a/lib-python/3/test/test_pyclbr.py b/lib-python/3/test/test_pyclbr.py
--- a/lib-python/3/test/test_pyclbr.py
+++ b/lib-python/3/test/test_pyclbr.py
@@ -125,7 +125,10 @@
 raise
 
 # Now check for missing stuff.
-def defined_in(item, module):
+def defined_in(item, module, name):
+if item.__name__ != name:
+# Item was defined with another name
+return False
 if isinstance(item, type):
 return item.__module__ == module.__name__
 if isinstance(item, FunctionType):
@@ -134,7 +137,7 @@
 for name in dir(module):
 item = getattr(module, name)
 if isinstance(item,  (type, FunctionType)):
-if defined_in(item, module):
+if defined_in(item, module, name):
 self.assertHaskey(dict, name, ignore)
 
 def test_easy(self):
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg backout a1c35f4c589a

2017-01-12 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r89532:056335ce40d8
Date: 2017-01-12 23:03 +0100
http://bitbucket.org/pypy/pypy/changeset/056335ce40d8/

Log:hg backout a1c35f4c589a

The test was fixed in 511e7a4e706b

diff --git a/pypy/interpreter/astcompiler/astbuilder.py 
b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -126,7 +126,7 @@
 try:
 misc.check_forbidden_name(name)
 except misc.ForbiddenNameAssignment as e:
-self.error("assignment to keyword", node)
+self.error("cannot assign to %s" % (e.name,), node)
 
 def new_identifier(self, name):
 return misc.new_identifier(self.space, name)
@@ -138,7 +138,7 @@
 except ast.UnacceptableExpressionContext as e:
 self.error_ast(e.msg, e.node)
 except misc.ForbiddenNameAssignment as e:
-self.error_ast("assignment to keyword", e.node)
+self.error_ast("cannot assign to %s" % (e.name,), e.node)
 
 def handle_del_stmt(self, del_node):
 targets = self.handle_exprlist(del_node.get_child(1), ast.Del)
diff --git a/pypy/interpreter/astcompiler/asthelpers.py 
b/pypy/interpreter/astcompiler/asthelpers.py
--- a/pypy/interpreter/astcompiler/asthelpers.py
+++ b/pypy/interpreter/astcompiler/asthelpers.py
@@ -182,5 +182,5 @@
 
 class __extend__(ast.NameConstant):
 
-_description = "keyword"
+_description = "name constant"
 constant = True
diff --git a/pypy/interpreter/astcompiler/test/test_astbuilder.py 
b/pypy/interpreter/astcompiler/test/test_astbuilder.py
--- a/pypy/interpreter/astcompiler/test/test_astbuilder.py
+++ b/pypy/interpreter/astcompiler/test/test_astbuilder.py
@@ -812,7 +812,7 @@
 for template in invalid:
 input = template % (name,)
 exc = py.test.raises(SyntaxError, self.get_ast, input).value
-assert exc.msg == "assignment to keyword"
+assert exc.msg == "cannot assign to %s" % (name,)
 
 def test_lambda(self):
 lam = self.get_first_expr("lambda x: expr")
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Test and fix for an issue with braces inside brackets

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89533:ec2d5317659d
Date: 2017-01-12 23:13 +0100
http://bitbucket.org/pypy/pypy/changeset/ec2d5317659d/

Log:Test and fix for an issue with braces inside brackets

diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py
--- a/pypy/objspace/std/newformat.py
+++ b/pypy/objspace/std/newformat.py
@@ -122,6 +122,11 @@
 nested -= 1
 if not nested:
 break
+elif c == "[":
+i += 1
+while i < end and s[i] != "]":
+i += 1
+continue
 i += 1
 if nested:
 raise oefmt(space.w_ValueError, "Unmatched '{'")
@@ -214,7 +219,10 @@
 try:
 w_arg = self.args[index]
 except IndexError:
-raise oefmt(space.w_IndexError, "out of range")
+raise oefmt(space.w_IndexError,
+"out of range: index %d but only %d 
argument%s",
+index, len(self.args),
+"s" if len(self.args) != 1 else "")
 return self._resolve_lookups(w_arg, name, i, end)
 
 @jit.unroll_safe
diff --git a/pypy/objspace/std/test/test_newformat.py 
b/pypy/objspace/std/test/test_newformat.py
--- a/pypy/objspace/std/test/test_newformat.py
+++ b/pypy/objspace/std/test/test_newformat.py
@@ -191,6 +191,11 @@
 assert self.s('{0:\x00<12}').format(3+2.0j) == '(3+2j)' + '\x00' * 6
 assert self.s('{0:\x01<12}').format(3+2.0j) == '(3+2j)' + '\x01' * 6
 
+def test_more_indexing_cases(self):
+assert self.s('x{[3]}y').format(['a', 'b', 'c', 'd', 'e']) == 'xdy'
+assert self.s('x{[[]}y').format({'[': 'a'}) == 'xay'
+assert self.s('x{[{]}y').format({'{': 'a'}) == 'xay'
+
 
 class AppTestUnicodeFormat(BaseStringFormatTests):
 def setup_class(cls):
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: More tests and fixes

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r89534:ce9b5b7a5f2d
Date: 2017-01-12 23:51 +0100
http://bitbucket.org/pypy/pypy/changeset/ce9b5b7a5f2d/

Log:More tests and fixes

diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py
--- a/pypy/objspace/std/newformat.py
+++ b/pypy/objspace/std/newformat.py
@@ -165,6 +165,12 @@
 conversion = None
 i += 1
 return s[start:end_name], conversion, i
+elif c == "[":
+while i + 1 < end and s[i + 1] != "]":
+i += 1
+elif c == "{":
+raise oefmt(self.space.w_ValueError,
+"unexpected '{' in field name")
 i += 1
 return s[start:end], None, end
 
diff --git a/pypy/objspace/std/test/test_newformat.py 
b/pypy/objspace/std/test/test_newformat.py
--- a/pypy/objspace/std/test/test_newformat.py
+++ b/pypy/objspace/std/test/test_newformat.py
@@ -195,6 +195,11 @@
 assert self.s('x{[3]}y').format(['a', 'b', 'c', 'd', 'e']) == 'xdy'
 assert self.s('x{[[]}y').format({'[': 'a'}) == 'xay'
 assert self.s('x{[{]}y').format({'{': 'a'}) == 'xay'
+assert self.s("x{[:]}y").format({":" : "a"}) == "xay"
+assert self.s("x{[!]}y").format({"!" : "a"}) == "xay"
+raises(ValueError, self.s("{a{}b}").format, 42)
+raises(ValueError, self.s("{a{b}").format, 42)
+raises(ValueError, self.s("{[}").format, 42)
 
 
 class AppTestUnicodeFormat(BaseStringFormatTests):
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fix doc

2017-01-12 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r89535:da438adf8c4f
Date: 2017-01-13 00:26 +0100
http://bitbucket.org/pypy/pypy/changeset/da438adf8c4f/

Log:Fix doc

diff --git a/pypy/doc/getting-started-dev.rst b/pypy/doc/getting-started-dev.rst
--- a/pypy/doc/getting-started-dev.rst
+++ b/pypy/doc/getting-started-dev.rst
@@ -336,6 +336,6 @@
that fixes some bugs and is translatable.
 
 *  :source:`pypy/objspace/std` contains the :ref:`Standard object space 
`.  The main file
-   is :source:`pypy/objspace/std/objspace.py`.  For each type, the files 
``xxxtype.py`` and
-   ``xxxobject.py`` contain respectively the definition of the type and its
-   (default) implementation.
+   is :source:`pypy/objspace/std/objspace.py`.  For each type, the file
+   ``xxxobject.py`` contains the implementation for objects of type ``xxx``,
+   as a first approximation.  (Some types have multiple implementations.)
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit