Skip to content

Commit ff6a4e2

Browse files
committed
pre-commit
1 parent 82c53cc commit ff6a4e2

File tree

18 files changed

+43
-40
lines changed

18 files changed

+43
-40
lines changed

jupyter_server/_version.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55

66
import re
7-
from typing import List
87

98
# Version string must appear intact for automatic versioning
109
__version__ = "2.15.0.dev0"
@@ -13,7 +12,7 @@
1312
pattern = r"(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?P<rest>.*)"
1413
match = re.match(pattern, __version__)
1514
assert match is not None
16-
parts: List[object] = [int(match[part]) for part in ["major", "minor", "patch"]]
15+
parts: list[object] = [int(match[part]) for part in ["major", "minor", "patch"]]
1716
if match["rest"]:
1817
parts.append(match["rest"])
1918
version_info = tuple(parts)

jupyter_server/auth/authorizer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
# Distributed under the terms of the Modified BSD License.
1111
from __future__ import annotations
1212

13-
from typing import TYPE_CHECKING, Awaitable
13+
from collections.abc import Awaitable
14+
from typing import TYPE_CHECKING
1415

1516
from traitlets import Instance
1617
from traitlets.config import LoggingConfigurable

jupyter_server/base/call_context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Distributed under the terms of the Modified BSD License.
44

55
from contextvars import Context, ContextVar, copy_context
6-
from typing import Any, Dict, List
6+
from typing import Any
77

88

99
class CallContext:
@@ -22,7 +22,7 @@ class CallContext:
2222
# easier management over maintaining a set of ContextVar instances, since the Context is a
2323
# map of ContextVar instances to their values, and the "name" is no longer a lookup key.
2424
_NAME_VALUE_MAP = "_name_value_map"
25-
_name_value_map: ContextVar[Dict[str, Any]] = ContextVar(_NAME_VALUE_MAP)
25+
_name_value_map: ContextVar[dict[str, Any]] = ContextVar(_NAME_VALUE_MAP)
2626

2727
@classmethod
2828
def get(cls, name: str) -> Any:
@@ -65,7 +65,7 @@ def set(cls, name: str, value: Any) -> None:
6565
name_value_map[name] = value
6666

6767
@classmethod
68-
def context_variable_names(cls) -> List[str]:
68+
def context_variable_names(cls) -> list[str]:
6969
"""Returns a list of variable names set for this call context.
7070
7171
Returns
@@ -77,7 +77,7 @@ def context_variable_names(cls) -> List[str]:
7777
return list(name_value_map.keys())
7878

7979
@classmethod
80-
def _get_map(cls) -> Dict[str, Any]:
80+
def _get_map(cls) -> dict[str, Any]:
8181
"""Get the map of names to their values from the _NAME_VALUE_MAP context var.
8282
8383
If the map does not exist in the current context, an empty map is created and returned.

jupyter_server/base/handlers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
import re
1414
import types
1515
import warnings
16+
from collections.abc import Awaitable, Coroutine, Sequence
1617
from http.client import responses
1718
from logging import Logger
18-
from typing import TYPE_CHECKING, Any, Awaitable, Coroutine, Sequence, cast
19+
from typing import TYPE_CHECKING, Any, cast
1920
from urllib.parse import urlparse
2021

2122
import prometheus_client

jupyter_server/config_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from traitlets.config import LoggingConfigurable
1515
from traitlets.traitlets import Bool, Unicode
1616

17-
StrDict = t.Dict[str, t.Any]
17+
StrDict = dict[str, t.Any]
1818

1919

2020
def recursive_update(target: StrDict, new: StrDict) -> None:

jupyter_server/files/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import mimetypes
88
from base64 import decodebytes
9-
from typing import Awaitable
9+
from collections.abc import Awaitable
1010

1111
from jupyter_core.utils import ensure_async
1212
from tornado import web

jupyter_server/services/api/handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Distributed under the terms of the Modified BSD License.
55
import json
66
import os
7-
from typing import Any, Dict, List
7+
from typing import Any
88

99
from jupyter_core.utils import ensure_async
1010
from tornado import web
@@ -87,7 +87,7 @@ async def get(self):
8787
else:
8888
permissions_to_check = {}
8989

90-
permissions: Dict[str, List[str]] = {}
90+
permissions: dict[str, list[str]] = {}
9191
user = self.current_user
9292

9393
for resource, actions in permissions_to_check.items():
@@ -106,7 +106,7 @@ async def get(self):
106106
if authorized:
107107
allowed.append(action)
108108

109-
identity: Dict[str, Any] = self.identity_provider.identity_model(user)
109+
identity: dict[str, Any] = self.identity_provider.identity_model(user)
110110
model = {
111111
"identity": identity,
112112
"permissions": permissions,

jupyter_server/services/config/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ConfigManager(LoggingConfigurable):
2323

2424
def get(self, section_name):
2525
"""Get the config from all config sections."""
26-
config: t.Dict[str, t.Any] = {}
26+
config: dict[str, t.Any] = {}
2727
# step through back to front, to ensure front of the list is top priority
2828
for p in self.read_config_path[::-1]:
2929
cm = BaseJSONConfigManager(config_dir=p)

jupyter_server/services/contents/handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Distributed under the terms of the Modified BSD License.
88
import json
99
from http import HTTPStatus
10-
from typing import Any, Dict, List
10+
from typing import Any
1111

1212
try:
1313
from jupyter_client.jsonutil import json_default
@@ -24,7 +24,7 @@
2424
AUTH_RESOURCE = "contents"
2525

2626

27-
def _validate_keys(expect_defined: bool, model: Dict[str, Any], keys: List[str]):
27+
def _validate_keys(expect_defined: bool, model: dict[str, Any], keys: list[str]):
2828
"""
2929
Validate that the keys are defined (i.e. not None) or not (i.e. None)
3030
"""

jupyter_server/services/events/handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import json
99
from datetime import datetime
10-
from typing import TYPE_CHECKING, Any, Dict, Optional, cast
10+
from typing import TYPE_CHECKING, Any, Optional, cast
1111

1212
from jupyter_core.utils import ensure_async
1313
from tornado import web, websocket
@@ -127,7 +127,7 @@ async def post(self):
127127
validate_model(payload, self.event_logger.schemas)
128128
self.event_logger.emit(
129129
schema_id=cast(str, payload.get("schema_id")),
130-
data=cast("Dict[str, Any]", payload.get("data")),
130+
data=cast("dict[str, Any]", payload.get("data")),
131131
timestamp_override=get_timestamp(payload),
132132
)
133133
self.set_status(204)

jupyter_server/services/kernels/connection/abc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import ABC, abstractmethod
2-
from typing import Any, List
2+
from typing import Any
33

44

55
class KernelWebsocketConnectionABC(ABC):
@@ -25,5 +25,5 @@ def handle_incoming_message(self, incoming_msg: str) -> None:
2525
"""Broker the incoming websocket message to the appropriate ZMQ channel."""
2626

2727
@abstractmethod
28-
def handle_outgoing_message(self, stream: str, outgoing_msg: List[Any]) -> None:
28+
def handle_outgoing_message(self, stream: str, outgoing_msg: list[Any]) -> None:
2929
"""Broker outgoing ZMQ messages to the kernel websocket."""

jupyter_server/services/kernels/connection/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import json
44
import struct
5-
from typing import Any, List
5+
from typing import Any
66

77
from jupyter_client.session import Session
88
from tornado.websocket import WebSocketHandler
@@ -89,7 +89,7 @@ def serialize_msg_to_ws_v1(msg_or_list, channel, pack=None):
8989
else:
9090
msg_list = msg_or_list
9191
channel = channel.encode("utf-8")
92-
offsets: List[Any] = []
92+
offsets: list[Any] = []
9393
offsets.append(8 * (1 + 1 + len(msg_list) + 1))
9494
offsets.append(len(channel) + offsets[-1])
9595
for msg in msg_list:
@@ -173,7 +173,7 @@ def handle_incoming_message(self, incoming_msg: str) -> None:
173173
"""Handle an incoming message."""
174174
raise NotImplementedError
175175

176-
def handle_outgoing_message(self, stream: str, outgoing_msg: List[Any]) -> None:
176+
def handle_outgoing_message(self, stream: str, outgoing_msg: list[Any]) -> None:
177177
"""Handle an outgoing message."""
178178
raise NotImplementedError
179179

jupyter_server/services/sessions/sessionmanager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import pathlib
77
import uuid
8-
from typing import Any, Dict, List, NewType, Optional, Union, cast
8+
from typing import Any, NewType, Optional, Union, cast
99

1010
KernelName = NewType("KernelName", str)
1111
ModelName = NewType("ModelName", str)
@@ -100,7 +100,7 @@ class KernelSessionRecordList:
100100
it will be appended.
101101
"""
102102

103-
_records: List[KernelSessionRecord]
103+
_records: list[KernelSessionRecord]
104104

105105
def __init__(self, *records: KernelSessionRecord):
106106
"""Initialize a record list."""
@@ -267,7 +267,7 @@ async def create_session(
267267
type: Optional[str] = None,
268268
kernel_name: Optional[KernelName] = None,
269269
kernel_id: Optional[str] = None,
270-
) -> Dict[str, Any]:
270+
) -> dict[str, Any]:
271271
"""Creates a session and returns its model
272272
273273
Parameters
@@ -291,11 +291,11 @@ async def create_session(
291291
session_id, path=path, name=name, type=type, kernel_id=kernel_id
292292
)
293293
self._pending_sessions.remove(record)
294-
return cast(Dict[str, Any], result)
294+
return cast(dict[str, Any], result)
295295

296296
def get_kernel_env(
297297
self, path: Optional[str], name: Optional[ModelName] = None
298-
) -> Dict[str, str]:
298+
) -> dict[str, str]:
299299
"""Return the environment variables that need to be set in the kernel
300300
301301
Parameters

tests/auth/test_authorizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
import json
55
import os
6-
from typing import Awaitable
6+
from collections.abc import Awaitable
77

88
import pytest
99
from jupyter_client.kernelspec import NATIVE_KERNEL_NAME

tests/services/api/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Awaitable, Dict, List
2+
from collections.abc import Awaitable
33
from unittest import mock
44

55
import pytest
@@ -31,7 +31,7 @@ async def test_get_status(jp_fetch):
3131

3232

3333
class MockUser(User):
34-
permissions: Dict[str, List[str]]
34+
permissions: dict[str, list[str]]
3535

3636

3737
class MockIdentityProvider(IdentityProvider):

tests/services/contents/test_manager.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import time
55
from itertools import combinations
6-
from typing import Dict, Optional, Tuple
6+
from typing import Optional
77
from unittest.mock import patch
88

99
import pytest
@@ -112,7 +112,7 @@ def add_invalid_cell(notebook):
112112

113113
async def prepare_notebook(
114114
jp_contents_manager: FileContentsManager, make_invalid: Optional[bool] = False
115-
) -> Tuple[Dict, str]:
115+
) -> tuple[dict, str]:
116116
cm = jp_contents_manager
117117
model = await ensure_async(cm.new_untitled(type="notebook"))
118118
name = model["name"]
@@ -983,9 +983,10 @@ async def test_nb_validation(jp_contents_manager):
983983
# successful methods and ensure that calls to the aliased "validate_nb" are
984984
# zero. Note that since patching side-effects the validation error case, we'll
985985
# skip call-count assertions for that portion of the test.
986-
with patch("nbformat.validate") as mock_validate, patch(
987-
"jupyter_server.services.contents.manager.validate_nb"
988-
) as mock_validate_nb:
986+
with (
987+
patch("nbformat.validate") as mock_validate,
988+
patch("jupyter_server.services.contents.manager.validate_nb") as mock_validate_nb,
989+
):
989990
# Valid notebook, save, then get
990991
model = await ensure_async(cm.save(model, path))
991992
assert "message" not in model

tests/test_gateway.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from http.cookies import SimpleCookie
1111
from io import BytesIO
1212
from queue import Empty
13-
from typing import Any, Dict, Union
13+
from typing import Any, Union
1414
from unittest.mock import MagicMock, patch
1515

1616
import pytest
@@ -74,7 +74,7 @@ def generate_kernelspec(name):
7474
#
7575
# This is used to simulate inconsistency in list results from the Gateway server
7676
# due to issues like race conditions, bugs, etc.
77-
omitted_kernels: Dict[str, bool] = {}
77+
omitted_kernels: dict[str, bool] = {}
7878

7979

8080
def generate_model(name):

tests/test_serverapp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ async def test_generate_config(tmp_path, jp_configurable_serverapp):
154154

155155
def test_server_password(tmp_path, jp_configurable_serverapp):
156156
password = "secret"
157-
with patch.dict("os.environ", {"JUPYTER_CONFIG_DIR": str(tmp_path)}), patch.object(
158-
getpass, "getpass", return_value=password
157+
with (
158+
patch.dict("os.environ", {"JUPYTER_CONFIG_DIR": str(tmp_path)}),
159+
patch.object(getpass, "getpass", return_value=password),
159160
):
160161
app = JupyterPasswordApp(log_level=logging.ERROR)
161162
app.initialize([])

0 commit comments

Comments
 (0)