Issue369

Title Coroutine args are quasi in local scope
Priority bug Status resolved
Superseder Nosy List jeremy, kayhayen
Assigned To kayhayen Keywords wrong_execution

Created on 2017-07-02.06:52:49 by jeremy, last changed by kayhayen.

Messages
msg2183 (view) Author: kayhayen Date: 2017-07-19.09:28:19
About to be released
msg2162 (view) Author: jeremy Date: 2017-07-02.11:48:48
Great! Saves me some refactoring. 

Thanks for the fix, looking forward. 

Jeremy Blow
msg2161 (view) Author: kayhayen Date: 2017-07-02.09:13:08
I did reproduce and fix the issue. Expect 
a hotfix tomorrow. Asyncgen were affected 
too.

Thanks for reporting the issue.

Yours
Kay
msg2159 (view) Author: jeremy Date: 2017-07-02.06:52:49
Hi,

This is an odd one, to me at least. Ran in to this with Nuitka==0.5.26 on Python 3.5.2/macOS 10.12.3. To 
demonstrate:

=========================================
import asyncio


def test_non_coro(x):
    print(vars())
    print('test_non_coro', x)


async def test_coro1(x):
    print(vars())
    print('test_coro1', x)


async def test_coro2(x):
    print(vars())
    print('test_coro2', x)
    x += 1


if __name__ == "__main__":
    test_non_coro(0)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(test_coro1(0))
    loop.run_until_complete(test_coro2(0))
    loop.close()
=========================================

Result:
=========================================
$ nuitka scratch.py && ./scratch.exe
{'x': 0}
test_non_coro 0
{}
test_coro1 0
{}
Traceback (most recent call last):
  File "/Users/jeremy/Projects/scratch/scratch.py", line 26, in <module>
    loop.run_until_complete(test_coro2(0))
  File "/Users/jeremy/.pyenv/versions/3.5.2/lib/python3.5/asyncio/base_events.py", line 387, in 
run_until_complete
    return future.result()
  File "/Users/jeremy/.pyenv/versions/3.5.2/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/Users/jeremy/.pyenv/versions/3.5.2/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/Users/jeremy/Projects/scratch/scratch.py", line 16, in test_coro2
    print('test_coro2', x)
UnboundLocalError: local variable 'x' referenced before assignment
=========================================

FYI, on Nuitka==0.5.27rc4:
=========================================
$ nuitka scratch.py && ./scratch.exe
Traceback (most recent call last):
  File "/Users/jeremy/.pyenv/versions/scratch_3.5.2/bin/nuitka", line 207, in <module>
    MainControl.main()
  File "/Users/jeremy/.pyenv/versions/3.5.2/envs/scratch_3.5.2/lib/python3.5/site-
packages/nuitka/MainControl.py", line 762, in main
    main_module = main_module
  File "/Users/jeremy/.pyenv/versions/3.5.2/envs/scratch_3.5.2/lib/python3.5/site-
packages/nuitka/MainControl.py", line 639, in compileTree
    main_module = main_module
  File "/Users/jeremy/.pyenv/versions/3.5.2/envs/scratch_3.5.2/lib/python3.5/site-
packages/nuitka/MainControl.py", line 345, in makeSourceDirectory
    module_name    = module.getFullName(),
  File "/Users/jeremy/.pyenv/versions/3.5.2/envs/scratch_3.5.2/lib/python3.5/site-
packages/nuitka/codegen/CodeGeneration.py", line 413, in prepareModuleCode
    context       = context
  File "/Users/jeremy/.pyenv/versions/3.5.2/envs/scratch_3.5.2/lib/python3.5/site-
packages/nuitka/codegen/CodeGeneration.py", line 299, in generateFunctionBodyCode
    needs_generator_return = function_body.needsGeneratorReturnExit()
  File "/Users/jeremy/.pyenv/versions/3.5.2/envs/scratch_3.5.2/lib/python3.5/site-
packages/nuitka/codegen/CoroutineCodes.py", line 64, in getCoroutineObjectCode
    assert not function_cleanup
AssertionError
=========================================
History
Date User Action Args
2017-07-19 09:28:19kayhayensetstatus: in-progress -> resolved
messages: + msg2183
2017-07-02 11:48:48jeremysetmessages: + msg2162
2017-07-02 09:13:08kayhayensetstatus: unread -> in-progress
assignedto: kayhayen
messages: + msg2161
keyword: + wrong_execution
nosy: + kayhayen
2017-07-02 06:52:49jeremycreate