@@ -119,6 +119,24 @@ def __str__(self):
119119
120120class APIRegisterMixin (object ):
121121
122+
123+ def _new_node (self , cls , args , kwargs ):
124+ """ Constructor for downstream nodes.
125+
126+ Examples
127+ --------
128+ To provide inheritance through nodes :
129+
130+ >>> class MyStream(Stream):
131+ >>>
132+ >>> def _new_node(self, cls, args, kwargs):
133+ >>> if not issubclass(cls, MyStream):
134+ >>> cls = type(cls.__name__, (cls, MyStream), dict(cls.__dict__))
135+ >>> return cls(*args, **kwargs)
136+ """
137+ return cls (* args , ** kwargs )
138+
139+
122140 @classmethod
123141 def register_api (cls , modifier = identity , attribute_name = None ):
124142 """ Add callable to Stream API
@@ -158,6 +176,10 @@ def register_api(cls, modifier=identity, attribute_name=None):
158176 def _ (func ):
159177 @functools .wraps (func )
160178 def wrapped (* args , ** kwargs ):
179+ if identity is not staticmethod and args :
180+ self = args [0 ]
181+ if isinstance (self , APIRegisterMixin ):
182+ return self ._new_node (func , args , kwargs )
161183 return func (* args , ** kwargs )
162184 name = attribute_name if attribute_name else func .__name__
163185 setattr (cls , name , modifier (wrapped ))
0 commit comments