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

@decorator example #1742

Closed
elbaro opened this issue Jul 28, 2021 · 2 comments · Fixed by #1832
Closed

@decorator example #1742

elbaro opened this issue Jul 28, 2021 · 2 comments · Fixed by #1832
Assignees

Comments

@elbaro
Copy link

elbaro commented Jul 28, 2021

@pyo3_module.cls_decorator(1, 2, a=3, b=[4])
class A:
  pass

@pyo3_module.fn_decorator(1, 2, a=3, b=[4])
async def f():
  pass

An example or documentation on how to write a decorator in pyo3 would be great.
It also would be a good example teaching how to wrap a dynamically generated closure into pyfunction.

@mejrs
Copy link
Member

mejrs commented Jul 28, 2021

Absolutely - we should have a chapter on that.

It also would be a good example teaching how to wrap a dynamically generated closure into pyfunction.

You can't really do that at the moment, but you can create a pyclass with a __call__ method, much like how you can (in Python) implement decorators as classes rather than functions.

@mejrs mejrs self-assigned this Jul 28, 2021
@davidhewitt
Copy link
Member

(Regarding the closure -> pyfunction, probably talking about #804. Howver there has been no real research into it.)

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

Successfully merging a pull request may close this issue.

3 participants