Inner generator function throws NameError when accessing outer function's arg
patiences opened this issue · comments
def fun(lst):
def gen():
for x in lst:
yield x
return list(gen())
print(fun([1, 2, 3, 4]))
This results in:
test_generator_in_function (tests.structures.test_generator.GeneratorTests) ... java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at python.testdaemon.TestDaemon.main(TestDaemon.java:65)
Caused by: NameError: name 'lst' is not defined
at org.python.types.Module.__getattribute__(Module.java:38)
at python.test.fun$gen.invoke$generator(test.py:3)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.python.types.Generator.__next__(Generator.java:78)
at org.python.types.List.<init>(List.java:71)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.python.types.Type.invoke(Type.java:478)
at python.test.fun(test.py:6)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.python.types.Function.invoke(Function.java:397)
at org.python.types.Function.invoke(Function.java:356)
at python.test.module$import(test.py:8)
at python.test.main(test.py)
... 5 more
FAIL
Hi @patiences , I've tried your test case on the latest master branch, turns out it is passing on my end (as intended after patch #854 was merged). I'm surprised that the smoke test didn't throw Unexpected Success
though, considering that the patch was merged few hours earlier than #898 🤔. Have you merged your local fork with the latest commits?