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

Support __self__ on asynq'ed methods #102

Closed
besfahbod opened this issue Dec 17, 2020 · 2 comments · Fixed by quora/qcore#70
Closed

Support __self__ on asynq'ed methods #102

besfahbod opened this issue Dec 17, 2020 · 2 comments · Fixed by quora/qcore#70

Comments

@besfahbod
Copy link

Regular PY bound method objects have a __self__ attribute, pointing to the object they are bound to.

Would be great to be able to have the same for asynq()ed methods.

In [36]: class A:
    ...:     def foo():
    ...:         pass
    ...:     @asynq()
    ...:     def bar():
    ...:         pass
    ...:

In [37]: A().foo.__self__.__class__ is A
Out[37]: True

In [38]: A().bar.__self__.__class__ is A

Traceback (most recent call last):
  File "/.../venv/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-38-a140d1d32042>", line 1, in <module>
    A().bar.__self__.__class__ is A
AttributeError: 'asynq.decorators.AsyncDecoratorBinder' object has no attribute '__self__'
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-38-a140d1d32042> in <module>()
----> 1 A().bar.__self__.__class__ is A

AttributeError: 'asynq.decorators.AsyncDecoratorBinder' object has no attribute '__self__'
@JelleZijlstra
Copy link
Collaborator

You can currently already do this with .instance; I agree that it would be more consistent to support __self__ though. I submitted quora/qcore#70 to fix this.

@besfahbod
Copy link
Author

Uh, I didn't find `.instance' when trying things out in ipython. Thanks for both! :)

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

Successfully merging a pull request may close this issue.

2 participants