Skip to content

Commit 2f6a820

Browse files
committed
Type check nbclient/util.py
1 parent fc42084 commit 2f6a820

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

nbclient/util.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,29 @@
66
import asyncio
77
import sys
88
import inspect
9+
from typing import Callable, Awaitable, Any, Union
910

1011

11-
def check_ipython():
12+
def check_ipython() -> None:
1213
# original from vaex/asyncio.py
1314
IPython = sys.modules.get('IPython')
1415
if IPython:
15-
IPython_version = tuple(map(int, IPython.__version__.split('.')))
16+
IPython_version = tuple(map(int, IPython.__version__.split('.'))) # type: ignore
1617
if IPython_version < (7, 0, 0):
17-
raise RuntimeError(f'You are using IPython {IPython.__version__} while we require'
18+
raise RuntimeError(f'You are using IPython {IPython.__version__} while we require' # type: ignore
1819
'7.0.0+, please update IPython')
1920

2021

21-
def check_patch_tornado():
22+
def check_patch_tornado() -> None:
2223
"""If tornado is imported, add the patched asyncio.Future to its tuple of acceptable Futures"""
2324
# original from vaex/asyncio.py
2425
if 'tornado' in sys.modules:
2526
import tornado.concurrent
2627
if asyncio.Future not in tornado.concurrent.FUTURES:
27-
tornado.concurrent.FUTURES = tornado.concurrent.FUTURES + (asyncio.Future, )
28+
tornado.concurrent.FUTURES = tornado.concurrent.FUTURES + (asyncio.Future, ) # type: ignore
2829

2930

30-
def just_run(coro):
31+
def just_run(coro: Awaitable) -> Any:
3132
"""Make the coroutine run, even if there is an event loop running (using nest_asyncio)"""
3233
# original from vaex/asyncio.py
3334
loop = asyncio._get_running_loop()
@@ -51,7 +52,7 @@ def just_run(coro):
5152
return loop.run_until_complete(coro)
5253

5354

54-
def run_sync(coro):
55+
def run_sync(coro: Callable) -> Callable:
5556
"""Runs a coroutine and blocks until it has executed.
5657
5758
An event loop is created if no one already exists. If an event loop is
@@ -74,7 +75,7 @@ def wrapped(*args, **kwargs):
7475
return wrapped
7576

7677

77-
async def ensure_async(obj):
78+
async def ensure_async(obj: Union[Awaitable, Any]) -> Any:
7879
"""Convert a non-awaitable object to a coroutine if needed,
7980
and await it if it was not already awaited.
8081
"""

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ commands = flake8 nbclient --count --ignore=E203,E731,F811,W503 --max-complexity
1818
[testenv:mypy]
1919
skip_install = true
2020
deps = mypy
21-
commands = mypy nbclient/client.py
21+
commands = mypy nbclient/client.py nbclient/util.py
2222

2323
# Manifest
2424
[testenv:manifest]

0 commit comments

Comments
 (0)