Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
frmdstryr opened this issue Feb 25, 2020 · 9 comments
Closed

Comments

@frmdstryr
Copy link
Contributor

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
Copy link
Member

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

@MatthieuDartiailh MatthieuDartiailh changed the title byteplay: code should not have more than one of the following flag set bytecode: code should not have more than one of the following flag set Feb 25, 2020
@MatthieuDartiailh
Copy link
Member

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
Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Contributor Author

frmdstryr commented Feb 26, 2020

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

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
Copy link
Member

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
Copy link
Member

The fix for the issue is in MatthieuDartiailh/bytecode#56 I will try to merge and release over the weekend and bump enaml dependency.

@MatthieuDartiailh
Copy link
Member

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
Copy link
Contributor Author

Working with the latest bytecode, thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants