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

Cython used with async - Decorators can only be followed by functions or classes #1462

Closed
JendaPlhak opened this issue Sep 16, 2016 · 6 comments

Comments

@JendaPlhak
Copy link

JendaPlhak commented Sep 16, 2016

I'm trying to compile Python 3 code using Cython (version 0.25a0). The code heavily depends on asyncio and works normally when run with latest Python. Compilation however gives me following error:

Error compiling Cython file:
------------------------------------------------------------
...

    @helpers.json_handler(logger = logger)
    async def get_index(req, req_body):
   ^
------------------------------------------------------------

skystore/mem_node.py:40:4: Decorators can only be followed by functions or classes

Does it mean, that async and await keywords are not supported? I thought otherwise because according to changelog it was implemented last year.

@robertwb
Copy link
Contributor

I think this combination simply hasn't been implemented yet. It'd require a bit of plumbing, but hopefully it wouldn't be that hard.

@JendaPlhak
Copy link
Author

I would be happy to help my self, but I never really touched Cython internals so I don't know whether I can be of any use :-/

@scoder scoder closed this as completed in be53f12 Oct 18, 2019
@scoder
Copy link
Contributor

scoder commented Oct 18, 2019

Works for me. I guess async def wasn't actually implemented at the time.

@buckle2000
Copy link

buckle2000 commented May 15, 2020

This is not fully fixed! The following code won't compile.

# a.py
def pass_through(func):
    return func


async def another():
    @pass_through
    async def test_pass_through():
        pass
> cython -3 a.py

Error compiling Cython file:
------------------------------------------------------------
...
    return func


async def another():
    @pass_through
    async def test_pass_through():
   ^
------------------------------------------------------------

a.py:8:4: Decorators can only be followed by functions or classes

@scoder
Copy link
Contributor

scoder commented May 15, 2020

Ah, yeah, thanks for noticing. Turns out, decorators work for the first async def spotted, and that enables async as keyword. Afterwards, async is a keyword and is then no longer recognised in the parser code paths that accept decorators. :)

@scoder scoder reopened this May 15, 2020
@scoder scoder added this to the 0.29.18 milestone May 15, 2020
@scoder scoder added the defect label May 15, 2020
@scoder
Copy link
Contributor

scoder commented May 15, 2020

Actually, I think Cython 3.0 is a good time to generally make async a keyword for good.
Although – why break stuff that works…

@scoder scoder closed this as completed in 3b1b45d May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants