|
108 | 108 | "source": [
|
109 | 109 | "#export\n",
|
110 | 110 | "class _TfmMeta(type):\n",
|
111 |
| - " @classmethod\n", |
112 |
| - " def __prepare__(cls, name, bases): return _TfmDict()\n", |
113 |
| - "\n", |
114 | 111 | " def __new__(cls, name, bases, dict):\n",
|
115 | 112 | " res = super().__new__(cls, name, bases, dict)\n",
|
116 | 113 | " res.__signature__ = inspect.signature(res.__init__)\n",
|
|
119 | 116 | " def __call__(cls, *args, **kwargs):\n",
|
120 | 117 | " f = first(args)\n",
|
121 | 118 | " n = getattr(f,'__name__',None)\n",
|
122 |
| - " if not _is_tfm_method(f,n): return super().__call__(*args,**kwargs)\n", |
123 |
| - " if n in cls.__dict__: getattr(cls,n).dispatch(f)\n", |
124 |
| - " return _mk_plum_func(dispatch,n,f,cls=cls)" |
| 119 | + " if _is_tfm_method(f,n):\n", |
| 120 | + " if n in cls.__dict__: return getattr(cls,n).dispatch(f)\n", |
| 121 | + " return _mk_plum_func(dispatch,n,f,cls=cls)\n", |
| 122 | + " return super().__call__(*args,**kwargs)\n", |
| 123 | + "\n", |
| 124 | + " @classmethod\n", |
| 125 | + " def __prepare__(cls, name, bases): return _TfmDict()" |
125 | 126 | ]
|
126 | 127 | },
|
127 | 128 | {
|
|
166 | 167 | " self._d = Dispatcher() # TODO: do we need to hold this reference?\n",
|
167 | 168 | " for n in _tfm_methods: setattr(self,n,_mk_plum_func(self._d,n))\n",
|
168 | 169 | " if enc:\n",
|
169 |
| - " self.encodes = self.encodes.dispatch(enc)\n", |
| 170 | + " self.encodes.dispatch(enc)\n", |
170 | 171 | " self.order = getattr(enc,'order',self.order)\n",
|
171 | 172 | " if len(type_hints(enc)) > 0: self.input_types = first(type_hints(enc).values())\n",
|
172 | 173 | " self._name = _get_name(enc)\n",
|
173 |
| - " if dec: self.decodes = self.decodes.dispatch(dec)\n", |
| 174 | + " if dec: self.decodes.dispatch(dec)\n", |
174 | 175 | "\n",
|
175 | 176 | " @property\n",
|
176 | 177 | " def name(self): return getattr(self, '_name', _get_name(self))\n",
|
|
355 | 356 | "test_eq(f1(1), 2) # f1(1) is the same as f1.encode(1)"
|
356 | 357 | ]
|
357 | 358 | },
|
358 |
| - { |
359 |
| - "cell_type": "code", |
360 |
| - "execution_count": null, |
361 |
| - "metadata": {}, |
362 |
| - "outputs": [], |
363 |
| - "source": [ |
364 |
| - "class A(Transform):\n", |
365 |
| - " def encodes(self,x:int): return x+1" |
366 |
| - ] |
367 |
| - }, |
368 | 359 | {
|
369 | 360 | "cell_type": "markdown",
|
370 | 361 | "metadata": {},
|
|
624 | 615 | "test_eq_type(f(FloatSubclass(3.0)), FloatSubclass(6.0))"
|
625 | 616 | ]
|
626 | 617 | },
|
627 |
| - { |
628 |
| - "cell_type": "code", |
629 |
| - "execution_count": null, |
630 |
| - "metadata": {}, |
631 |
| - "outputs": [ |
632 |
| - { |
633 |
| - "data": { |
634 |
| - "text/plain": [ |
635 |
| - "__main__.FloatSubclass" |
636 |
| - ] |
637 |
| - }, |
638 |
| - "execution_count": null, |
639 |
| - "metadata": {}, |
640 |
| - "output_type": "execute_result" |
641 |
| - } |
642 |
| - ], |
643 |
| - "source": [ |
644 |
| - "type(f(FloatSubclass(3.0)))" |
645 |
| - ] |
646 |
| - }, |
647 | 618 | {
|
648 | 619 | "cell_type": "markdown",
|
649 | 620 | "metadata": {},
|
|
1083 | 1054 | "data": {
|
1084 | 1055 | "text/plain": [
|
1085 | 1056 | "A:\n",
|
1086 |
| - "encodes: <function <function noop at 0x111e2be50> with 2 method(s)>decodes: <function <function noop at 0x111e2be50> with 2 method(s)>" |
| 1057 | + "encodes: <function <function noop at 0x11fa2aa60> with 2 method(s)>decodes: <function <function noop at 0x11fa2aa60> with 2 method(s)>" |
1087 | 1058 | ]
|
1088 | 1059 | },
|
1089 | 1060 | "execution_count": null,
|
|
1113 | 1084 | "data": {
|
1114 | 1085 | "text/plain": [
|
1115 | 1086 | "A -- {'a': 1, 'b': 2}:\n",
|
1116 |
| - "encodes: <function <function noop at 0x111e2be50> with 3 method(s)>decodes: <function <function Transform.decodes at 0x115652f70> with 1 method(s)>" |
| 1087 | + "encodes: <function <function noop at 0x11fa2aa60> with 3 method(s)>decodes: <function <function Transform.decodes at 0x123253f70> with 1 method(s)>" |
1117 | 1088 | ]
|
1118 | 1089 | },
|
1119 | 1090 | "execution_count": null,
|
|
0 commit comments