]> granicus.if.org Git - python/commitdiff
mangle keyword-only argname when loading defaults (closes #14607)
authorBenjamin Peterson <benjamin@python.org>
Tue, 17 Apr 2012 23:53:21 +0000 (19:53 -0400)
committerBenjamin Peterson <benjamin@python.org>
Tue, 17 Apr 2012 23:53:21 +0000 (19:53 -0400)
Lib/test/test_keywordonlyarg.py
Misc/NEWS
Python/compile.c

index 3aebd68b2a17f22ef2ca413074abab94b390dfc0..108ed18c59f850bee080ecfec339f6dc5a64c4f2 100644 (file)
@@ -170,6 +170,12 @@ class KeywordOnlyArgTestCase(unittest.TestCase):
         # used to fail with a SystemError.
         lambda *, k1=unittest: None
 
+    def test_mangling(self):
+        class X:
+            def f(self, *, __a=42):
+                return __a
+        self.assertEqual(X().f(), 42)
+
 def test_main():
     run_unittest(KeywordOnlyArgTestCase)
 
index adb0b08f224fff30fbb64bd7796c22308efc118c..2c135638b55d554a02a5d75e3952a75372aac728 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.2.4
 Core and Builtins
 -----------------
 
+- Issue #14607: Fix defaults keyword-only arguments which started with ``__``.
+
 - Issue #13889: Check and (if necessary) set FPU control word before calling
   any of the dtoa.c string <-> float conversion functions, on MSVC builds of
   Python.  This fixes issues when embedding Python in a Delphi app.
index ba593a0b99498e6f9b506fdb17e3daa561bff10d..19e7cb2b3f2314861c3e7d089a48e4c662b4ad6b 100644 (file)
@@ -1319,7 +1319,11 @@ compiler_visit_kwonlydefaults(struct compiler *c, asdl_seq *kwonlyargs,
         arg_ty arg = asdl_seq_GET(kwonlyargs, i);
         expr_ty default_ = asdl_seq_GET(kw_defaults, i);
         if (default_) {
-            ADDOP_O(c, LOAD_CONST, arg->arg, consts);
+            PyObject *mangled = _Py_Mangle(c->u->u_private, arg->arg);
+            if (!mangled)
+                return -1;
+            ADDOP_O(c, LOAD_CONST, mangled, consts);
+            Py_DECREF(mangled);
             if (!compiler_visit_expr(c, default_)) {
                 return -1;
             }