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

Skip to content

Commit 419d9a8

Browse files
committed
evaluate lambda keyword-only defaults after positional defaults (#16967 again)
1 parent 8b466c9 commit 419d9a8

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,15 @@ def _call_with_frames_removed(f, *args, **kwds):
396396
3210 (added size modulo 2**32 to the pyc header)
397397
Python 3.3a1 3220 (changed PEP 380 implementation)
398398
Python 3.3a4 3230 (revert changes to implicit __class__ closure)
399-
Python 3.4a1 3240 (evaluate positional default arguments before
399+
Python 3.4a1 3250 (evaluate positional default arguments before
400400
keyword-only defaults)
401401
402402
MAGIC must change whenever the bytecode emitted by the compiler may no
403403
longer be understood by older implementations of the eval loop (usually
404404
due to the addition of new opcodes).
405405
406406
"""
407-
_RAW_MAGIC_NUMBER = 3240 | ord('\r') << 16 | ord('\n') << 24
407+
_RAW_MAGIC_NUMBER = 3250 | ord('\r') << 16 | ord('\n') << 24
408408
_MAGIC_BYTES = bytes(_RAW_MAGIC_NUMBER >> n & 0xff for n in range(0, 25, 8))
409409

410410
_PYCACHE = '__pycache__'

Lib/test/test_keywordonlyarg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ def test_default_evaluation_order(self):
183183
def f(v=a, x=b, *, y=c, z=d):
184184
pass
185185
self.assertEqual(str(err.exception), "global name 'b' is not defined")
186+
with self.assertRaises(NameError) as err:
187+
f = lambda v=a, x=b, *, y=c, z=d: None
188+
self.assertEqual(str(err.exception), "global name 'b' is not defined")
189+
186190

187191
def test_main():
188192
run_unittest(KeywordOnlyArgTestCase)

Python/compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,14 +1794,14 @@ compiler_lambda(struct compiler *c, expr_ty e)
17941794
return 0;
17951795
}
17961796

1797+
if (args->defaults)
1798+
VISIT_SEQ(c, expr, args->defaults);
17971799
if (args->kwonlyargs) {
17981800
int res = compiler_visit_kwonlydefaults(c, args->kwonlyargs,
17991801
args->kw_defaults);
18001802
if (res < 0) return 0;
18011803
kw_default_count = res;
18021804
}
1803-
if (args->defaults)
1804-
VISIT_SEQ(c, expr, args->defaults);
18051805
if (!compiler_enter_scope(c, name, COMPILER_SCOPE_FUNCTION,
18061806
(void *)e, e->lineno))
18071807
return 0;

Python/importlib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ unsigned char _Py_M__importlib[] = {
756756
114,101,109,111,118,101,100,49,1,0,0,115,2,0,0,0,
757757
0,8,117,25,0,0,0,95,99,97,108,108,95,119,105,116,
758758
104,95,102,114,97,109,101,115,95,114,101,109,111,118,101,100,
759-
105,168,12,0,0,117,1,0,0,0,13,105,16,0,0,0,
759+
105,178,12,0,0,117,1,0,0,0,13,105,16,0,0,0,
760760
117,1,0,0,0,10,105,24,0,0,0,99,1,0,0,0,
761761
0,0,0,0,2,0,0,0,3,0,0,0,99,0,0,0,
762762
115,29,0,0,0,124,0,0,93,19,0,125,1,0,116,0,

0 commit comments

Comments
 (0)