Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a1fdc4

Browse files
committed
merge 3.2 (#14607)
2 parents 64befe9 + 32c59b6 commit 2a1fdc4

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lib/test/test_keywordonlyarg.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ def test_issue13343(self):
170170
# used to fail with a SystemError.
171171
lambda *, k1=unittest: None
172172

173+
def test_mangling(self):
174+
class X:
175+
def f(self, *, __a=42):
176+
return __a
177+
self.assertEqual(X().f(), 42)
178+
173179
def test_main():
174180
run_unittest(KeywordOnlyArgTestCase)
175181

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Core and Builtins
1313
- Issue #14592: Attempting a relative import w/o __package__ or __name__ set in
1414
globals raises a KeyError.
1515

16+
- Issue #14607: Fix defaults keyword-only arguments which started with ``__``.
17+
1618
- Issue #10854: The ImportError raised when an extension module on Windows
1719
fails to import now uses the new path and name attributes from
1820
Issue #1559549.

Python/compile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,11 @@ compiler_visit_kwonlydefaults(struct compiler *c, asdl_seq *kwonlyargs,
14091409
arg_ty arg = asdl_seq_GET(kwonlyargs, i);
14101410
expr_ty default_ = asdl_seq_GET(kw_defaults, i);
14111411
if (default_) {
1412-
ADDOP_O(c, LOAD_CONST, arg->arg, consts);
1412+
PyObject *mangled = _Py_Mangle(c->u->u_private, arg->arg);
1413+
if (!mangled)
1414+
return -1;
1415+
ADDOP_O(c, LOAD_CONST, mangled, consts);
1416+
Py_DECREF(mangled);
14131417
if (!compiler_visit_expr(c, default_)) {
14141418
return -1;
14151419
}

0 commit comments

Comments
 (0)