[New-bugs-announce] [issue43947] lambdas stored with assignment expressions are unoptimized
Dan Snider
report at bugs.python.org
Mon Apr 26 22:13:48 EDT 2021
New submission from Dan Snider <mr.assume.away at gmail.com>:
>>> import dis
>>> @dis.dis
... def funcdef(k): return k in {None} ... 2 0 LOAD_FAST 0 (k)
2 LOAD_CONST 1 (frozenset({None})) 4 COMPARE_OP 6 (in) 6 RETURN_VALUE
>>> regass = lambda k: k in {None}
>>> dis.dis(regass)
1 0 LOAD_FAST 0 (k)
2 LOAD_CONST 1 (frozenset({None}))
4 COMPARE_OP 6 (in)
6 RETURN_VALUE >>> dis.dis(walrus:=lambda k: k in {None})
1 0 LOAD_FAST 0 (k)
2 LOAD_CONST 0 (None)
4 BUILD_SET 1
6 COMPARE_OP 6 (in)
8 RETURN_VALUE
As the third example demonstrates, the code for the anonymous function assigned to walrus by an assignment expression isn't receiving the relatively recent frozenset optimization.
----------
messages: 392015
nosy: bup
priority: normal
severity: normal
status: open
title: lambdas stored with assignment expressions are unoptimized
type: performance
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43947>
_______________________________________
More information about the New-bugs-announce
mailing list