nucleic / enaml

Declarative User Interfaces for Python
http://enaml.readthedocs.io/en/latest/
Other
1.54k stars 131 forks source link

bytecode: code should not have more than one of the following flag set #399

Closed frmdstryr closed 4 years ago

frmdstryr commented 4 years ago

When attempting to run the current master + changes from #348 using a project with enaml-web on python 3.7 I'm getting:

Traceback (most recent call last):
  File "main.py", line 41, in <module>
    main()
  File "main.py", line 36, in main
    from omitted import app
  File "/home/user/Clients/omitted/omitted/omitted/app.py", line 25, in <module>
    from omitted.handlers import add_handlers
  File "/home/user/Clients/omitted/omitted/omitted/handlers.py", line 24, in <module>
    from omitted.views.api import (
  File "/home/user/Clients/omitted/omitted/omitted/views/api.py", line 18, in <module>
    from .forecasts import ForecastView
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "/home/user/Workspace/enaml/enaml/core/import_hooks.py", line 151, in exec_module
    code, _ = self.get_code()
  File "/home/user/Workspace/enaml/enaml/core/import_hooks.py", line 412, in get_code
    return self.compile_code()
  File "/home/user/Workspace/enaml/enaml/core/import_hooks.py", line 377, in compile_code
    code = EnamlCompiler.compile(ast, file_info.src_path)
  File "/home/user/Workspace/enaml/enaml/core/enaml_compiler.py", line 179, in compile
    return compiler.visit(node)
  File "/home/user/Workspace/enaml/enaml/core/enaml_ast.py", line 359, in visit
    result = visitor(node, *args, **kwargs)
  File "/home/user/Workspace/enaml/enaml/core/enaml_compiler.py", line 195, in visit_Module
    self.visit(item)
  File "/home/user/Workspace/enaml/enaml/core/enaml_ast.py", line 359, in visit
    result = visitor(node, *args, **kwargs)
  File "/home/user/Workspace/enaml/enaml/core/enaml_compiler.py", line 218, in visit_EnamlDef
    code = EnamlDefCompiler.compile(node, cg.filename)
  File "/home/user/Workspace/enaml/enaml/core/enamldef_compiler.py", line 241, in compile
    return compiler.visit(node)
  File "/home/user/Workspace/enaml/enaml/core/enaml_ast.py", line 359, in visit
    result = visitor(node, *args, **kwargs)
  File "/home/user/Workspace/enaml/enaml/core/enamldef_compiler.py", line 256, in visit_EnamlDef
    node, second_args, index_map, filename
  File "/home/user/Workspace/enaml/enaml/core/enamldef_compiler.py", line 193, in compile
    compiler.visit(node)
  File "/home/user/Workspace/enaml/enaml/core/enaml_ast.py", line 359, in visit
    result = visitor(node, *args, **kwargs)
  File "/home/user/Workspace/enaml/enaml/core/enamldef_compiler.py", line 205, in visit_EnamlDef
    self.visit(item)
  File "/home/user/Workspace/enaml/enaml/core/enaml_ast.py", line 359, in visit
    result = visitor(node, *args, **kwargs)
  File "/home/user/Workspace/enaml/enaml/core/block_compiler.py", line 188, in visit_AsyncFuncDef
    self.visit_FuncDef(node)
  File "/home/user/Workspace/enaml/enaml/core/block_compiler.py", line 184, in visit_FuncDef
    cmn.gen_decl_funcdef(cg, node, index)
  File "/home/user/Workspace/enaml/enaml/core/compiler_common.py", line 857, in gen_decl_funcdef
    _insert_decl_function(cg, node.funcdef)
  File "/home/user/Workspace/enaml/enaml/core/compiler_common.py", line 825, in _insert_decl_function
    run_in_dynamic_scope(inner, global_vars)
  File "/home/user/Workspace/enaml/enaml/core/compiler_common.py", line 487, in run_in_dynamic_scope
    code.update_flags()
  File "/home/user/miniconda3/envs/omitted/lib/python3.7/site-packages/bytecode/bytecode.py", line 79, in update_flags
    self.flags = infer_flags(self, is_async)
  File "/home/user/miniconda3/envs/omitted/lib/python3.7/site-packages/bytecode/flags.py", line 87, in infer_flags
    "%s" % flags)
ValueError: Code should not have more than one of the following flag set : generator, coroutine, iterable coroutine and async generator, got:CompilerFlags.COROUTINE|NOFREE|GENERATOR

I'm guessing it's because it doesn't like using values = list(somedict.values()) in an async fn?

MatthieuDartiailh commented 4 years ago

Could you make a minimal reproducer ? I will try to have a look tomorow night

MatthieuDartiailh commented 4 years ago

If you do not have a minimal reproducer could you share the relevant enaml block for me to investigate ? It may be that the logic to handle flags update in bytecode need some refinement but having an example to work with would make figuring out the issue much easier.

frmdstryr commented 4 years ago

Sorry, don't have much time to look into this, just reverted for now. It's a client's code so it can't be shared.

It's like 800 loc with multiple enamldefs and multiple async fn's... There's a few places where it's doing item = next(iter(a_set)), there's also an async with block so maybe one of those is causing it.

I could probably reduce it if the error had the line where it fails or some hints as to what to look for.

MatthieuDartiailh commented 4 years ago

Looking at the traceback I would look for an async function which contains a yield or yield from statement and some other asynchronous construct. I will try to also have a look on my side. I never used async func in enaml so I am have missed something either in enaml or in how bytecode do flag inference.

frmdstryr commented 4 years ago

Well there's 10 async fn's that are doing db queries so that doesn't reduce the scope much :slightly_frowning_face:

It's using aiomysql (Edit via atom-db). If it works with that I'd have to do more digging to see what else it could be from.

MatthieuDartiailh commented 4 years ago

I figured out what is the issue and I need to fix some logic in bytecode. I had no time to finish tonight but I will try to do it ASAP and publish a bugfix release of bytecode. In the meantime if you can propose some additional tests for enaml (typically any async func with an await will trigger the bug) that would be great.

MatthieuDartiailh commented 4 years ago

The fix for the issue is in https://github.com/vstinner/bytecode/pull/56 I will try to merge and release over the weekend and bump enaml dependency.

MatthieuDartiailh commented 4 years ago

The current master now requires the most recent version of bytecode in which the issue causing this has been fixed. Please close when you can confirm.

frmdstryr commented 4 years ago

Working with the latest bytecode, thanks!!