Skip to content

Commit 61d36ce

Browse files
authored
Clean up docs and typings (#230)
1 parent 4fb7b5d commit 61d36ce

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

docs/client.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ the state of all the widgets can be stored in the notebook's metadata.
187187
This allows rendering of the live widgets on for instance nbviewer, or when
188188
converting to html.
189189

190-
We can tell nbclient to not store the state using the `store_widget_state`
190+
We can tell nbclient to not store the state using the ``store_widget_state``
191191
argument::
192192

193193
client = NotebookClient(nb, store_widget_state=False)

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
'sphinx.ext.intersphinx',
3939
'sphinx.ext.mathjax',
4040
'sphinx.ext.napoleon',
41+
# 'autodoc_traits', # TODO
4142
'myst_parser',
4243
]
4344

@@ -187,4 +188,5 @@ def setup(app):
187188
os.chdir(HERE)
188189
with open(autogen_config) as f:
189190
exec(compile(f.read(), autogen_config, "exec"), {})
191+
print('Updated cli docs')
190192
os.chdir(prev_dir)

docs/requirements-doc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
autodoc-traits
12
mock
23
moto
34
myst-parser

nbclient/client.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,13 @@ class NotebookClient(LoggingConfigurable):
114114
If a cell execution was interrupted after a timeout, don't wait for
115115
the execute_reply from the kernel (e.g. KeyboardInterrupt error).
116116
Instead, return an execute_reply with the given error, which should
117-
be of the following form:
118-
{
119-
'ename': str, # Exception name, as a string
120-
'evalue': str, # Exception value, as a string
121-
'traceback': list(str), # traceback frames, as strings
122-
}
117+
be of the following form::
118+
119+
{
120+
'ename': str, # Exception name, as a string
121+
'evalue': str, # Exception value, as a string
122+
'traceback': list(str), # traceback frames, as strings
123+
}
123124
"""
124125
),
125126
).tag(config=True)
@@ -838,6 +839,7 @@ async def _async_handle_timeout(
838839
return execute_reply
839840
return None
840841
else:
842+
assert cell is not None
841843
raise CellTimeoutError.error_from_timeout_and_cell(
842844
"Cell execution timed out", timeout, cell
843845
)
@@ -1015,7 +1017,7 @@ async def async_execute_cell(
10151017

10161018
def process_message(
10171019
self, msg: t.Dict, cell: NotebookNode, cell_index: int
1018-
) -> t.Optional[t.List]:
1020+
) -> t.Optional[NotebookNode]:
10191021
"""
10201022
Processes a kernel message, updates cell state, and returns the
10211023
resulting output object that was appended to cell.outputs.
@@ -1033,7 +1035,7 @@ def process_message(
10331035
10341036
Returns
10351037
-------
1036-
output : dict
1038+
output : NotebookNode
10371039
The execution output payload (or None for no output).
10381040
10391041
Raises
@@ -1082,6 +1084,7 @@ def output(
10821084
) -> t.Optional[NotebookNode]:
10831085

10841086
msg_type = msg['msg_type']
1087+
out = None
10851088

10861089
parent_msg_id = msg['parent_header'].get('msg_id')
10871090
if self.output_hook_stack[parent_msg_id]:
@@ -1112,7 +1115,7 @@ def output(
11121115

11131116
outs.append(out)
11141117

1115-
return out
1118+
return out # type:ignore[no-any-return]
11161119

11171120
def clear_output(self, outs: t.List, msg: t.Dict, cell_index: int) -> None:
11181121

nbclient/tests/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ def test_mock_wrapper(self):
206206
cell_mock = NotebookNode(
207207
source='"foo" = "bar"', metadata={}, cell_type='code', outputs=[]
208208
)
209-
executor = NotebookClient({})
210-
executor.nb = {'cells': [cell_mock]}
209+
executor = NotebookClient({}) # type:ignore
210+
executor.nb = {'cells': [cell_mock]} # type:ignore
211211

212212
# self.kc.iopub_channel.get_msg => message_mock.side_effect[i]
213213
message_mock = iopub_messages_mock()
@@ -503,7 +503,7 @@ class TestExecute(NBClientTestsBase):
503503
maxDiff = None
504504

505505
def test_constructor(self):
506-
NotebookClient({})
506+
NotebookClient({}) # type:ignore
507507

508508
def test_populate_language_info(self):
509509
nb = nbformat.v4.new_notebook() # Certainly has no language_info.

nbclient/util.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import asyncio
77
import inspect
88
import sys
9-
from typing import Any, Awaitable, Callable, Optional, Union
9+
from typing import Any, Awaitable, Callable, Optional, TypeVar, Union
1010

1111

1212
def check_ipython() -> None:
@@ -62,7 +62,10 @@ def just_run(coro: Awaitable) -> Any:
6262
return loop.run_until_complete(coro)
6363

6464

65-
def run_sync(coro: Callable) -> Callable:
65+
T = TypeVar("T")
66+
67+
68+
def run_sync(coro: Callable[..., Awaitable[T]]) -> Callable[..., T]:
6669
"""Runs a coroutine and blocks until it has executed.
6770
6871
An event loop is created if no one already exists. If an event loop is

0 commit comments

Comments
 (0)