Skip to content

Commit ff94e31

Browse files
authored
Enable strict typing (#984)
* Use strict typing * fix imports * ignore pep585 and 604 typing changes
1 parent 49dbf0f commit ff94e31

31 files changed

+365
-271
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def filter(self, record: pylogging.LogRecord) -> bool:
329329
intersphinx_mapping = {'ipython': ('http://ipython.readthedocs.io/en/stable/', None)}
330330

331331

332-
def setup(app):
332+
def setup(app: object) -> None:
333333
HERE = osp.abspath(osp.dirname(__file__))
334334
dest = osp.join(HERE, 'changelog.md')
335335
shutil.copy(osp.join(HERE, '..', 'CHANGELOG.md'), dest)

jupyter_client/asynchronous/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""Implements an async kernel client"""
22
# Copyright (c) Jupyter Development Team.
33
# Distributed under the terms of the Modified BSD License.
4+
from __future__ import annotations
5+
6+
import typing as t
47

58
import zmq.asyncio
69
from traitlets import Instance, Type
@@ -9,10 +12,10 @@
912
from ..client import KernelClient, reqrep
1013

1114

12-
def wrapped(meth, channel):
15+
def wrapped(meth: t.Callable, channel: str) -> t.Callable:
1316
"""Wrap a method on a channel and handle replies."""
1417

15-
def _(self, *args, **kwargs):
18+
def _(self: AsyncKernelClient, *args: t.Any, **kwargs: t.Any) -> t.Any:
1619
reply = kwargs.pop("reply", False)
1720
timeout = kwargs.pop("timeout", None)
1821
msg_id = meth(self, *args, **kwargs)

jupyter_client/blocking/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
"""
55
# Copyright (c) Jupyter Development Team.
66
# Distributed under the terms of the Modified BSD License.
7+
from __future__ import annotations
8+
9+
import typing as t
10+
711
from traitlets import Type
812

913
from ..channels import HBChannel, ZMQSocketChannel
1014
from ..client import KernelClient, reqrep
1115
from ..utils import run_sync
1216

1317

14-
def wrapped(meth, channel):
18+
def wrapped(meth: t.Callable, channel: str) -> t.Callable:
1519
"""Wrap a method on a channel and handle replies."""
1620

17-
def _(self, *args, **kwargs):
21+
def _(self: BlockingKernelClient, *args: t.Any, **kwargs: t.Any) -> t.Any:
1822
reply = kwargs.pop("reply", False)
1923
timeout = kwargs.pop("timeout", None)
2024
msg_id = meth(self, *args, **kwargs)

jupyter_client/channels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(
5454
context: t.Optional[zmq.Context] = None,
5555
session: t.Optional[Session] = None,
5656
address: t.Union[t.Tuple[str, int], str] = "",
57-
):
57+
) -> None:
5858
"""Create the heartbeat monitor thread.
5959
6060
Parameters

jupyter_client/channelsabc.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ class ChannelABC(metaclass=abc.ABCMeta):
88
"""A base class for all channel ABCs."""
99

1010
@abc.abstractmethod
11-
def start(self):
11+
def start(self) -> None:
1212
"""Start the channel."""
1313
pass
1414

1515
@abc.abstractmethod
16-
def stop(self):
16+
def stop(self) -> None:
1717
"""Stop the channel."""
1818
pass
1919

2020
@abc.abstractmethod
21-
def is_alive(self):
21+
def is_alive(self) -> bool:
2222
"""Test whether the channel is alive."""
2323
pass
2424

@@ -32,20 +32,20 @@ class HBChannelABC(ChannelABC):
3232
"""
3333

3434
@abc.abstractproperty
35-
def time_to_dead(self):
35+
def time_to_dead(self) -> float:
3636
pass
3737

3838
@abc.abstractmethod
39-
def pause(self):
39+
def pause(self) -> None:
4040
"""Pause the heartbeat channel."""
4141
pass
4242

4343
@abc.abstractmethod
44-
def unpause(self):
44+
def unpause(self) -> None:
4545
"""Unpause the heartbeat channel."""
4646
pass
4747

4848
@abc.abstractmethod
49-
def is_beating(self):
49+
def is_beating(self) -> bool:
5050
"""Test whether the channel is beating."""
5151
pass

jupyter_client/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _context_default(self) -> zmq.Context:
113113
# flag for whether execute requests should be allowed to call raw_input:
114114
allow_stdin: bool = True
115115

116-
def __del__(self):
116+
def __del__(self) -> None:
117117
"""Handle garbage collection. Destroy context if applicable."""
118118
if (
119119
self._created_context
@@ -511,7 +511,7 @@ async def _async_execute_interactive(
511511
if output_hook is None and "IPython" in sys.modules:
512512
from IPython import get_ipython
513513

514-
ip = get_ipython()
514+
ip = get_ipython() # type:ignore[no-untyped-call]
515515
in_kernel = getattr(ip, "kernel", False)
516516
if in_kernel:
517517
output_hook = partial(

jupyter_client/clientabc.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
# -----------------------------------------------------------------------------
99
# Imports
1010
# -----------------------------------------------------------------------------
11+
from __future__ import annotations
12+
1113
import abc
14+
from typing import TYPE_CHECKING, Any
15+
16+
if TYPE_CHECKING:
17+
from .channelsabc import ChannelABC
1218

1319
# -----------------------------------------------------------------------------
1420
# Main kernel client class
@@ -24,64 +30,71 @@ class KernelClientABC(metaclass=abc.ABCMeta):
2430
"""
2531

2632
@abc.abstractproperty
27-
def kernel(self):
33+
def kernel(self) -> Any:
2834
pass
2935

3036
@abc.abstractproperty
31-
def shell_channel_class(self):
37+
def shell_channel_class(self) -> type[ChannelABC]:
3238
pass
3339

3440
@abc.abstractproperty
35-
def iopub_channel_class(self):
41+
def iopub_channel_class(self) -> type[ChannelABC]:
3642
pass
3743

3844
@abc.abstractproperty
39-
def hb_channel_class(self):
45+
def hb_channel_class(self) -> type[ChannelABC]:
4046
pass
4147

4248
@abc.abstractproperty
43-
def stdin_channel_class(self):
49+
def stdin_channel_class(self) -> type[ChannelABC]:
4450
pass
4551

4652
@abc.abstractproperty
47-
def control_channel_class(self):
53+
def control_channel_class(self) -> type[ChannelABC]:
4854
pass
4955

5056
# --------------------------------------------------------------------------
5157
# Channel management methods
5258
# --------------------------------------------------------------------------
5359

5460
@abc.abstractmethod
55-
def start_channels(self, shell=True, iopub=True, stdin=True, hb=True, control=True):
61+
def start_channels(
62+
self,
63+
shell: bool = True,
64+
iopub: bool = True,
65+
stdin: bool = True,
66+
hb: bool = True,
67+
control: bool = True,
68+
) -> None:
5669
"""Start the channels for the client."""
5770
pass
5871

5972
@abc.abstractmethod
60-
def stop_channels(self):
73+
def stop_channels(self) -> None:
6174
"""Stop the channels for the client."""
6275
pass
6376

6477
@abc.abstractproperty
65-
def channels_running(self):
78+
def channels_running(self) -> bool:
6679
"""Get whether the channels are running."""
6780
pass
6881

6982
@abc.abstractproperty
70-
def shell_channel(self):
83+
def shell_channel(self) -> ChannelABC:
7184
pass
7285

7386
@abc.abstractproperty
74-
def iopub_channel(self):
87+
def iopub_channel(self) -> ChannelABC:
7588
pass
7689

7790
@abc.abstractproperty
78-
def stdin_channel(self):
91+
def stdin_channel(self) -> ChannelABC:
7992
pass
8093

8194
@abc.abstractproperty
82-
def hb_channel(self):
95+
def hb_channel(self) -> ChannelABC:
8396
pass
8497

8598
@abc.abstractproperty
86-
def control_channel(self):
99+
def control_channel(self) -> ChannelABC:
87100
pass

0 commit comments

Comments
 (0)