Skip to content

Commit 1ce5865

Browse files
authored
Merge pull request #769 from blink1073/more-mypy
2 parents 1715bd1 + 779eef3 commit 1ce5865

29 files changed

+174
-133
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ jobs:
6868
pip install -e .[test]
6969
pip freeze
7070
71-
- name: Check types
72-
run: mypy jupyter_client --exclude '\/tests|kernelspecapp|ioloop|runapp' --install-types --non-interactive
73-
7471
- name: Run the tests
7572
if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(matrix.os, 'windows') }}
7673
run: |

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ repos:
5050
]
5151
stages: [manual]
5252

53+
- repo: https://github.com/pre-commit/mirrors-mypy
54+
rev: v0.942
55+
hooks:
56+
- id: mypy
57+
exclude: jupyter_client/tests
58+
args: ["--config-file", "pyproject.toml"]
59+
additional_dependencies: [pyzmq, tornado, types-paramiko]
60+
stages: [manual]
61+
5362
- repo: https://github.com/PyCQA/doc8
5463
rev: 0.11.1
5564
hooks:

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
# |version| and |release|, also used in various other places throughout the
6464
# built documents.
6565
#
66-
version_ns = {}
66+
version_ns: dict = {}
6767
here = os.path.dirname(__file__)
6868
version_py = os.path.join(here, os.pardir, 'jupyter_client', '_version.py')
6969
with open(version_py) as f:
@@ -219,7 +219,7 @@
219219

220220
# -- Options for LaTeX output ---------------------------------------------
221221

222-
latex_elements = {
222+
latex_elements: dict = {
223223
# The paper size ('letterpaper' or 'a4paper').
224224
# 'papersize': 'letterpaper',
225225
# The font size ('10pt', '11pt' or '12pt').
@@ -312,7 +312,7 @@
312312
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
313313

314314
if not on_rtd: # only import and set the theme if we're building docs locally
315-
import sphinx_rtd_theme
315+
import sphinx_rtd_theme # type:ignore[import]
316316

317317
html_theme = 'sphinx_rtd_theme'
318318
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

jupyter_client/adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def handle_reply_status_error(self, msg: Dict[str, Any]) -> Dict[str, Any]:
8484
"""
8585
return msg
8686

87-
def __call__(self, msg: Dict[str, Any]):
87+
def __call__(self, msg: Dict[str, Any]) -> Dict[str, Any]:
8888
msg = self.update_header(msg)
8989
msg = self.update_metadata(msg)
9090
msg = self.update_msg_type(msg)

jupyter_client/asynchronous/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Implements an async kernel client"""
22
# Copyright (c) Jupyter Development Team.
33
# Distributed under the terms of the Modified BSD License.
4-
from traitlets import Type # type: ignore
4+
from traitlets import Type
55

66
from jupyter_client.channels import HBChannel
77
from jupyter_client.channels import ZMQSocketChannel

jupyter_client/blocking/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55
# Copyright (c) Jupyter Development Team.
66
# Distributed under the terms of the Modified BSD License.
7-
from traitlets import Type # type: ignore
7+
from traitlets import Type
88

99
from ..utils import run_sync
1010
from jupyter_client.channels import HBChannel

jupyter_client/channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class HBChannel(Thread):
4949

5050
def __init__(
5151
self,
52-
context: zmq.asyncio.Context = None,
52+
context: t.Optional[zmq.asyncio.Context] = None,
5353
session: t.Optional[Session] = None,
5454
address: t.Union[t.Tuple[str, int], str] = "",
5555
):
@@ -210,7 +210,7 @@ def __init__(
210210
self.socket: t.Optional[zmq.sugar.socket.Socket] = socket
211211
self.session = session
212212

213-
async def _recv(self, **kwargs) -> t.Dict[str, t.Any]:
213+
async def _recv(self, **kwargs: t.Any) -> t.Dict[str, t.Any]:
214214
assert self.socket is not None
215215
msg = await self.socket.recv_multipart(**kwargs)
216216
ident, smsg = self.session.feed_identities(msg)

jupyter_client/client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from queue import Empty
1111

1212
import zmq.asyncio
13-
from traitlets import Any # type: ignore
13+
from traitlets import Any
1414
from traitlets import Bool
1515
from traitlets import Instance
1616
from traitlets import Type
@@ -120,19 +120,19 @@ def _context_default(self) -> zmq.asyncio.Context:
120120
# Channel proxy methods
121121
# --------------------------------------------------------------------------
122122

123-
async def _async_get_shell_msg(self, *args, **kwargs) -> t.Dict[str, t.Any]:
123+
async def _async_get_shell_msg(self, *args: Any, **kwargs: Any) -> t.Dict[str, t.Any]:
124124
"""Get a message from the shell channel"""
125125
return await self.shell_channel.get_msg(*args, **kwargs)
126126

127-
async def _async_get_iopub_msg(self, *args, **kwargs) -> t.Dict[str, t.Any]:
127+
async def _async_get_iopub_msg(self, *args: Any, **kwargs: Any) -> t.Dict[str, t.Any]:
128128
"""Get a message from the iopub channel"""
129129
return await self.iopub_channel.get_msg(*args, **kwargs)
130130

131-
async def _async_get_stdin_msg(self, *args, **kwargs) -> t.Dict[str, t.Any]:
131+
async def _async_get_stdin_msg(self, *args: Any, **kwargs: Any) -> t.Dict[str, t.Any]:
132132
"""Get a message from the stdin channel"""
133133
return await self.stdin_channel.get_msg(*args, **kwargs)
134134

135-
async def _async_get_control_msg(self, *args, **kwargs) -> t.Dict[str, t.Any]:
135+
async def _async_get_control_msg(self, *args: Any, **kwargs: Any) -> t.Dict[str, t.Any]:
136136
"""Get a message from the control channel"""
137137
return await self.control_channel.get_msg(*args, **kwargs)
138138

@@ -253,7 +253,7 @@ def _output_hook_kernel(
253253
self,
254254
session: Session,
255255
socket: zmq.sugar.socket.Socket,
256-
parent_header,
256+
parent_header: Any,
257257
msg: t.Dict[str, t.Any],
258258
) -> None:
259259
"""Output hook when running inside an IPython kernel
@@ -676,7 +676,7 @@ def history(
676676
raw: bool = True,
677677
output: bool = False,
678678
hist_access_type: str = "range",
679-
**kwargs,
679+
**kwargs: Any,
680680
) -> str:
681681
"""Get entries from the kernel's history list.
682682

jupyter_client/connect.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
from typing import Tuple
2424
from typing import Union
2525

26-
import zmq # type: ignore
27-
from jupyter_core.paths import jupyter_data_dir # type: ignore
26+
import zmq
27+
from jupyter_core.paths import jupyter_data_dir
2828
from jupyter_core.paths import jupyter_runtime_dir
2929
from jupyter_core.paths import secure_write
30-
from traitlets import Bool # type: ignore
30+
from traitlets import Bool
3131
from traitlets import CaselessStrEnum
3232
from traitlets import Instance
3333
from traitlets import Int
3434
from traitlets import Integer
3535
from traitlets import observe
3636
from traitlets import Type
3737
from traitlets import Unicode
38-
from traitlets.config import LoggingConfigurable # type: ignore
38+
from traitlets.config import LoggingConfigurable
3939
from traitlets.config import SingletonConfigurable
4040

4141
from .localinterfaces import localhost
@@ -644,7 +644,7 @@ class is attempting to resolve (minimize).
644644
See: https://github.com/jupyter/jupyter_client/issues/487
645645
"""
646646

647-
def __init__(self, **kwargs) -> None:
647+
def __init__(self, **kwargs: Any) -> None:
648648
super().__init__(**kwargs)
649649
self.currently_used_ports: Set[int] = set()
650650

jupyter_client/consoleapp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
import warnings
1515
from typing import cast
1616

17-
from jupyter_core.application import base_aliases # type: ignore
17+
from jupyter_core.application import base_aliases
1818
from jupyter_core.application import base_flags
19-
from traitlets import CBool # type: ignore
19+
from traitlets import CBool
2020
from traitlets import CUnicode
2121
from traitlets import Dict
2222
from traitlets import List
2323
from traitlets import Type
2424
from traitlets import Unicode
25-
from traitlets.config.application import boolean_flag # type: ignore
25+
from traitlets.config.application import boolean_flag
2626

2727
from . import connect
2828
from . import find_connection_file
@@ -155,7 +155,7 @@ def _connection_file_default(self) -> str:
155155
to force a direct exit without any confirmation.""",
156156
)
157157

158-
def build_kernel_argv(self, argv=None) -> None:
158+
def build_kernel_argv(self, argv: object = None) -> None:
159159
"""build argv to be passed to kernel subprocess
160160
161161
Override in subclasses if any args should be passed to the kernel
@@ -354,7 +354,7 @@ def init_kernel_client(self) -> None:
354354

355355
self.kernel_client.start_channels()
356356

357-
def initialize(self, argv=None) -> None:
357+
def initialize(self, argv: object = None) -> None:
358358
"""
359359
Classes which mix this class in should call:
360360
JupyterConsoleApp.initialize(self,argv)

0 commit comments

Comments
 (0)