Skip to content

Commit

Permalink
Update typings and fix tests (#1344)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Oct 29, 2023
1 parent 1ffd6ee commit 444138c
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 42 deletions.
12 changes: 4 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-ast
Expand Down Expand Up @@ -44,11 +44,6 @@ repos:
- id: blacken-docs
additional_dependencies: [black==23.7.0]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
hooks:
Expand All @@ -63,13 +58,14 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
rev: v0.1.3
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/scientific-python/cookie
rev: "2023.09.21"
rev: "2023.10.27"
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
# html_theme_options = {}
html_theme_options = {"navigation_with_keys": False}

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
Expand Down
6 changes: 2 additions & 4 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ async def prepare(self) -> Awaitable[None] | None: # type:ignore[override]
warnings.warn( # noqa
"Overriding JupyterHandler.get_current_user is deprecated in jupyter-server 2.0."
" Use an IdentityProvider class.",
DeprecationWarning
DeprecationWarning,
# stacklevel not useful here
)
user = User(self.get_current_user())
Expand Down Expand Up @@ -993,9 +993,7 @@ def initialize(
if isinstance(path, str):
path = [path]

self.root = tuple(
os.path.abspath(os.path.expanduser(p)) + os.sep for p in path
) # type:ignore[assignment]
self.root = tuple(os.path.abspath(os.path.expanduser(p)) + os.sep for p in path) # type:ignore[assignment]
self.default_filename = default_filename

def compute_etag(self) -> str | None:
Expand Down
4 changes: 1 addition & 3 deletions jupyter_server/gateway/gateway_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,7 @@ def __init__(self, **kwargs):
"""Initialize a gateway client."""
super().__init__(**kwargs)
self._connection_args = {} # initialized on first use
self.gateway_token_renewer = self.gateway_token_renewer_class(
parent=self, log=self.log
) # type:ignore[operator]
self.gateway_token_renewer = self.gateway_token_renewer_class(parent=self, log=self.log) # type:ignore[operator]

# store of cookies with store time
self._cookies: ty.Dict[str, ty.Tuple[Morsel, datetime]] = {}
Expand Down
13 changes: 6 additions & 7 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,8 +1255,7 @@ def _default_allow_remote(self) -> bool:
# scoped to the loopback interface. For now, we'll assume that
# any scoped link-local address is effectively local.
if not (
parsed.is_loopback
or (("%" in addr) and parsed.is_link_local) # type:ignore[operator]
parsed.is_loopback or (("%" in addr) and parsed.is_link_local) # type:ignore[operator]
):
return True
return False
Expand Down Expand Up @@ -1885,7 +1884,8 @@ def init_configurables(self) -> None:
self.gateway_config = GatewayClient.instance(parent=self)

if not issubclass(
self.kernel_manager_class, AsyncMappingKernelManager # type:ignore[arg-type]
self.kernel_manager_class, # type:ignore[arg-type]
AsyncMappingKernelManager,
):
warnings.warn(
"The synchronous MappingKernelManager class is deprecated and will not be supported in Jupyter Server 3.0",
Expand All @@ -1894,7 +1894,8 @@ def init_configurables(self) -> None:
)

if not issubclass(
self.contents_manager_class, AsyncContentsManager # type:ignore[arg-type]
self.contents_manager_class, # type:ignore[arg-type]
AsyncContentsManager,
):
warnings.warn(
"The synchronous ContentsManager classes are deprecated and will not be supported in Jupyter Server 3.0",
Expand Down Expand Up @@ -1967,9 +1968,7 @@ def init_configurables(self) -> None:
f"Ignoring deprecated config ServerApp.login_handler_class={self.login_handler_class}."
" Superseded by ServerApp.identity_provider_class={self.identity_provider_class}."
)
self.identity_provider = self.identity_provider_class(
**identity_provider_kwargs
) # type:ignore[operator]
self.identity_provider = self.identity_provider_class(**identity_provider_kwargs) # type:ignore[operator]

if self.identity_provider_class is LegacyIdentityProvider:
# legacy config stored the password in tornado_settings
Expand Down
6 changes: 1 addition & 5 deletions jupyter_server/services/kernels/connection/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,11 +627,7 @@ def _finish_kernel_info(self, info):
if protocol_version != client_protocol_version:
self.session.adapt_version = int(protocol_version.split(".")[0])
self.log.info(
"Adapting from protocol version {protocol_version} (kernel {kernel_id}) to {client_protocol_version} (client).".format(
protocol_version=protocol_version,
kernel_id=self.kernel_id,
client_protocol_version=client_protocol_version,
)
f"Adapting from protocol version {protocol_version} (kernel {self.kernel_id}) to {client_protocol_version} (client)."
)
if not self._kernel_info_future.done():
self._kernel_info_future.set_result(info)
Expand Down
4 changes: 1 addition & 3 deletions jupyter_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,7 @@ def is_namespace_package(namespace: str) -> bool | None:
# NOTE: using submodule_search_locations because the loader can be None
try:
spec = importlib.util.find_spec(namespace)
except (
ValueError
): # spec is not set - see https://docs.python.org/3/library/importlib.html#importlib.util.find_spec
except ValueError: # spec is not set - see https://docs.python.org/3/library/importlib.html#importlib.util.find_spec
return None

if not spec:
Expand Down
18 changes: 7 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ nowarn = "test -W default {args}"

[tool.hatch.envs.typing]
features = ["test"]
dependencies = [ "mypy~=1.6", "traitlets>=5.11.2", "jupyter_core>=5.3.2"]
dependencies = [ "mypy~=1.6", "traitlets>=5.11.2", "jupyter_core>=5.3.2", "jupyter_client>=8.5"]
[tool.hatch.envs.typing.scripts]
test = "mypy --install-types --non-interactive {args:.}"

Expand All @@ -119,19 +119,18 @@ integration = "test --integration_tests=true {args}"
[tool.hatch.envs.lint]
detached = true
dependencies = [
"black[jupyter]==23.3.0",
"mdformat>0.7",
"ruff==0.0.287",
"ruff==0.1.3",
]
[tool.hatch.envs.lint.scripts]
style = [
"ruff {args:.}",
"black --check --diff {args:.}",
"ruff format {args:.}",
"mdformat --check {args:docs/source *.md}"
]
fmt = [
"black {args:.}",
"ruff --fix {args:.}",
"ruff format {args:.}",
"mdformat {args:docs/source *.md}"
]

Expand All @@ -153,13 +152,11 @@ skip-if-exists = ["jupyter_server/static/style/bootstrap.min.css"]
install-pre-commit-hook = true
optional-editable-build = true

[tool.black]
line-length = 100
target-version = ["py38"]

[tool.ruff]
target-version = "py38"
line-length = 100

[tool.ruff.lint]
select = [
"A",
"B",
Expand All @@ -171,7 +168,6 @@ select = [
"FBT",
"I",
"ICN",
"ISC",
"N",
"PLC",
"PLE",
Expand Down Expand Up @@ -234,7 +230,7 @@ unfixable = [
"RUF100",
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
# B011 Do not call assert False since python -O removes these calls
# F841 local variable 'foo' is assigned to but never used
# C408 Unnecessary `dict` call
Expand Down
3 changes: 3 additions & 0 deletions tests/services/sessions/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class DummyKernel:
def __init__(self, kernel_name="python"):
self.kernel_name = kernel_name

def update_env(self, *args, **kwargs):
pass


dummy_date = utcnow()
dummy_date_s = isoformat(dummy_date)
Expand Down

0 comments on commit 444138c

Please sign in to comment.