Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up typing config #1163

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
hatch run lint:build
pipx run interrogate -vv .
pipx run doc8 --max-line-length=200

Expand Down
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ repos:
- id: prettier
types_or: [yaml, html, json]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.6.1"
hooks:
- id: mypy
files: ipykernel
stages: [manual]
args: ["--install-types", "--non-interactive"]
additional_dependencies:
[
"traitlets>=5.13",
"ipython>=8.16.1",
"jupyter_client>=8.5",
"appnope",
]

- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
hooks:
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/comm/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


# this is the class that will be created if we do comm.create_comm
class BaseComm(comm.base_comm.BaseComm):
class BaseComm(comm.base_comm.BaseComm): # type:ignore[misc]
"""The base class for comms."""

kernel: Optional["Kernel"] = None
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/comm/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger = logging.getLogger("ipykernel.comm")


class CommManager(comm.base_comm.CommManager, traitlets.config.LoggingConfigurable):
class CommManager(comm.base_comm.CommManager, traitlets.config.LoggingConfigurable): # type:ignore[misc]
"""A comm manager."""

kernel = traitlets.Instance("ipykernel.kernelbase.Kernel")
Expand Down
4 changes: 3 additions & 1 deletion ipykernel/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def get_connection_info(
return info_str


def connect_qtconsole(connection_file: str | None = None, argv: list[str] | None = None) -> Popen:
def connect_qtconsole(
connection_file: str | None = None, argv: list[str] | None = None
) -> Popen[Any]:
"""Connect a qtconsole to the current kernel.

This is useful for connecting a second qtconsole to a kernel, or to a
Expand Down
4 changes: 2 additions & 2 deletions ipykernel/eventloops.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def wake():

# We have to put the wx.Timer in a wx.Frame for it to fire properly.
# We make the Frame hidden when we create it in the main app below.
class TimerFrame(wx.Frame):
class TimerFrame(wx.Frame): # type:ignore[misc]
def __init__(self, func):
wx.Frame.__init__(self, None, -1)
self.timer = wx.Timer(self)
Expand All @@ -182,7 +182,7 @@ def on_timer(self, event):

# We need a custom wx.App to create our Frame subclass that has the
# wx.Timer to defer back to the tornado event loop.
class IPWxApp(wx.App):
class IPWxApp(wx.App): # type:ignore[misc]
def OnInit(self):
self.frame = TimerFrame(wake)
self.frame.Show(False)
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, socket, pipe=False):
self._event_pipes: Dict[threading.Thread, Any] = {}
self._event_pipe_gc_lock: threading.Lock = threading.Lock()
self._event_pipe_gc_seconds: float = 10
self._event_pipe_gc_task: Optional[asyncio.Task] = None
self._event_pipe_gc_task: Optional[asyncio.Task[Any]] = None
self._setup_event_pipe()
self.thread = threading.Thread(target=self._thread_main, name="IOPub")
self.thread.daemon = True
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def __init__(self, **kwargs):

if _use_appnope() and self._darwin_app_nap:
# Disable app-nap as the kernel is not a gui but can have guis
import appnope
import appnope # type:ignore[import-untyped]

appnope.nope()

Expand Down
5 changes: 3 additions & 2 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
from __future__ import annotations

import atexit
import errno
Expand All @@ -10,10 +11,10 @@
import signal
import sys
import traceback
import typing as t
from functools import partial
from io import FileIO, TextIOWrapper
from logging import StreamHandler
from typing import Optional

import zmq
from IPython.core.application import ( # type:ignore[attr-defined]
Expand Down Expand Up @@ -132,7 +133,7 @@ class IPKernelApp(BaseIPythonApplication, InteractiveShellApp, ConnectionFileMix
poller = Any() # don't restrict this even though current pollers are all Threads
heartbeat = Instance(Heartbeat, allow_none=True)

context: Optional[zmq.Context] = Any() # type:ignore[assignment]
context: zmq.Context[t.Any] | None = Any() # type:ignore[assignment]
shell_socket = Any()
control_socket = Any()
debugpy_socket = Any()
Expand Down
5 changes: 3 additions & 2 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,8 @@ async def usage_request(self, stream, ident, parent):
# Ensure 1) self.processes is updated to only current subprocesses
# and 2) we reuse processes when possible (needed for accurate CPU)
self.processes = {
process.pid: self.processes.get(process.pid, process) for process in all_processes
process.pid: self.processes.get(process.pid, process) # type:ignore[misc,call-overload]
for process in all_processes
}
reply_content["kernel_cpu"] = sum(
[
Expand All @@ -1062,7 +1063,7 @@ async def usage_request(self, stream, ident, parent):
cpu_percent = psutil.cpu_percent()
# https://psutil.readthedocs.io/en/latest/index.html?highlight=cpu#psutil.cpu_percent
# The first time cpu_percent is called it will return a meaningless 0.0 value which you are supposed to ignore.
if cpu_percent is not None and cpu_percent != 0.0:
if cpu_percent is not None and cpu_percent != 0.0: # type:ignore[redundant-expr]
reply_content["host_cpu_percent"] = cpu_percent
reply_content["cpu_count"] = psutil.cpu_count(logical=True)
reply_content["host_virtual_memory"] = dict(psutil.virtual_memory()._asdict())
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/pylab/backend_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import warnings

from matplotlib_inline.backend_inline import * # analysis: ignore # noqa F401
from matplotlib_inline.backend_inline import * # type:ignore[import-untyped] # analysis: ignore # noqa F401

warnings.warn(
"`ipykernel.pylab.backend_inline` is deprecated, directly "
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/pylab/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import warnings

from matplotlib_inline.config import * # analysis: ignore # noqa F401
from matplotlib_inline.config import * # type:ignore[import-untyped] # analysis: ignore # noqa F401

warnings.warn(
"`ipykernel.pylab.config` is deprecated, directly use `matplotlib_inline.config`",
Expand Down
41 changes: 8 additions & 33 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,51 +111,26 @@ matrix.qt.features = [
]

[tool.hatch.envs.typing]
features = ["test"]
dependencies = ["mypy>=1.6.0", "traitlets>=5.13.0", "ipython>=8.16.1", "jupyter_client>=8.5"]
dependencies = ["pre-commit"]
detached = true
[tool.hatch.envs.typing.scripts]
test = "mypy --install-types --non-interactive {args}"
test = "pre-commit run --all-files --hook-stage manual mypy"

[tool.hatch.envs.lint]
dependencies = ["mdformat>0.7", "ruff==0.1.3"]
dependencies = ["pre-commit"]
detached = true
[tool.hatch.envs.lint.scripts]
style = [
"ruff {args:.}",
"ruff format {args:.}",
"mdformat --check {args:docs *.md}"
]
fmt = [
"ruff --fix {args:.}",
"ruff format {args:.}",
"mdformat {args:docs *.md}"
]
build = ["pre-commit run --all-files ruff"]

[tool.mypy]
files = "ipykernel"
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_decorators = true
strict = true
disable_error_code = ["no-untyped-def", "no-untyped-call", "import-not-found"]
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
follow_imports = "normal"
ignore_missing_imports = true
no_implicit_optional = true
no_implicit_reexport = true
pretty = true
show_error_context = true
show_error_codes = true
strict_equality = true
strict_optional = true
warn_unused_configs = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = "tests.*"
disable_error_code = ["ignore-without-code"]
warn_unreachable = false

[tool.pytest.ini_options]
minversion = "6.0"
Expand Down Expand Up @@ -340,4 +315,4 @@ toplevel = ["ipykernel/", "ipykernel_launcher.py"]
ignore = ["W002"]

[tool.repo-review]
ignore = ["PY007", "PP308", "GH102", "PC140", "MY101"]
ignore = ["PY007", "PP308", "GH102", "MY101"]
Loading