[Python-checkins] cpython: evaluate lambda keyword-only defaults after positional defaults (#16967 again)

benjamin.peterson python-checkins at python.org
Sun Feb 10 15:48:30 CET 2013


http://hg.python.org/cpython/rev/6917402c6191
changeset:   82135:6917402c6191
user:        Benjamin Peterson <benjamin at python.org>
date:        Sun Feb 10 09:48:22 2013 -0500
summary:
  evaluate lambda keyword-only defaults after positional defaults (#16967 again)

files:
  Lib/importlib/_bootstrap.py     |  4 ++--
  Lib/test/test_keywordonlyarg.py |  4 ++++
  Python/compile.c                |  4 ++--
  Python/importlib.h              |  2 +-
  4 files changed, 9 insertions(+), 5 deletions(-)


diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -396,7 +396,7 @@
                      3210 (added size modulo 2**32 to the pyc header)
     Python 3.3a1  3220 (changed PEP 380 implementation)
     Python 3.3a4  3230 (revert changes to implicit __class__ closure)
-    Python 3.4a1  3240 (evaluate positional default arguments before
+    Python 3.4a1  3250 (evaluate positional default arguments before
                        keyword-only defaults)
 
 MAGIC must change whenever the bytecode emitted by the compiler may no
@@ -404,7 +404,7 @@
 due to the addition of new opcodes).
 
 """
-_RAW_MAGIC_NUMBER = 3240 | ord('\r') << 16 | ord('\n') << 24
+_RAW_MAGIC_NUMBER = 3250 | ord('\r') << 16 | ord('\n') << 24
 _MAGIC_BYTES = bytes(_RAW_MAGIC_NUMBER >> n & 0xff for n in range(0, 25, 8))
 
 _PYCACHE = '__pycache__'
diff --git a/Lib/test/test_keywordonlyarg.py b/Lib/test/test_keywordonlyarg.py
--- a/Lib/test/test_keywordonlyarg.py
+++ b/Lib/test/test_keywordonlyarg.py
@@ -183,6 +183,10 @@
             def f(v=a, x=b, *, y=c, z=d):
                 pass
         self.assertEqual(str(err.exception), "global name 'b' is not defined")
+        with self.assertRaises(NameError) as err:
+            f = lambda v=a, x=b, *, y=c, z=d: None
+        self.assertEqual(str(err.exception), "global name 'b' is not defined")
+
 
 def test_main():
     run_unittest(KeywordOnlyArgTestCase)
diff --git a/Python/compile.c b/Python/compile.c
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1794,14 +1794,14 @@
             return 0;
     }
 
+    if (args->defaults)
+        VISIT_SEQ(c, expr, args->defaults);
     if (args->kwonlyargs) {
         int res = compiler_visit_kwonlydefaults(c, args->kwonlyargs,
                                                 args->kw_defaults);
         if (res < 0) return 0;
         kw_default_count = res;
     }
-    if (args->defaults)
-        VISIT_SEQ(c, expr, args->defaults);
     if (!compiler_enter_scope(c, name, COMPILER_SCOPE_FUNCTION,
                               (void *)e, e->lineno))
         return 0;
diff --git a/Python/importlib.h b/Python/importlib.h
--- a/Python/importlib.h
+++ b/Python/importlib.h
[stripped]

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list