[pypy-commit] pypy PEP393: hg merge py3.5
rlamy
pypy.commits at gmail.com
Mon Jan 30 11:22:08 EST 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: PEP393
Changeset: r89844:7f5f8c45c219
Date: 2017-01-30 16:21 +0000
http://bitbucket.org/pypy/pypy/changeset/7f5f8c45c219/
Log: hg merge py3.5
diff --git a/pypy/interpreter/astcompiler/symtable.py b/pypy/interpreter/astcompiler/symtable.py
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -547,6 +547,13 @@
for item in list(consider):
item.walkabout(self)
self.pop_scope()
+ # http://bugs.python.org/issue10544: was never fixed in CPython,
+ # but we can at least issue a SyntaxWarning in the meantime
+ if new_scope.is_generator:
+ msg = ("'yield' inside a list or generator comprehension behaves "
+ "unexpectedly (http://bugs.python.org/issue10544)")
+ misc.syntax_warning(self.space, msg, self.compile_info.filename,
+ node.lineno, node.col_offset)
def visit_ListComp(self, listcomp):
self._visit_comprehension(listcomp, listcomp.generators, listcomp.elt)
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
@@ -343,6 +343,7 @@
assert ex.match(self.space, self.space.w_SyntaxError)
def test_globals_warnings(self):
+ # also tests some other constructions that give a warning
space = self.space
w_mod = space.appexec((), '():\n import warnings\n return warnings\n') #sys.getmodule('warnings')
w_filterwarnings = space.getattr(w_mod, space.wrap('filterwarnings'))
@@ -364,6 +365,18 @@
print x
x = 2
global x
+''', '''
+def wrong_listcomp():
+ return [(yield 42) for i in j]
+''', '''
+def wrong_gencomp():
+ return ((yield 42) for i in j)
+''', '''
+def wrong_dictcomp():
+ return {(yield 42):2 for i in j}
+''', '''
+def wrong_setcomp():
+ return {(yield 42) for i in j}
'''):
space.call_args(w_filterwarnings, filter_arg)
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
@@ -486,19 +486,23 @@
return unwrapper
return decorate
+def api_func_from_cdef(func, cdef, cts,
+ error=_NOT_SPECIFIED, header=DEFAULT_HEADER):
+ func._always_inline_ = 'try'
+ cdecl = cts.parse_func(cdef)
+ RESULT = cdecl.get_llresult(cts)
+ api_function = ApiFunction(
+ cdecl.get_llargs(cts), RESULT, func,
+ error=_compute_error(error, RESULT), cdecl=cdecl)
+ FUNCTIONS_BY_HEADER[header][cdecl.name] = api_function
+ unwrapper = api_function.get_unwrapper()
+ unwrapper.func = func
+ unwrapper.api_func = api_function
+ return unwrapper
+
def api_decl(cdef, cts, error=_NOT_SPECIFIED, header=DEFAULT_HEADER):
def decorate(func):
- func._always_inline_ = 'try'
- cdecl = cts.parse_func(cdef)
- RESULT = cdecl.get_llresult(cts)
- api_function = ApiFunction(
- cdecl.get_llargs(cts), RESULT, func,
- error=_compute_error(error, RESULT), cdecl=cdecl)
- FUNCTIONS_BY_HEADER[header][cdecl.name] = api_function
- unwrapper = api_function.get_unwrapper()
- unwrapper.func = func
- unwrapper.api_func = api_function
- return unwrapper
+ return api_func_from_cdef(func, cdef, cts, error=error, header=header)
return decorate
def slot_function(argtypes, restype, error=_NOT_SPECIFIED):
@@ -681,7 +685,17 @@
% (cpyname, ))
build_exported_objects()
-cts = CTypeSpace(headers=['sys/types.h', 'stdarg.h', 'stdio.h', 'stddef.h'])
+
+class CpyextTypeSpace(CTypeSpace):
+ def decl(self, cdef, error=_NOT_SPECIFIED, header=DEFAULT_HEADER):
+ def decorate(func):
+ return api_func_from_cdef(
+ func, cdef, self, error=error, header=header)
+ return decorate
+
+
+CPYEXT_BASE_HEADERS = ['sys/types.h', 'stdarg.h', 'stdio.h', 'stddef.h']
+cts = CpyextTypeSpace(headers=CPYEXT_BASE_HEADERS)
cts.parse_header(parse_dir / 'cpyext_object.h')
Py_ssize_t = cts.gettype('Py_ssize_t')
diff --git a/pypy/module/cpyext/import_.py b/pypy/module/cpyext/import_.py
--- a/pypy/module/cpyext/import_.py
+++ b/pypy/module/cpyext/import_.py
@@ -1,6 +1,5 @@
from pypy.module.cpyext.api import (
- cpython_api, PyObject, CONST_STRING, CANNOT_FAIL,
- cts, api_decl)
+ cpython_api, PyObject, CONST_STRING, CANNOT_FAIL, cts)
from rpython.rtyper.lltypesystem import lltype, rffi
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.module import Module
@@ -51,10 +50,10 @@
return PyImport_Import(space, space.wrap(rffi.charp2str(name)))
- at api_decl(
+ at cts.decl(
'''PyObject* PyImport_ImportModuleLevelObject(
PyObject *name, PyObject *given_globals, PyObject *locals,
- PyObject *given_fromlist, int level)''', cts)
+ PyObject *given_fromlist, int level)''')
def PyImport_ImportModuleLevelObject(space, w_name, w_glob, w_loc, w_fromlist, level):
level = rffi.cast(lltype.Signed, level)
if w_glob is None:
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,7 +11,7 @@
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, cts, api_decl)
+ PyTypeObjectPtr, slot_function, cts)
from pypy.module.cpyext.pyobject import (
Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
@@ -272,7 +272,7 @@
def PyCFunction_NewEx(space, ml, w_self, w_name):
return space.wrap(W_PyCFunctionObject(space, ml, w_self, w_name))
- at api_decl("PyCFunction PyCFunction_GetFunction(PyObject *)", cts)
+ at cts.decl("PyCFunction PyCFunction_GetFunction(PyObject *)")
def PyCFunction_GetFunction(space, w_obj):
try:
cfunction = space.interp_w(W_PyCFunctionObject, w_obj)
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
@@ -1,7 +1,7 @@
from rpython.rtyper.lltypesystem import rffi, lltype
from pypy.module.cpyext.api import (
cpython_api, generic_cpy_call, CANNOT_FAIL, Py_ssize_t, Py_ssize_tP,
- PyVarObject, Py_buffer, size_t, slot_function, api_decl, cts,
+ PyVarObject, Py_buffer, size_t, slot_function, cts,
PyBUF_FORMAT, PyBUF_ND, PyBUF_STRIDES,
Py_TPFLAGS_HEAPTYPE, Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT,
Py_GE, CONST_STRING, CONST_STRINGP, FILEP, fwrite)
@@ -248,7 +248,7 @@
return space.wrap("<NULL>")
return space.str(w_obj)
- at api_decl("PyObject * PyObject_Bytes(PyObject *v)", cts)
+ at cts.decl("PyObject * PyObject_Bytes(PyObject *v)")
def PyObject_Bytes(space, w_obj):
if w_obj is None:
return space.newbytes("<NULL>")
diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -2,7 +2,7 @@
from rpython.rtyper.lltypesystem import rffi, lltype
from pypy.module.unicodedata import unicodedb
from pypy.module.cpyext.api import (
- CANNOT_FAIL, Py_ssize_t, build_type_checkers, cpython_api, api_decl,
+ CANNOT_FAIL, Py_ssize_t, build_type_checkers, cpython_api,
bootstrap_function, CONST_STRING,
CONST_WSTRING, Py_CLEANUP_SUPPORTED, slot_function, cts, parse_dir)
from pypy.module.cpyext.pyerrors import PyErr_BadArgument
@@ -256,7 +256,7 @@
raise oefmt(space.w_TypeError, "expected unicode object")
return PyUnicode_AS_UNICODE(space, rffi.cast(rffi.VOIDP, ref))
- at api_decl("char * PyUnicode_AsUTF8(PyObject *unicode)", cts)
+ at cts.decl("char * PyUnicode_AsUTF8(PyObject *unicode)")
def PyUnicode_AsUTF8(space, ref):
ref_unicode = rffi.cast(PyUnicodeObject, ref)
if not get_utf8(ref_unicode):
More information about the pypy-commit
mailing list