|
41 | 41 | "from IPython.core.displayhook import DisplayHook\n", |
42 | 42 | "from IPython.utils.capture import capture_output\n", |
43 | 43 | "from IPython.utils.text import strip_ansi\n", |
44 | | - "from IPython.core.completer import IPCompleter,provisionalcompleter\n", |
| 44 | + "from IPython.core.completer import IPCompleter,provisionalcompleter,Completer\n", |
45 | 45 | "from IPython.core.hooks import CommandChainDispatcher\n", |
46 | 46 | "from IPython.core.completerlib import module_completer\n", |
47 | 47 | "from IPython.utils.strdispatch import StrDispatch\n", |
|
779 | 779 | "text/plain": [ |
780 | 780 | "[{'name': 'stdout',\n", |
781 | 781 | " 'output_type': 'stream',\n", |
782 | | - " 'text': ['CPU times: user 4 us, sys: 1 us, total: 5 us\\n',\n", |
783 | | - " 'Wall time: 9.06 us\\n']},\n", |
| 782 | + " 'text': ['CPU times: user 1e+03 ns, sys: 1 us, total: 2 us\\n',\n", |
| 783 | + " 'Wall time: 2.15 us\\n']},\n", |
784 | 784 | " {'data': {'text/plain': ['2']},\n", |
785 | 785 | " 'metadata': {},\n", |
786 | 786 | " 'output_type': 'execute_result',\n", |
|
1020 | 1020 | "File <ipython-input-1-a5c3817716b6>:1\n", |
1021 | 1021 | "----> 1 import time; time.sleep(1.1)\n", |
1022 | 1022 | "\n", |
1023 | | - "Cell In[58], line 7, in run_cell.<locals>.handler(*args)\n", |
| 1023 | + "Cell In[6], line 7, in run_cell.<locals>.handler(*args)\n", |
1024 | 1024 | "----> 7 def handler(*args): raise TimeoutError()\n", |
1025 | 1025 | "\n", |
1026 | 1026 | "TimeoutError: \n", |
|
1059 | 1059 | "File <span class=\"ansi-green-fg\"><ipython-input-1-a5c3817716b6>:1</span>\n", |
1060 | 1060 | "<span class=\"ansi-green-fg\">----> 1</span> <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">import</span> <span class=\"ansi-bold\" style=\"color: rgb(0,0,255)\">time</span>; time<span style=\"color: rgb(98,98,98)\">.</span>sleep(<span style=\"color: rgb(98,98,98)\">1.1</span>)\n", |
1061 | 1061 | "\n", |
1062 | | - "Cell <span class=\"ansi-green-fg\">In[58], line 7</span>, in <span class=\"ansi-cyan-fg\">run_cell.<locals>.handler</span><span class=\"ansi-blue-fg\">(*args)</span>\n", |
| 1062 | + "Cell <span class=\"ansi-green-fg\">In[6], line 7</span>, in <span class=\"ansi-cyan-fg\">run_cell.<locals>.handler</span><span class=\"ansi-blue-fg\">(*args)</span>\n", |
1063 | 1063 | "<span class=\"ansi-green-fg\">----> 7</span> <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">def</span> <span style=\"color: rgb(0,0,255)\">handler</span>(<span style=\"color: rgb(98,98,98)\">*</span>args): <span class=\"ansi-bold\" style=\"color: rgb(0,135,0)\">raise</span> <span class=\"ansi-bold\" style=\"color: rgb(215,95,95)\">TimeoutError</span>()\n", |
1064 | 1064 | "\n", |
1065 | 1065 | "<span class=\"ansi-red-fg\">TimeoutError</span>: \n", |
|
1738 | 1738 | "===========================================================================\n", |
1739 | 1739 | "\n", |
1740 | 1740 | "While Executing Cell #2:\n", |
1741 | | - "['Traceback (most recent call last):\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_23644/1421292703.py\", line 3, in <module>\\n s.execute(\\'../tests/error.ipynb\\', exc_stop=True)\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_23644/3609882568.py\", line 18, in execute\\n self.run_all(nb, exc_stop=exc_stop, preproc=preproc, postproc=postproc,\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_23644/3068237356.py\", line 19, in run_all\\n if self.exc and exc_stop: raise self.exc from None\\n ^^^^^^^^^^^^^^^^^^^^^^^^\\n', ' File \"/Users/jhoward/miniconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py\", line 3577, in run_code\\n exec(code_obj, self.user_global_ns, self.user_ns)\\n', ' File \"<ipython-input-1-b968a57a586e>\", line 3, in <module>\\n foo()\\n', ' File \"/Users/jhoward/subs_aai/execnb/tests/err.py\", line 2, in foo\\n assert 13 == 98\\n ^^^^^^^^\\n', 'AssertionError\\n']\n", |
| 1741 | + "['Traceback (most recent call last):\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_37071/1421292703.py\", line 3, in <module>\\n s.execute(\\'../tests/error.ipynb\\', exc_stop=True)\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_37071/3609882568.py\", line 18, in execute\\n self.run_all(nb, exc_stop=exc_stop, preproc=preproc, postproc=postproc,\\n', ' File \"/var/folders/ss/34z569j921v58v8n1n_8z7h40000gn/T/ipykernel_37071/3068237356.py\", line 19, in run_all\\n if self.exc and exc_stop: raise self.exc from None\\n ^^^^^^^^^^^^^^^^^^^^^^^^\\n', ' File \"/Users/jhoward/miniconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py\", line 3577, in run_code\\n exec(code_obj, self.user_global_ns, self.user_ns)\\n', ' File \"<ipython-input-1-b968a57a586e>\", line 3, in <module>\\n foo()\\n', ' File \"/Users/jhoward/subs_aai/execnb/tests/err.py\", line 2, in foo\\n assert 13 == 98\\n ^^^^^^^^\\n', 'AssertionError\\n']\n", |
1742 | 1742 | "\n" |
1743 | 1743 | ] |
1744 | 1744 | } |
|
2016 | 2016 | " def __call__(self, c):\n", |
2017 | 2017 | " if not c: return []\n", |
2018 | 2018 | " with provisionalcompleter():\n", |
2019 | | - " return [o.text.rpartition('.')[-1]\n", |
2020 | | - " for o in self.completions(c, len(c))\n", |
2021 | | - " if o.type not in ('magic', 'path')]" |
| 2019 | + " res = [o.text.rpartition('.')[-1] for o in self.completions(c, len(c)) if o.type!='magic']\n", |
| 2020 | + " if res and res[0][-1]=='=': res = [o for o in res if o[-1]=='=']\n", |
| 2021 | + " return res" |
2022 | 2022 | ] |
2023 | 2023 | }, |
2024 | 2024 | { |
|
2049 | 2049 | "test_set(cc(\"from abc import AB\"), ['ABC', 'ABCMeta'])" |
2050 | 2050 | ] |
2051 | 2051 | }, |
| 2052 | + { |
| 2053 | + "cell_type": "code", |
| 2054 | + "execution_count": null, |
| 2055 | + "metadata": {}, |
| 2056 | + "outputs": [ |
| 2057 | + { |
| 2058 | + "data": { |
| 2059 | + "text/plain": [ |
| 2060 | + "['n=', 'pat=', 's=']" |
| 2061 | + ] |
| 2062 | + }, |
| 2063 | + "execution_count": null, |
| 2064 | + "metadata": {}, |
| 2065 | + "output_type": "execute_result" |
| 2066 | + } |
| 2067 | + ], |
| 2068 | + "source": [ |
| 2069 | + "s = CaptureShell()\n", |
| 2070 | + "cc = SmartCompleter(s)\n", |
| 2071 | + "s.run('''def captures(pat, s, n, **kw):\n", |
| 2072 | + " return 1''')\n", |
| 2073 | + "cc('captures(')" |
| 2074 | + ] |
| 2075 | + }, |
2052 | 2076 | { |
2053 | 2077 | "cell_type": "code", |
2054 | 2078 | "execution_count": null, |
|
0 commit comments