-
Notifications
You must be signed in to change notification settings - Fork 148
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
Fail to extend a Stream with new methods #442
Comments
It would work with |
@martindurant, the issue with |
It's called subclassing in the |
I think I see what you are trying to do, but you face the following problem: That leaves you with the two obvious paths, as you point out: come up with unique names for all node types, or allow name clashes and understand that you may clobber for all streams. For your example, I'm not totally sure how you expect the method However, another possibility, is maybe what you are actually after. You can use s = Stream()
m = s.map(func) or s = Stream()
m = streamz.core.map(s, func) or s = Stream()
m = streamz.core.map(None, func)
s.connect(m) |
Line 161 in 7453431
The following @classmethod
def register_api(cls, func):
@functools.wraps(func)
def wrapped(self, *args, **kwargs):
clazz = type(func.__name__, (func, type(self)), {})
node = clazz(self, *args, **kwargs)
return node
setattr(Stream, func.__name__, wrapped)
This is just an example to demonstrate the issue with inheritance. Don't read too much into it.
This library threats it's methods as plugings but doesn't keep track of them. So I'd have to rewrite all the methods that are registered by |
I haven't had a chance yet to understand what difference your alternate decorator has, but please do propose a PR to demonstrate it! I daresay there are others who have thought along these lines and not known how to proceed. |
Inheritance on a Stream seems to be broken.
The following example fails with
'map' object has no attribute 'draw'
:I couldn't find a class factory in the source and it looks like all the nodes are instantiated directlly with
Stream
when it should use the type of the main instance.The text was updated successfully, but these errors were encountered: