Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r88011:b0a93780397a
Date: 2016-11-01 10:28 +0100
http://bitbucket.org/pypy/pypy/changeset/b0a93780397a/
Log: Keyword only argument default values were evaluated before other
defaults (CPython issue #16967)
diff --git a/pypy/interpreter/astcompiler/codegen.py
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -376,10 +376,10 @@
self.visit_sequence(func.decorator_list)
args = func.args
assert isinstance(args, ast.arguments)
+ self.visit_sequence(args.defaults)
kw_default_count = 0
if args.kwonlyargs:
kw_default_count = self._visit_kwonlydefaults(args)
- self.visit_sequence(args.defaults)
num_annotations = self._visit_annotations(func, args, func.returns)
num_defaults = len(args.defaults) if args.defaults is not None else 0
oparg = num_defaults
@@ -406,10 +406,10 @@
self.update_position(lam.lineno)
args = lam.args
assert isinstance(args, ast.arguments)
+ self.visit_sequence(args.defaults)
kw_default_count = 0
if args.kwonlyargs:
kw_default_count = self._visit_kwonlydefaults(args)
- self.visit_sequence(args.defaults)
default_count = len(args.defaults) if args.defaults is not None else 0
code, qualname = self.sub_scope(
LambdaCodeGenerator, "<lambda>", lam, lam.lineno)
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -38,7 +38,7 @@
# time you make pyc files incompatible. This value ends up in the frozen
# importlib, via MAGIC_NUMBER in module/_frozen_importlib/__init__.
-pypy_incremental_magic = 80 # bump it by 16
+pypy_incremental_magic = 96 # bump it by 16
assert pypy_incremental_magic % 16 == 0
assert pypy_incremental_magic < 3000 # the magic number of Python 3. There are
# no known magic numbers below this value
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1258,7 +1258,6 @@
w_ann = space.newdict(strdict=True)
for i in range(len(names_w) - 1, -1, -1):
space.setitem(w_ann, names_w[i], self.popvalue())
- defaultarguments = self.popvalues(posdefaults)
kw_defs_w = None
if kwdefaults:
kw_defs_w = []
@@ -1266,7 +1265,9 @@
w_defvalue = self.popvalue()
w_defname = self.popvalue()
kw_defs_w.append((w_defname, w_defvalue))
- fn = function.Function(space, codeobj, self.get_w_globals(),
defaultarguments,
+ defaultarguments = self.popvalues(posdefaults)
+ fn = function.Function(space, codeobj, self.get_w_globals(),
+ defaultarguments,
kw_defs_w, freevars, w_ann, qualname=qualname)
self.pushvalue(space.wrap(fn))
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
@@ -944,6 +944,19 @@
exc = raises(ValueError, compile, mod, 'filename', 'exec')
assert str(exc.value) == "empty targets on Delete"
+ def test_evaluate_argument_definition_order(self): """
+ lst = [1, 2, 3, 4]
+ def f(a=lst.pop(), b=lst.pop(), *, c=lst.pop(), d=lst.pop()):
+ return (a, b, c, d)
+ assert f('a') == ('a', 3, 2, 1), repr(f('a'))
+ assert f() == (4, 3, 2, 1), repr(f())
+ #
+ lst = [1, 2, 3, 4]
+ f = lambda a=lst.pop(), b=lst.pop(), *, c=lst.pop(), d=lst.pop(): (
+ a, b, c, d)
+ assert f('a') == ('a', 3, 2, 1), repr(f('a'))
+ assert f() == (4, 3, 2, 1), repr(f())
+ """
class AppTestOptimizer(object):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit