|
298 | 298 | "outputs": [], |
299 | 299 | "source": [ |
300 | 300 | "#export\n", |
301 | | - "@docs\n", |
302 | 301 | "class TypeDispatch:\n", |
303 | 302 | " \"Dictionary-like object; `__getitem__` matches keys of types using `issubclass`\"\n", |
304 | 303 | " def __init__(self, funcs=(), bases=()):\n", |
|
317 | 316 | " self.funcs.add(a0, t)\n", |
318 | 317 | " t.add(a1, f)\n", |
319 | 318 | "\n", |
320 | | - " def first(self): return self.funcs.first().first()\n", |
321 | | - " def returns(self, x): return anno_ret(self[type(x)])\n", |
322 | | - " def returns_none(self, x):\n", |
323 | | - " r = anno_ret(self[type(x)])\n", |
324 | | - " return None if r == NoneType else r\n", |
| 319 | + " def first(self):\n", |
| 320 | + " \"Get first function in ordered dict of type:func.\"\n", |
| 321 | + " return self.funcs.first().first()\n", |
| 322 | + " \n", |
| 323 | + " def returns(self, x):\n", |
| 324 | + " \"Get the return type of annotation of `x`.\"\n", |
| 325 | + " return anno_ret(self[type(x)])\n", |
325 | 326 | "\n", |
326 | 327 | " def _attname(self,k): return getattr(k,'__name__',str(k))\n", |
327 | 328 | " def __repr__(self):\n", |
|
355 | 356 | " for base in self.bases:\n", |
356 | 357 | " res = base[k]\n", |
357 | 358 | " if res is not None: return res\n", |
358 | | - " return None\n", |
359 | | - " \n", |
360 | | - " _docs = dict(first=\"Get first function in ordered dict of type:func.\",\n", |
361 | | - " returns=\"Get the return type of annotation of `x`.\",\n", |
362 | | - " returns_none=\"Returns `None` if return type annotation is `None` or `NoneType`.\")" |
363 | | - ] |
364 | | - }, |
365 | | - { |
366 | | - "cell_type": "code", |
367 | | - "execution_count": null, |
368 | | - "metadata": {}, |
369 | | - "outputs": [ |
370 | | - { |
371 | | - "data": { |
372 | | - "text/plain": [ |
373 | | - "<function __main__.a(z: type)>" |
374 | | - ] |
375 | | - }, |
376 | | - "execution_count": null, |
377 | | - "metadata": {}, |
378 | | - "output_type": "execute_result" |
379 | | - } |
380 | | - ], |
381 | | - "source": [ |
382 | | - "def a(z:type): return 'a'\n", |
383 | | - "def b(z:object): return 'b'\n", |
384 | | - "\n", |
385 | | - "t = TypeDispatch([a,b])\n", |
386 | | - "\n", |
387 | | - "t[TypeDispatch]" |
| 359 | + " return None" |
388 | 360 | ] |
389 | 361 | }, |
390 | 362 | { |
|
507 | 479 | { |
508 | 480 | "data": { |
509 | 481 | "text/markdown": [ |
510 | | - "<h4 id=\"TypeDispatch.add\" class=\"doc_header\"><code>TypeDispatch.add</code><a href=\"__main__.py#L11\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n", |
| 482 | + "<h4 id=\"TypeDispatch.add\" class=\"doc_header\"><code>TypeDispatch.add</code><a href=\"__main__.py#L10\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n", |
511 | 483 | "\n", |
512 | 484 | "> <code>TypeDispatch.add</code>(**`f`**)\n", |
513 | 485 | "\n", |
|
830 | 802 | { |
831 | 803 | "data": { |
832 | 804 | "text/markdown": [ |
833 | | - "<h4 id=\"TypeDispatch.__call__\" class=\"doc_header\"><code>TypeDispatch.__call__</code><a href=\"__main__.py#L34\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n", |
| 805 | + "<h4 id=\"TypeDispatch.__call__\" class=\"doc_header\"><code>TypeDispatch.__call__</code><a href=\"__main__.py#L35\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n", |
834 | 806 | "\n", |
835 | 807 | "> <code>TypeDispatch.__call__</code>(**\\*`args`**, **\\*\\*`kwargs`**)\n", |
836 | 808 | "\n", |
|
918 | 890 | { |
919 | 891 | "data": { |
920 | 892 | "text/markdown": [ |
921 | | - "<h4 id=\"TypeDispatch.returns\" class=\"doc_header\"><code>TypeDispatch.returns</code><a href=\"__main__.py#L22\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n", |
| 893 | + "<h4 id=\"TypeDispatch.returns\" class=\"doc_header\"><code>TypeDispatch.returns</code><a href=\"__main__.py#L24\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n", |
922 | 894 | "\n", |
923 | 895 | "> <code>TypeDispatch.returns</code>(**`x`**)\n", |
924 | 896 | "\n", |
|
0 commit comments