|
7 | 7 | "metadata": {}, |
8 | 8 | "outputs": [], |
9 | 9 | "source": [ |
10 | | - "#|default_exp cast" |
| 10 | + "#| default_exp cast" |
11 | 11 | ] |
12 | 12 | }, |
13 | 13 | { |
|
17 | 17 | "metadata": {}, |
18 | 18 | "outputs": [], |
19 | 19 | "source": [ |
20 | | - "#|export\n", |
| 20 | + "#| export\n", |
21 | 21 | "from typing import Any\n", |
22 | 22 | "\n", |
23 | 23 | "from plum import dispatch, Function\n", |
|
79 | 79 | "metadata": {}, |
80 | 80 | "outputs": [], |
81 | 81 | "source": [ |
82 | | - "#|export\n", |
| 82 | + "#| export\n", |
83 | 83 | "def retain_meta(x, res, as_copy=False):\n", |
84 | 84 | " \"Call `res.set_meta(x)`, if it exists\"\n", |
85 | 85 | " if hasattr(res,'set_meta'): res.set_meta(x, as_copy=as_copy)\n", |
|
94 | 94 | "metadata": {}, |
95 | 95 | "outputs": [], |
96 | 96 | "source": [ |
97 | | - "#|export\n", |
| 97 | + "#| export\n", |
98 | 98 | "def default_set_meta(self, x, as_copy=False):\n", |
99 | 99 | " \"Copy over `_meta` from `x` to `res`, if it's missing\"\n", |
100 | 100 | " if hasattr(x, '_meta') and not hasattr(self, '_meta'):\n", |
|
112 | 112 | "metadata": {}, |
113 | 113 | "outputs": [], |
114 | 114 | "source": [ |
115 | | - "#|export\n", |
| 115 | + "#| export\n", |
116 | 116 | "def cast(x, typ):\n", |
117 | 117 | " \"cast `x` to type `typ` (may also change `x` inplace)\"\n", |
118 | 118 | " res = typ._before_cast(x) if hasattr(typ, '_before_cast') else x\n", |
|
206 | 206 | "metadata": {}, |
207 | 207 | "outputs": [], |
208 | 208 | "source": [ |
209 | | - "#|export\n", |
| 209 | + "#| export\n", |
210 | 210 | "def retain_type(new, old, ret_type=Any,as_copy=False):\n", |
211 | 211 | " \"Cast `new` to `ret_type` if given, or `old`'s type if `new` is a superclass of `old`. No conversion is done if `ret_type=None`\"\n", |
212 | 212 | " if new is None: return new\n", |
|
468 | 468 | "metadata": {}, |
469 | 469 | "outputs": [], |
470 | 470 | "source": [ |
471 | | - "#|export\n", |
| 471 | + "#| export\n", |
472 | 472 | "def retain_types(new, old=None, typs=None):\n", |
473 | 473 | " \"Cast each item of `new` to type of matching item in `old` if it's a superclass\"\n", |
474 | 474 | " if not is_listy(new): \n", |
|
509 | 509 | "metadata": {}, |
510 | 510 | "outputs": [], |
511 | 511 | "source": [ |
512 | | - "#|export\n", |
| 512 | + "#| export\n", |
513 | 513 | "def explode_types(o):\n", |
514 | 514 | " \"Return the type of `o`, potentially in nested dictionaries for thing that are listy\"\n", |
515 | 515 | " if not is_listy(o): return type(o)\n", |
|
541 | 541 | "metadata": {}, |
542 | 542 | "outputs": [], |
543 | 543 | "source": [ |
544 | | - "#|hide\n", |
545 | | - "#|eval: false\n", |
| 544 | + "#| hide\n", |
| 545 | + "#| eval: false\n", |
546 | 546 | "from nbdev import nbdev_export\n", |
547 | 547 | "nbdev_export()" |
548 | 548 | ] |
|
0 commit comments