-
Notifications
You must be signed in to change notification settings - Fork 34
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
use operator
on a class method fails
#23
Comments
Hi @jenda1, thank you for creating this issue. The problem here is that the decorated generator becomes a Instead, you could consider this alternative: @operator
async def stream_from_test_instance(test):
yield test.n
class test:
n = 123
def testit(self):
return stream_from_test_instance(self) Or, since streams are reusable: class test:
def __init__(self, n):
self.n = n
self.stream = stream_from_test_instance(self)
def testit(self):
return self.stream The error message you got isn't really explaining what's happening though. Let's try to detect Hope that helps, thanks again. |
ok, thanks for explanation.
- Jenda
po 27. 8. 2018 v 12:07 odesílatel Vincent Michel <notifications@github.com>
napsal:
… Hi @jenda1 <https://github.com/jenda1>, thank you for creating this issue.
The problem here is that the decorated generator becomes a Stream
subclass, in order to provide support for pipe-lining (|), slicing ([])
and concatenation (+). That means testit is *not* a method and this is
why you have to pass the t instance explicitly in your workaround.
Instead, you could consider this alternative:
@operatorasync def stream_from_test_instance(test):
yield test.n
class test:
n = 123
def testit(self):
return stream_from_test_instance(self)
Or, since streams are reusable:
class test:
def __init__(self, n):
self.n = n
self.stream = stream_from_test_instance(self)
def testit(self):
return self.stream
The error message you got isn't really explaining what's happening though.
I think I'll try to detect self or cls arguments and raise an exception
with a proper explanation.
Hope that helps, thanks again.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ARJE-rfymZ_eAE27ukYs50GsEBw9eUO8ks5uU8TGgaJpZM4WLsYA>
.
|
Done ! (see PR #24) |
I tried to use
aiostream.core.operator
on a class method:but it fails with error:
As workaround it is possible to use different name and call the operator with the class instance:
The text was updated successfully, but these errors were encountered: