[pypy-commit] pypy py3.5: Fix the exception class we get
Author: Armin Rigo
Branch: py3.5
Changeset: r89411:2cf5804b5f91
Date: 2017-01-08 15:24 +0100
http://bitbucket.org/pypy/pypy/changeset/2cf5804b5f91/
Log:Fix the exception class we get
diff --git a/pypy/module/_warnings/interp_warnings.py
b/pypy/module/_warnings/interp_warnings.py
--- a/pypy/module/_warnings/interp_warnings.py
+++ b/pypy/module/_warnings/interp_warnings.py
@@ -69,12 +69,12 @@
# Validate category
try:
if not space.abstract_issubclass_w(w_category, space.w_Warning):
-raise oefmt(space.w_ValueError,
+raise oefmt(space.w_TypeError,
"category is not a subclass of Warning")
except OperationError as e:
if e.async(space):
raise
-raise oefmt(space.w_ValueError,
+raise oefmt(space.w_TypeError,
"category must be a Warning subclass, not '%T'",
w_category)
diff --git a/pypy/module/_warnings/test/test_warnings.py
b/pypy/module/_warnings/test/test_warnings.py
--- a/pypy/module/_warnings/test/test_warnings.py
+++ b/pypy/module/_warnings/test/test_warnings.py
@@ -80,3 +80,10 @@
_warnings.warn('test', UserWarning)
globals()['__file__'] = None
_warnings.warn('test', UserWarning)
+
+def test_bad_category(self):
+import _warnings
+raises(TypeError, _warnings.warn, "text", 123)
+class Foo:
+pass
+raises(TypeError, _warnings.warn, "text", Foo)
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Add an XXX about .decode('utf-8') in RPython
Author: Armin Rigo
Branch:
Changeset: r89412:b144076bf8d4
Date: 2017-01-08 15:54 +0100
http://bitbucket.org/pypy/pypy/changeset/b144076bf8d4/
Log:Add an XXX about .decode('utf-8') in RPython
diff --git a/rpython/rtyper/rstr.py b/rpython/rtyper/rstr.py
--- a/rpython/rtyper/rstr.py
+++ b/rpython/rtyper/rstr.py
@@ -33,6 +33,10 @@
value, len(value), 'strict', final=True,
errorhandler=self.ll_raise_unicode_exception_decode,
allow_surrogates=False, result=result)
+# XXX should it really be 'allow_surrogates=False'? In RPython,
+# unicode.decode('utf-8') happily accepts surrogates. This
+# makes it hard to test untranslated (it's the cause of a
+# failure in lib-python's test_warnings on PyPy3, for example)
return self.ll.llunicode(result.build())
@staticmethod
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Trying it out in this order: PYTHONWARNINGS should have lower priority than explicit -W options
Author: Armin Rigo
Branch: py3.5
Changeset: r89413:62f33b906529
Date: 2017-01-08 15:56 +0100
http://bitbucket.org/pypy/pypy/changeset/62f33b906529/
Log:Trying it out in this order: PYTHONWARNINGS should have lower
priority than explicit -W options
diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -586,7 +586,7 @@
pythonwarnings = readenv and os.getenv('PYTHONWARNINGS')
if pythonwarnings:
-warnoptions.extend(pythonwarnings.split(','))
+warnoptions = pythonwarnings.split(',') + warnoptions
if warnoptions:
sys.warnoptions[:] = warnoptions
from warnings import _processoptions
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Fix the check for "is a built-in function"
Author: Armin Rigo Branch: py3.5 Changeset: r89414:6f5a8cd7e3b2 Date: 2017-01-08 15:59 +0100 http://bitbucket.org/pypy/pypy/changeset/6f5a8cd7e3b2/ Log:Fix the check for "is a built-in function" diff --git a/lib-python/3/test/test_warnings/__init__.py b/lib-python/3/test/test_warnings/__init__.py --- a/lib-python/3/test/test_warnings/__init__.py +++ b/lib-python/3/test/test_warnings/__init__.py @@ -561,8 +561,9 @@ # As an early adopter, we sanity check the # test.support.import_fresh_module utility function def test_accelerated(self): +import types self.assertFalse(original_warnings is self.module) -self.assertFalse(hasattr(self.module.warn, '__code__')) +self.assertIs(type(self.module.warn), types.BuiltinFunctionType) class PyWarnTests(WarnTests, unittest.TestCase): module = py_warnings @@ -570,8 +571,9 @@ # As an early adopter, we sanity check the # test.support.import_fresh_module utility function def test_pure_python(self): +import types self.assertFalse(original_warnings is self.module) -self.assertTrue(hasattr(self.module.warn, '__code__')) +self.assertIs(type(self.module.warn), types.FunctionType) class WCmdLineTests(BaseTest): ___ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: missing gc.collect()
Author: Armin Rigo
Branch: py3.5
Changeset: r89415:4c3fa9a270fd
Date: 2017-01-08 16:01 +0100
http://bitbucket.org/pypy/pypy/changeset/4c3fa9a270fd/
Log:missing gc.collect()
diff --git a/lib-python/3/test/test_warnings/__init__.py
b/lib-python/3/test/test_warnings/__init__.py
--- a/lib-python/3/test/test_warnings/__init__.py
+++ b/lib-python/3/test/test_warnings/__init__.py
@@ -1003,12 +1003,11 @@
def __del__(self):
warn("test")
-a=A()
+A()
+import gc; gc.collect()
"""
rc, out, err = assert_python_ok("-c", code)
-# note: "__main__" filename is not correct, it should be the name
-# of the script
-self.assertEqual(err, b'__main__:7: UserWarning: test')
+self.assertEqual(err, b'-c:7: UserWarning: test')
def test_late_resource_warning(self):
# Issue #21925: Emitting a ResourceWarning late during the Python
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: this test is really CPython-only
Author: Armin Rigo
Branch: py3.5
Changeset: r89416:52da0cf18848
Date: 2017-01-08 16:03 +0100
http://bitbucket.org/pypy/pypy/changeset/52da0cf18848/
Log:this test is really CPython-only
diff --git a/lib-python/3/test/test_warnings/__init__.py
b/lib-python/3/test/test_warnings/__init__.py
--- a/lib-python/3/test/test_warnings/__init__.py
+++ b/lib-python/3/test/test_warnings/__init__.py
@@ -1009,6 +1009,7 @@
rc, out, err = assert_python_ok("-c", code)
self.assertEqual(err, b'-c:7: UserWarning: test')
[email protected]_only
def test_late_resource_warning(self):
# Issue #21925: Emitting a ResourceWarning late during the Python
# shutdown must be logged.
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Issue #17032: The "global" in the "NameError: global name 'x' is not defined"
Author: Armin Rigo Branch: py3.5 Changeset: r89417:cbb0db3f773d Date: 2017-01-08 16:19 +0100 http://bitbucket.org/pypy/pypy/changeset/cbb0db3f773d/ Log:Issue #17032: The "global" in the "NameError: global name 'x' is not defined" error message has been removed. diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -923,8 +923,10 @@ @dont_inline def _load_global_failed(self, w_varname): +# CPython Issue #17032: The "global" in the "NameError: global +# name 'x' is not defined" error message has been removed. raise oefmt(self.space.w_NameError, -"global name %R is not defined", w_varname) +"name %R is not defined", w_varname) @always_inline def LOAD_GLOBAL(self, nameindex, next_instr): ___ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: list.insert() in RPython should not force the list in the JIT, at least
Author: Armin Rigo Branch: Changeset: r89418:9c99515a58a3 Date: 2017-01-08 16:29 +0100 http://bitbucket.org/pypy/pypy/changeset/9c99515a58a3/ Log:list.insert() in RPython should not force the list in the JIT, at least if the index is constant diff --git a/rpython/jit/codewriter/support.py b/rpython/jit/codewriter/support.py --- a/rpython/jit/codewriter/support.py +++ b/rpython/jit/codewriter/support.py @@ -210,7 +210,6 @@ return rlist.ll_pop(rlist.dum_checkidx, l, index) _ll_2_list_append = rlist.ll_append _ll_2_list_extend = rlist.ll_extend -_ll_3_list_insert = rlist.ll_insert_nonneg _ll_2_list_delslice_startonly = rlist.ll_listdelslice_startonly _ll_3_list_delslice_startstop = rlist.ll_listdelslice_startstop _ll_2_list_inplace_mul = rlist.ll_inplace_mul diff --git a/rpython/jit/metainterp/test/test_list.py b/rpython/jit/metainterp/test/test_list.py --- a/rpython/jit/metainterp/test/test_list.py +++ b/rpython/jit/metainterp/test/test_list.py @@ -212,6 +212,8 @@ s += lst[0] lst.pop() lst.append(1) +lst.insert(0, 5) +lst.insert(1, 6) s *= lst.pop() return s res = self.meta_interp(f, [15], listops=True) diff --git a/rpython/rtyper/rlist.py b/rpython/rtyper/rlist.py --- a/rpython/rtyper/rlist.py +++ b/rpython/rtyper/rlist.py @@ -588,6 +588,7 @@ l.ll_setitem_fast(length, newitem) # this one is for the special case of insert(0, x) [email protected]_inside_iff(lambda l,n: jit.isvirtual(l)) def ll_prepend(l, newitem): length = l.ll_length() l._ll_resize_ge(length+1) # see "a note about overflows" above @@ -597,7 +598,6 @@ l.ll_setitem_fast(dst, l.ll_getitem_fast(src)) dst = src l.ll_setitem_fast(0, newitem) -ll_prepend.oopspec = 'list.insert(l, 0, newitem)' def ll_concat(RESLIST, l1, l2): len1 = l1.ll_length() @@ -612,6 +612,7 @@ return l # no oopspec -- the function is inlined by the JIT [email protected]_inside_iff(lambda l,i,n: jit.isvirtual(l) and jit.isconstant(i)) def ll_insert_nonneg(l, index, newitem): length = l.ll_length() ll_assert(0 <= index, "negative list insertion index") @@ -623,7 +624,6 @@ l.ll_setitem_fast(dst, l.ll_getitem_fast(src)) dst = src l.ll_setitem_fast(index, newitem) -ll_insert_nonneg.oopspec = 'list.insert(l, index, newitem)' def ll_pop_nonneg(func, l, index): ll_assert(index >= 0, "unexpectedly negative list pop index") ___ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: fix
Author: Armin Rigo
Branch: py3.5
Changeset: r89419:de42c521f47a
Date: 2017-01-08 16:45 +0100
http://bitbucket.org/pypy/pypy/changeset/de42c521f47a/
Log:fix
diff --git a/pypy/module/sys/test/test_sysmodule.py
b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -32,7 +32,7 @@
w_sys.flush_std_files(space)
msg = space.bytes_w(space.call_function(w_read))
-assert 'Exception OSError' in msg
+assert 'Exception ignored in:' in msg and '\nOSError' in msg
finally:
space.setattr(w_sys, space.wrap('stdout'), w_sys.get('__stdout__'))
space.setattr(w_sys, space.wrap('stderr'), w_sys.get('__stderr__'))
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Pass test_invalid_context
Author: Armin Rigo Branch: py3.5 Changeset: r89421:feb960899f2a Date: 2017-01-08 16:59 +0100 http://bitbucket.org/pypy/pypy/changeset/feb960899f2a/ Log:Pass test_invalid_context diff --git a/lib_pypy/_decimal.py b/lib_pypy/_decimal.py --- a/lib_pypy/_decimal.py +++ b/lib_pypy/_decimal.py @@ -1086,26 +1086,30 @@ if traps is None: ctx.traps = dc.traps -elif not isinstance(traps, dict): +elif isinstance(traps, list): ctx.traps = 0 for signal in traps: ctx.traps |= _SIGNALS[signal] -else: +elif isinstance(traps, dict): ctx.traps = 0 for signal, value in traps.items(): if value: ctx.traps |= _SIGNALS[signal] +else: +self.traps = traps if flags is None: ctx.status = 0 -elif not isinstance(flags, dict): +elif isinstance(flags, list): ctx.status = 0 for signal in flags: ctx.status |= _SIGNALS[signal] -else: +elif isinstance(flags, dict): for signal, value in flags.items(): if value: ctx.status |= _SIGNALS[signal] +else: +self.flags = flags def clear_flags(self): self._ctx.status = 0 ___ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: add an extra test
Author: Armin Rigo Branch: py3.5 Changeset: r89420:ea5c8eea66d5 Date: 2017-01-08 16:55 +0100 http://bitbucket.org/pypy/pypy/changeset/ea5c8eea66d5/ Log:add an extra test diff --git a/lib-python/3/test/test_decimal.py b/lib-python/3/test/test_decimal.py --- a/lib-python/3/test/test_decimal.py +++ b/lib-python/3/test/test_decimal.py @@ -4039,6 +4039,11 @@ self.assertRaises(TypeError, Context, flags=(0,1)) self.assertRaises(TypeError, Context, traps=(1,0)) +def test_context_from_signaldict(self): +ctx = self.decimal.Context() +ctx2 = self.decimal.Context(flags=ctx.flags) +assert ctx.flags == ctx2.flags + class CContextInputValidation(ContextInputValidation): decimal = C class PyContextInputValidation(ContextInputValidation): ___ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Generalize the test to accept both ValueError and OverflowError for some cases
Author: Armin Rigo
Branch: py3.5
Changeset: r89422:5169bbf58c6c
Date: 2017-01-08 17:05 +0100
http://bitbucket.org/pypy/pypy/changeset/5169bbf58c6c/
Log:Generalize the test to accept both ValueError and OverflowError for
some cases
diff --git a/lib-python/3/test/test_decimal.py
b/lib-python/3/test/test_decimal.py
--- a/lib-python/3/test/test_decimal.py
+++ b/lib-python/3/test/test_decimal.py
@@ -4808,15 +4808,24 @@
self.assertRaises(OverflowError, Context, Emax=int_max+1)
self.assertRaises(OverflowError, Context, Emin=-int_max-2)
self.assertRaises(OverflowError, Context, clamp=int_max+1)
-self.assertRaises(OverflowError, Context, capitals=int_max+1)
+self.assertRaises((OverflowError, ValueError),
+ Context, capitals=int_max+1)
# OverflowError, general ValueError
for attr in ('prec', 'Emin', 'Emax', 'capitals', 'clamp'):
-self.assertRaises(OverflowError, setattr, c, attr, int_max+1)
-self.assertRaises(OverflowError, setattr, c, attr, -int_max-2)
+if attr == 'capitals':
+err = (OverflowError, ValueError)
+else:
+err = OverflowError
+self.assertRaises(err, setattr, c, attr, int_max+1)
+self.assertRaises(err, setattr, c, attr, -int_max-2)
if sys.platform != 'win32':
-self.assertRaises(ValueError, setattr, c, attr, int_max)
-self.assertRaises(ValueError, setattr, c, attr, -int_max-1)
+if attr == 'clamp':
+err = (ValueError, OverflowError)
+else:
+err = ValueError
+self.assertRaises(err, setattr, c, attr, int_max)
+self.assertRaises(err, setattr, c, attr, -int_max-1)
# OverflowError: _unsafe_setprec, _unsafe_setemin, _unsafe_setemax
if C.MAX_PREC == 42500:
@@ -4845,8 +4854,9 @@
self.assertRaises(ValueError, setattr, c, attr, 2)
self.assertRaises(TypeError, setattr, c, attr, [1,2,3])
if HAVE_CONFIG_64:
-self.assertRaises(ValueError, setattr, c, attr, 2**32)
-self.assertRaises(ValueError, setattr, c, attr, 2**32+1)
+err = (ValueError, OverflowError)
+self.assertRaises(err, setattr, c, attr, 2**32)
+self.assertRaises(err, setattr, c, attr, 2**32+1)
# Invalid local context
self.assertRaises(TypeError, exec, 'with localcontext("xyz"): pass',
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Fix for test_inspect_module
Author: Armin Rigo
Branch: py3.5
Changeset: r89424:acb109bf07ca
Date: 2017-01-08 17:11 +0100
http://bitbucket.org/pypy/pypy/changeset/acb109bf07ca/
Log:Fix for test_inspect_module
diff --git a/lib_pypy/_decimal.py b/lib_pypy/_decimal.py
--- a/lib_pypy/_decimal.py
+++ b/lib_pypy/_decimal.py
@@ -102,9 +102,10 @@
# Default context
import threading
-local = threading.local()
+__local = threading.local()
+del threading
-def getcontext(*, _local=local):
+def getcontext():
"""Returns this thread's context.
If this thread does not yet have a context, returns
@@ -112,10 +113,10 @@
New contexts are copies of DefaultContext.
"""
try:
-return _local.__decimal_context__
+return __local.__decimal_context__
except AttributeError:
context = Context()
-_local.__decimal_context__ = context
+__local.__decimal_context__ = context
return context
def _getcontext(context=None):
@@ -125,17 +126,14 @@
raise TypeError
return context
-def setcontext(context, *, _local=local):
+def setcontext(context):
"""Set this thread's context to context."""
if context in (DefaultContext, BasicContext, ExtendedContext):
context = context.copy()
context.clear_flags()
if not isinstance(context, Context):
raise TypeError
-_local.__decimal_context__ = context
-
-
-del local, threading
+__local.__decimal_context__ = context
def localcontext(ctx=None):
"""Return a context manager for a copy of the supplied context.
@@ -1042,7 +1040,9 @@
__slots__ = ('_ctx', '_capitals')
-def __new__(cls, *args, **kwargs):
+def __new__(cls, prec=None, rounding=None, Emin=None, Emax=None,
+capitals=None, clamp=None, flags=None, traps=None):
+# NOTE: the arguments are ignored here, they are used in __init__()
self = object.__new__(cls)
self._ctx = ctx = _ffi.new("struct mpd_context_t*")
# Default context
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: fix test
Author: Armin Rigo
Branch: py3.5
Changeset: r89423:2e6e0d9eba8a
Date: 2017-01-08 17:06 +0100
http://bitbucket.org/pypy/pypy/changeset/2e6e0d9eba8a/
Log:fix test
diff --git a/lib-python/3/test/test_decimal.py
b/lib-python/3/test/test_decimal.py
--- a/lib-python/3/test/test_decimal.py
+++ b/lib-python/3/test/test_decimal.py
@@ -4185,7 +4185,9 @@
x = [s for s in dir(C.Context()) if '__' in s or not s.startswith('_')]
y = [s for s in dir(P.Context()) if '__' in s or not s.startswith('_')]
-self.assertEqual(set(x) - set(y), set())
+extra = set(x) - set(y)
+extra.discard('__slots__')
+self.assertEqual(extra, set())
def test_decimal_attributes(self):
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Rename argument, as per test_inspect_types
Author: Armin Rigo Branch: py3.5 Changeset: r89426:eed5601c6e65 Date: 2017-01-08 17:29 +0100 http://bitbucket.org/pypy/pypy/changeset/eed5601c6e65/ Log:Rename argument, as per test_inspect_types diff --git a/lib_pypy/_decimal.py b/lib_pypy/_decimal.py --- a/lib_pypy/_decimal.py +++ b/lib_pypy/_decimal.py @@ -1260,8 +1260,8 @@ def create_decimal(self, num="0"): return Decimal._from_object(num, self, exact=False) -def create_decimal_from_float(self, value): -return Decimal._from_float(value, self, exact=False) +def create_decimal_from_float(self, f): +return Decimal._from_float(f, self, exact=False) # operations def _convert_unaryop(self, a, *, strict=True): ___ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Fix test_inspect_types (shows real failures now)
Author: Armin Rigo
Branch: py3.5
Changeset: r89425:b7c079c171ab
Date: 2017-01-08 17:27 +0100
http://bitbucket.org/pypy/pypy/changeset/b7c079c171ab/
Log:Fix test_inspect_types (shows real failures now)
diff --git a/lib-python/3/test/test_decimal.py
b/lib-python/3/test/test_decimal.py
--- a/lib-python/3/test/test_decimal.py
+++ b/lib-python/3/test/test_decimal.py
@@ -35,7 +35,7 @@
from test.support import (run_unittest, run_doctest, is_resource_enabled,
requires_IEEE_754, requires_docstrings)
from test.support import (check_warnings, import_fresh_module, TestFailed,
- run_with_locale, cpython_only)
+ run_with_locale, cpython_only, check_impl_detail)
import random
import time
import warnings
@@ -5452,6 +5452,7 @@
POS = inspect._ParameterKind.POSITIONAL_ONLY
POS_KWD = inspect._ParameterKind.POSITIONAL_OR_KEYWORD
+KWONLY = inspect._ParameterKind.KEYWORD_ONLY
# Type heuristic (type annotations would help!):
pdict = {C: {'other': C.Decimal(1),
@@ -5489,6 +5490,8 @@
args.append(pdict[module][name])
elif param.kind == POS_KWD:
kwargs[name] = pdict[module][name]
+elif param.kind == KWONLY:
+pass
else:
raise TestFailed("unexpected parameter kind")
return args, kwargs
@@ -5517,15 +5520,26 @@
p_names = list(p_sig.parameters.keys())
c_names = [tr(x) for x in c_sig.parameters.keys()]
+p_kind = [x.kind for x in p_sig.parameters.values()]
+c_kind = [x.kind for x in c_sig.parameters.values()]
+
+if check_impl_detail(pypy=True):
+# PyPy only: _decimal.py has some methods with
+# an extra keyword-only argument 'strict', which
+# we ignore here
+if c_names[-1:] == ['strict'] and c_kind[-1] == KWONLY:
+del c_names[-1]
+del c_kind[-1]
+
self.assertEqual(c_names, p_names,
msg="parameter name mismatch in %s" %
p_func)
-p_kind = [x.kind for x in p_sig.parameters.values()]
-c_kind = [x.kind for x in c_sig.parameters.values()]
-
# 'self' parameter:
self.assertIs(p_kind[0], POS_KWD)
-self.assertIs(c_kind[0], POS)
+if check_impl_detail(cpython=True):
+self.assertIs(c_kind[0], POS)
+else:
+self.assertIs(c_kind[0], POS_KWD)
# remaining parameters:
if ty == 'Decimal':
diff --git a/lib_pypy/_decimal.py b/lib_pypy/_decimal.py
--- a/lib_pypy/_decimal.py
+++ b/lib_pypy/_decimal.py
@@ -1264,7 +1264,7 @@
return Decimal._from_float(value, self, exact=False)
# operations
-def _convert_unaryop(self, a, strict=True):
+def _convert_unaryop(self, a, *, strict=True):
if isinstance(a, Decimal):
return a
elif isinstance(a, int):
@@ -1274,7 +1274,7 @@
else:
return NotImplemented
-def _convert_binop(self, a, b, strict=True):
+def _convert_binop(self, a, b, *, strict=True):
a = self._convert_unaryop(a, strict=strict)
b = self._convert_unaryop(b, strict=strict)
if b is NotImplemented:
@@ -1441,7 +1441,7 @@
_mpdec.mpd_qfinalize(result._mpd, ctx, status_ptr)
return result
-def divmod(self, a, b, strict=True):
+def divmod(self, a, b, *, strict=True):
a, b = self._convert_binop(a, b, strict=strict)
if a is NotImplemented:
return NotImplemented
@@ -1452,7 +1452,7 @@
ctx, status_ptr)
return q, r
-def power(self, a, b, modulo=None, strict=True):
+def power(self, a, b, modulo=None, *, strict=True):
a, b = self._convert_binop(a, b, strict=strict)
if a is NotImplemented:
return NotImplemented
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Add _testcapi.raise_signal(). Hack to have it (and awaitType) correctly
Author: Armin Rigo Branch: py3.5 Changeset: r89428:69efed9f9864 Date: 2017-01-08 17:57 +0100 http://bitbucket.org/pypy/pypy/changeset/69efed9f9864/ Log:Add _testcapi.raise_signal(). Hack to have it (and awaitType) correctly present even if cpyext is enabled. diff --git a/lib_pypy/_testcapi.py b/lib_pypy/_testcapi.py --- a/lib_pypy/_testcapi.py +++ b/lib_pypy/_testcapi.py @@ -25,3 +25,14 @@ self._iterator = iterator def __await__(self): return self._iterator + +def raise_signal(signum): +import _signal, _thread +_signal.pthread_kill(_thread.get_ident(), signum) + + +# the hacks above have replaced this module with another, so we need +# to push the extra names into this other module too... +import _testcapi +_testcapi.awaitType = awaitType +_testcapi.raise_signal = raise_signal ___ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Complain in signal.set_wakeup_fd() if the fd is blocking
Author: Armin Rigo Branch: py3.5 Changeset: r89427:3da675aed49d Date: 2017-01-08 17:42 +0100 http://bitbucket.org/pypy/pypy/changeset/3da675aed49d/ Log:Complain in signal.set_wakeup_fd() if the fd is blocking diff --git a/pypy/module/signal/interp_signal.py b/pypy/module/signal/interp_signal.py --- a/pypy/module/signal/interp_signal.py +++ b/pypy/module/signal/interp_signal.py @@ -6,12 +6,12 @@ import errno from pypy.interpreter.error import ( -OperationError, exception_from_saved_errno, oefmt) +OperationError, exception_from_saved_errno, oefmt, wrap_oserror) from pypy.interpreter.executioncontext import (AsyncAction, AbstractActionFlag, PeriodicAsyncAction) from pypy.interpreter.gateway import unwrap_spec -from rpython.rlib import jit, rgc +from rpython.rlib import jit, rgc, rposix, rposix_stat from rpython.rlib.objectmodel import we_are_translated from rpython.rlib.rarithmetic import intmask, widen from rpython.rlib.rsignal import * @@ -241,7 +241,7 @@ @jit.dont_look_inside -@unwrap_spec(fd=int) +@unwrap_spec(fd="c_int") def set_wakeup_fd(space, fd): """Sets the fd to be written to (with the signal number) when a signal comes in. Returns the old fd. A library can use this to @@ -254,11 +254,19 @@ "set_wakeup_fd only works in main thread or with " "__pypy__.thread.enable_signals()") if fd != -1: +if not rposix.is_valid_fd(fd): +raise oefmt(space.w_ValueError, "invalid fd") try: os.fstat(fd) +flags = rposix.get_status_flags(fd) except OSError as e: if e.errno == errno.EBADF: raise oefmt(space.w_ValueError, "invalid fd") +raise wrap_oserror(space, e, eintr_retry=False) +if flags & rposix.O_NONBLOCK == 0: +raise oefmt(space.w_ValueError, +"the fd %d must be in non-blocking mode", fd) + old_fd = pypysig_set_wakeup_fd(fd, False) return space.wrap(intmask(old_fd)) ___ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: TypeError => OverflowError
Author: Armin Rigo Branch: py3.5 Changeset: r89429:ddb87455245b Date: 2017-01-08 21:13 +0100 http://bitbucket.org/pypy/pypy/changeset/ddb87455245b/ Log:TypeError => OverflowError diff --git a/pypy/module/pyexpat/interp_pyexpat.py b/pypy/module/pyexpat/interp_pyexpat.py --- a/pypy/module/pyexpat/interp_pyexpat.py +++ b/pypy/module/pyexpat/interp_pyexpat.py @@ -741,7 +741,7 @@ def get_buffer_size(self, space): return space.wrap(self.buffer_size) def set_buffer_size(self, space, w_value): -value = space.getindex_w(w_value, space.w_TypeError) +value = space.getindex_w(w_value, space.w_OverflowError) if value <= 0: raise oefmt(space.w_ValueError, "buffer_size must be greater than zero") diff --git a/pypy/module/pyexpat/test/test_parser.py b/pypy/module/pyexpat/test/test_parser.py --- a/pypy/module/pyexpat/test/test_parser.py +++ b/pypy/module/pyexpat/test/test_parser.py @@ -89,7 +89,7 @@ p = pyexpat.ParserCreate() p.buffer_size = 150 assert p.buffer_size == 150 -raises((ValueError, TypeError), +raises(OverflowError, setattr, p, 'buffer_size', sys.maxsize + 1) def test_encoding_xml(self): ___ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Fix a division by zero
Author: Armin Rigo
Branch: py3.5
Changeset: r89430:f2d9207e657b
Date: 2017-01-08 21:21 +0100
http://bitbucket.org/pypy/pypy/changeset/f2d9207e657b/
Log:Fix a division by zero
diff --git a/pypy/module/struct/interp_struct.py
b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -107,6 +107,10 @@
class W_UnpackIter(W_Root):
def __init__(self, space, w_struct, w_buffer):
buf = space.buffer_w(w_buffer, space.BUF_SIMPLE)
+if w_struct.size <= 0:
+raise oefmt(get_error(space),
+"cannot iteratively unpack with a struct of length %d",
+w_struct.size)
if buf.getlength() % w_struct.size != 0:
raise oefmt(get_error(space),
"iterative unpacking requires a bytes length multiple of %d",
diff --git a/pypy/module/struct/test/test_struct.py
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -423,6 +423,12 @@
raises(struct.error, s.iter_unpack, b'123')
raises(struct.error, struct.iter_unpack, 'h', b'12345')
+def test_iter_unpack_empty_struct(self):
+struct = self.struct
+s = struct.Struct('')
+raises(struct.error, s.iter_unpack, b'')
+raises(struct.error, s.iter_unpack, b'?')
+
def test___float__(self):
class MyFloat(object):
def __init__(self, x):
___
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Skip tests that are really about subinterpreters
Author: Armin Rigo Branch: py3.5 Changeset: r89431:ce8c2c3d808f Date: 2017-01-08 21:24 +0100 http://bitbucket.org/pypy/pypy/changeset/ce8c2c3d808f/ Log:Skip tests that are really about subinterpreters diff --git a/lib-python/3/test/test_threading.py b/lib-python/3/test/test_threading.py --- a/lib-python/3/test/test_threading.py +++ b/lib-python/3/test/test_threading.py @@ -836,6 +836,7 @@ class SubinterpThreadingTests(BaseTestCase): +@cpython_only def test_threads_join(self): # Non-daemon threads should be joined at subinterpreter shutdown # (issue #18808) @@ -859,6 +860,7 @@ # The thread was joined properly. self.assertEqual(os.read(r, 1), b"x") +@cpython_only def test_threads_join_2(self): # Same as above, but a delay gets introduced after the thread's # Python code returned but before the thread state is deleted. ___ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy api_func-refactor: Move C code generation code to methods of ApiFunction
Author: Ronan Lamy
Branch: api_func-refactor
Changeset: r89432:deeb13497468
Date: 2017-01-09 01:12 +
http://bitbucket.org/pypy/pypy/changeset/deeb13497468/
Log:Move C code generation code to methods of ApiFunction
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
@@ -329,6 +329,47 @@
wrapper.c_name = cpyext_namespace.uniquename(self.c_name)
return wrapper
+def get_c_restype(self, c_writer):
+return c_writer.gettype(self.restype).replace('@', '').strip()
+
+def get_c_args(self, c_writer):
+args = []
+for i, argtype in enumerate(self.argtypes):
+if argtype is CONST_STRING:
+arg = 'const char *@'
+elif argtype is CONST_STRINGP:
+arg = 'const char **@'
+elif argtype is CONST_WSTRING:
+arg = 'const wchar_t *@'
+else:
+arg = c_writer.gettype(argtype)
+arg = arg.replace('@', 'arg%d' % (i,)).strip()
+args.append(arg)
+args = ', '.join(args) or "void"
+return args
+
+def get_api_decl(self, name, c_writer):
+restype = self.get_c_restype(c_writer)
+args = self.get_c_args(c_writer)
+return "PyAPI_FUNC({restype}) {name}({args});".format(**locals())
+
+def get_ptr_decl(self, name, c_writer):
+restype = self.get_c_restype(c_writer)
+args = self.get_c_args(c_writer)
+return "{restype} (*{name})({args});".format(**locals())
+
+def get_ctypes_impl(self, name, c_writer):
+restype = self.get_c_restype(c_writer)
+args = self.get_c_args(c_writer)
+callargs = ', '.join('arg%d' % (i,)
+for i in range(len(self.argtypes)))
+if self.restype is lltype.Void:
+body = "{ _pypyAPI.%s(%s); }" % (name, callargs)
+else:
+body = "{ return _pypyAPI.%s(%s); }" % (name, callargs)
+return '%s %s(%s)\n%s' % (restype, name, args, body)
+
+
DEFAULT_HEADER = 'pypy_decl.h'
def cpython_api(argtypes, restype, error=_NOT_SPECIFIED, header=DEFAULT_HEADER,
gil=None, result_borrowed=False, result_is_ll=False):
@@ -987,23 +1028,6 @@
for func in BOOTSTRAP_FUNCTIONS:
func(space)
-def c_function_signature(db, func):
-restype = db.gettype(func.restype).replace('@', '').strip()
-args = []
-for i, argtype in enumerate(func.argtypes):
-if argtype is CONST_STRING:
-arg = 'const char *@'
-elif argtype is CONST_STRINGP:
-arg = 'const char **@'
-elif argtype is CONST_WSTRING:
-arg = 'const wchar_t *@'
-else:
-arg = db.gettype(argtype)
-arg = arg.replace('@', 'arg%d' % (i,)).strip()
-args.append(arg)
-args = ', '.join(args) or "void"
-return restype, args
-
#_
# Build the bridge DLL, Allow extension DLLs to call
# back into Pypy space functions
@@ -1023,15 +1047,8 @@
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
-restype, args = c_function_signature(db, func)
-callargs = ', '.join('arg%d' % (i,)
-for i in range(len(func.argtypes)))
-if func.restype is lltype.Void:
-body = "{ _pypyAPI.%s(%s); }" % (name, callargs)
-else:
-body = "{ return _pypyAPI.%s(%s); }" % (name, callargs)
-functions.append('%s %s(%s)\n%s' % (restype, name, args, body))
-members.append('%s (*%s)(%s);' % (restype, name, args))
+functions.append(func.get_ctypes_impl(name, db))
+members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
@@ -1226,8 +1243,7 @@
for name, func in sorted(header_functions.iteritems()):
_name = mangle_name(prefix, name)
header.append("#define %s %s" % (name, _name))
-restype, args = c_function_signature(db, func)
-header.append("PyAPI_FUNC(%s) %s(%s);" % (restype, name, args))
+header.append(func.get_api_decl(name, db))
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
diff --git a/pypy/module/cpyext/test/test_api.py
b/pypy/module/cpyext/test/test_api.py
--- a/pypy/module/cpyext/test/test_api.py
+++ b/pypy/module/cpyext/test/test_api.py
@@ -89,10 +89,10 @@
def test_typedef(self, space):
from rpython.translator.c.database import LowLevelDatabase
db = LowLevelDatabase()
-assert (api.c_function_signature(db, PyPy_TypedefTest1.api_func)
-== ('Py_ssize_t', 'Py_ssize_t arg0'))
-assert (api.c_function_signature
