[issue29354] Python 2.7.12: pydoc.help(lambda (a, ): lambda x: a) raises IndexError
Emily Morehouse
report at bugs.python.org
Tue Jan 24 01:34:09 EST 2017
Emily Morehouse added the comment:
Yury, thanks for the encouragement to continue on this patch. I think it will be a good exercise to dive a bit deeper into Python's bytecode and put some knowledge to use.
I believe that tuple argument unpacking is handled appropriately, but there is an even further edge case where a closure is introduced. In the following, inspect.getargspec works for the first bit of code, but the second fails, as 'a' is referenced outside of scope.
>>> dis.dis(lambda (a,): lambda x: x)
1 0 LOAD_FAST 0 (.0)
3 UNPACK_SEQUENCE 1
6 STORE_FAST 1 (a)
9 LOAD_CONST 1 (<code object <lambda> at 0x10087a130, file "<stdin>", line 1>)
12 MAKE_FUNCTION 0
15 RETURN_VALUE
>>> dis.dis(lambda (a,): lambda x: a)
1 0 LOAD_FAST 0 (.0)
3 UNPACK_SEQUENCE 1
6 STORE_DEREF 0 (a)
9 LOAD_CLOSURE 0 (a)
12 BUILD_TUPLE 1
15 LOAD_CONST 1 (<code object <lambda> at 0x10087a930, file "<stdin>", line 1>)
18 MAKE_CLOSURE 0
21 RETURN_VALUE
I'll keep poking at this and see where I get.
-- EM
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29354>
_______________________________________
More information about the Python-bugs-list
mailing list