@@ -119,6 +119,22 @@ def __str__(self):
119119
120120class APIRegisterMixin (object ):
121121
122+ def _new_node (self , cls , args , kwargs ):
123+ """ Constructor for downstream nodes.
124+
125+ Examples
126+ --------
127+ To provide inheritance through nodes :
128+
129+ >>> class MyStream(Stream):
130+ >>>
131+ >>> def _new_node(self, cls, args, kwargs):
132+ >>> if not issubclass(cls, MyStream):
133+ >>> cls = type(cls.__name__, (cls, MyStream), dict(cls.__dict__))
134+ >>> return cls(*args, **kwargs)
135+ """
136+ return cls (* args , ** kwargs )
137+
122138 @classmethod
123139 def register_api (cls , modifier = identity , attribute_name = None ):
124140 """ Add callable to Stream API
@@ -158,6 +174,10 @@ def register_api(cls, modifier=identity, attribute_name=None):
158174 def _ (func ):
159175 @functools .wraps (func )
160176 def wrapped (* args , ** kwargs ):
177+ if identity is not staticmethod and args :
178+ self = args [0 ]
179+ if isinstance (self , APIRegisterMixin ):
180+ return self ._new_node (func , args , kwargs )
161181 return func (* args , ** kwargs )
162182 name = attribute_name if attribute_name else func .__name__
163183 setattr (cls , name , modifier (wrapped ))
0 commit comments