Skip to content

Commit 68fae7e

Browse files
committed
fixes #67
1 parent dbc7cfe commit 68fae7e

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

execnb/shell.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from IPython.core.displayhook import DisplayHook
1919
from IPython.utils.capture import capture_output
2020
from IPython.utils.text import strip_ansi
21-
from IPython.core.completer import IPCompleter,provisionalcompleter
21+
from IPython.core.completer import IPCompleter,provisionalcompleter,Completer
2222
from IPython.core.hooks import CommandChainDispatcher
2323
from IPython.core.completerlib import module_completer
2424
from IPython.utils.strdispatch import StrDispatch
@@ -307,9 +307,9 @@ def __init__(self, shell, namespace=None, jedi=False):
307307
def __call__(self, c):
308308
if not c: return []
309309
with provisionalcompleter():
310-
return [o.text.rpartition('.')[-1]
311-
for o in self.completions(c, len(c))
312-
if o.type not in ('magic', 'path')]
310+
res = [o.text.rpartition('.')[-1] for o in self.completions(c, len(c)) if o.type!='magic']
311+
if res and res[0][-1]=='=': res = [o for o in res if o[-1]=='=']
312+
return res
313313

314314
# %% ../nbs/02_shell.ipynb
315315
@patch

nbs/02_shell.ipynb

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"from IPython.core.displayhook import DisplayHook\n",
4242
"from IPython.utils.capture import capture_output\n",
4343
"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",
4545
"from IPython.core.hooks import CommandChainDispatcher\n",
4646
"from IPython.core.completerlib import module_completer\n",
4747
"from IPython.utils.strdispatch import StrDispatch\n",
@@ -779,8 +779,8 @@
779779
"text/plain": [
780780
"[{'name': 'stdout',\n",
781781
" '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",
784784
" {'data': {'text/plain': ['2']},\n",
785785
" 'metadata': {},\n",
786786
" 'output_type': 'execute_result',\n",
@@ -1020,7 +1020,7 @@
10201020
"File <ipython-input-1-a5c3817716b6>:1\n",
10211021
"----> 1 import time; time.sleep(1.1)\n",
10221022
"\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",
10241024
"----> 7 def handler(*args): raise TimeoutError()\n",
10251025
"\n",
10261026
"TimeoutError: \n",
@@ -1059,7 +1059,7 @@
10591059
"File <span class=\"ansi-green-fg\">&lt;ipython-input-1-a5c3817716b6&gt;:1</span>\n",
10601060
"<span class=\"ansi-green-fg\">----&gt; 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",
10611061
"\n",
1062-
"Cell <span class=\"ansi-green-fg\">In[58], line 7</span>, in <span class=\"ansi-cyan-fg\">run_cell.&lt;locals&gt;.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.&lt;locals&gt;.handler</span><span class=\"ansi-blue-fg\">(*args)</span>\n",
10631063
"<span class=\"ansi-green-fg\">----&gt; 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",
10641064
"\n",
10651065
"<span class=\"ansi-red-fg\">TimeoutError</span>: \n",
@@ -1738,7 +1738,7 @@
17381738
"===========================================================================\n",
17391739
"\n",
17401740
"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",
17421742
"\n"
17431743
]
17441744
}
@@ -2016,9 +2016,9 @@
20162016
" def __call__(self, c):\n",
20172017
" if not c: return []\n",
20182018
" 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"
20222022
]
20232023
},
20242024
{
@@ -2049,6 +2049,30 @@
20492049
"test_set(cc(\"from abc import AB\"), ['ABC', 'ABCMeta'])"
20502050
]
20512051
},
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+
},
20522076
{
20532077
"cell_type": "code",
20542078
"execution_count": null,

0 commit comments

Comments
 (0)