|
22 | 22 | "from contextlib import contextmanager\n", |
23 | 23 | "from copy import copy\n", |
24 | 24 | "from configparser import ConfigParser\n", |
25 | | - "import random,pickle" |
| 25 | + "import random,pickle,inspect" |
26 | 26 | ] |
27 | 27 | }, |
28 | 28 | { |
|
33 | 33 | "source": [ |
34 | 34 | "from fastcore.test import *\n", |
35 | 35 | "from nbdev.showdoc import *\n", |
36 | | - "from fastcore.nb_imports import *\n", |
37 | | - "import inspect" |
| 36 | + "from fastcore.nb_imports import *" |
38 | 37 | ] |
39 | 38 | }, |
40 | 39 | { |
|
681 | 680 | "cell_type": "code", |
682 | 681 | "execution_count": null, |
683 | 682 | "metadata": {}, |
684 | | - "outputs": [ |
685 | | - { |
686 | | - "data": { |
687 | | - "text/plain": [ |
688 | | - "b'\\x80\\x03cinspect\\nSignature\\nq\\x00(cinspect\\nParameter\\nq\\x01X\\x05\\x00\\x00\\x00itemsq\\x02cinspect\\n_ParameterKind\\nq\\x03K\\x01\\x85q\\x04Rq\\x05\\x86q\\x06Rq\\x07}q\\x08(X\\x08\\x00\\x00\\x00_defaultq\\tNX\\x0b\\x00\\x00\\x00_annotationq\\ncinspect\\n_empty\\nq\\x0bubh\\x01X\\x04\\x00\\x00\\x00restq\\x0ch\\x03K\\x02\\x85q\\rRq\\x0e\\x86q\\x0fRq\\x10}q\\x11(h\\th\\x0bh\\nh\\x0bubh\\x01X\\x08\\x00\\x00\\x00use_listq\\x12h\\x03K\\x03\\x85q\\x13Rq\\x14\\x86q\\x15Rq\\x16}q\\x17(h\\t\\x89h\\nh\\x0bubh\\x01X\\x05\\x00\\x00\\x00matchq\\x18h\\x14\\x86q\\x19Rq\\x1a}q\\x1b(h\\tNh\\nh\\x0bubtq\\x1c\\x85q\\x1dRq\\x1e}q\\x1fX\\x12\\x00\\x00\\x00_return_annotationq h\\x0bsb.'" |
689 | | - ] |
690 | | - }, |
691 | | - "execution_count": null, |
692 | | - "metadata": {}, |
693 | | - "output_type": "execute_result" |
694 | | - } |
695 | | - ], |
| 683 | + "outputs": [], |
696 | 684 | "source": [ |
| 685 | + "#export\n", |
697 | 686 | "#hide\n", |
698 | 687 | "# Here we are fixing the signature of L. What happens is that the __call__ method on the MetaClass of L shadows the __init__\n", |
699 | 688 | "# giving the wrong signature (https://stackoverflow.com/questions/49740290/call-from-metaclass-shadows-signature-of-init).\n", |
700 | | - "#\n", |
701 | | - "# The solution adopted tries to not import the inspect module inside the lib code (notice that this cell is not exported)\n", |
702 | | - "# because it's really slow, but instead relies on pickling the correct signature and loading it.\n", |
703 | | - "\n", |
704 | 689 | "def _f(items=None, *rest, use_list=False, match=None): ...\n", |
705 | | - "pickle.dumps(inspect.signature(_f))" |
706 | | - ] |
707 | | - }, |
708 | | - { |
709 | | - "cell_type": "code", |
710 | | - "execution_count": null, |
711 | | - "metadata": {}, |
712 | | - "outputs": [], |
713 | | - "source": [ |
714 | | - "#export\n", |
715 | | - "#hide\n", |
716 | | - "L.__signature__ = pickle.loads(b'\\x80\\x03cinspect\\nSignature\\nq\\x00(cinspect\\nParameter\\nq\\x01X\\x05\\x00\\x00\\x00itemsq\\x02cinspect\\n_ParameterKind\\nq\\x03K\\x01\\x85q\\x04Rq\\x05\\x86q\\x06Rq\\x07}q\\x08(X\\x08\\x00\\x00\\x00_defaultq\\tNX\\x0b\\x00\\x00\\x00_annotationq\\ncinspect\\n_empty\\nq\\x0bubh\\x01X\\x04\\x00\\x00\\x00restq\\x0ch\\x03K\\x02\\x85q\\rRq\\x0e\\x86q\\x0fRq\\x10}q\\x11(h\\th\\x0bh\\nh\\x0bubh\\x01X\\x08\\x00\\x00\\x00use_listq\\x12h\\x03K\\x03\\x85q\\x13Rq\\x14\\x86q\\x15Rq\\x16}q\\x17(h\\t\\x89h\\nh\\x0bubh\\x01X\\x05\\x00\\x00\\x00matchq\\x18h\\x14\\x86q\\x19Rq\\x1a}q\\x1b(h\\tNh\\nh\\x0bubtq\\x1c\\x85q\\x1dRq\\x1e}q\\x1fX\\x12\\x00\\x00\\x00_return_annotationq h\\x0bsb.')" |
| 690 | + "L.__signature__ = inspect.signature(_f)" |
717 | 691 | ] |
718 | 692 | }, |
719 | 693 | { |
|
0 commit comments