Skip to content

Commit

Permalink
Clean up docs and typings (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored May 9, 2022
1 parent 4fb7b5d commit 61d36ce
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ the state of all the widgets can be stored in the notebook's metadata.
This allows rendering of the live widgets on for instance nbviewer, or when
converting to html.

We can tell nbclient to not store the state using the `store_widget_state`
We can tell nbclient to not store the state using the ``store_widget_state``
argument::

client = NotebookClient(nb, store_widget_state=False)
Expand Down
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'sphinx.ext.intersphinx',
'sphinx.ext.mathjax',
'sphinx.ext.napoleon',
# 'autodoc_traits', # TODO
'myst_parser',
]

Expand Down Expand Up @@ -187,4 +188,5 @@ def setup(app):
os.chdir(HERE)
with open(autogen_config) as f:
exec(compile(f.read(), autogen_config, "exec"), {})
print('Updated cli docs')
os.chdir(prev_dir)
1 change: 1 addition & 0 deletions docs/requirements-doc.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
autodoc-traits
mock
moto
myst-parser
Expand Down
21 changes: 12 additions & 9 deletions nbclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ class NotebookClient(LoggingConfigurable):
If a cell execution was interrupted after a timeout, don't wait for
the execute_reply from the kernel (e.g. KeyboardInterrupt error).
Instead, return an execute_reply with the given error, which should
be of the following form:
{
'ename': str, # Exception name, as a string
'evalue': str, # Exception value, as a string
'traceback': list(str), # traceback frames, as strings
}
be of the following form::
{
'ename': str, # Exception name, as a string
'evalue': str, # Exception value, as a string
'traceback': list(str), # traceback frames, as strings
}
"""
),
).tag(config=True)
Expand Down Expand Up @@ -838,6 +839,7 @@ async def _async_handle_timeout(
return execute_reply
return None
else:
assert cell is not None
raise CellTimeoutError.error_from_timeout_and_cell(
"Cell execution timed out", timeout, cell
)
Expand Down Expand Up @@ -1015,7 +1017,7 @@ async def async_execute_cell(

def process_message(
self, msg: t.Dict, cell: NotebookNode, cell_index: int
) -> t.Optional[t.List]:
) -> t.Optional[NotebookNode]:
"""
Processes a kernel message, updates cell state, and returns the
resulting output object that was appended to cell.outputs.
Expand All @@ -1033,7 +1035,7 @@ def process_message(
Returns
-------
output : dict
output : NotebookNode
The execution output payload (or None for no output).
Raises
Expand Down Expand Up @@ -1082,6 +1084,7 @@ def output(
) -> t.Optional[NotebookNode]:

msg_type = msg['msg_type']
out = None

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

outs.append(out)

return out
return out # type:ignore[no-any-return]

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

Expand Down
6 changes: 3 additions & 3 deletions nbclient/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ def test_mock_wrapper(self):
cell_mock = NotebookNode(
source='"foo" = "bar"', metadata={}, cell_type='code', outputs=[]
)
executor = NotebookClient({})
executor.nb = {'cells': [cell_mock]}
executor = NotebookClient({}) # type:ignore
executor.nb = {'cells': [cell_mock]} # type:ignore

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

def test_constructor(self):
NotebookClient({})
NotebookClient({}) # type:ignore

def test_populate_language_info(self):
nb = nbformat.v4.new_notebook() # Certainly has no language_info.
Expand Down
7 changes: 5 additions & 2 deletions nbclient/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import asyncio
import inspect
import sys
from typing import Any, Awaitable, Callable, Optional, Union
from typing import Any, Awaitable, Callable, Optional, TypeVar, Union


def check_ipython() -> None:
Expand Down Expand Up @@ -62,7 +62,10 @@ def just_run(coro: Awaitable) -> Any:
return loop.run_until_complete(coro)


def run_sync(coro: Callable) -> Callable:
T = TypeVar("T")


def run_sync(coro: Callable[..., Awaitable[T]]) -> Callable[..., T]:
"""Runs a coroutine and blocks until it has executed.
An event loop is created if no one already exists. If an event loop is
Expand Down

0 comments on commit 61d36ce

Please sign in to comment.