Skip to content

Commit b8d5528

Browse files
committed
Apply more fixes/add noqa based on judgment
1 parent c7ec378 commit b8d5528

File tree

22 files changed

+35
-42
lines changed

22 files changed

+35
-42
lines changed

examples/authorization/jupyter_nbclassic_readonly_config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class ReadOnly(Authorizer):
88

99
def is_authorized(self, handler, user, action, resource):
1010
"""Only allows `read` operations."""
11-
if action != "read":
12-
return False
13-
return True
11+
return action == "read"
1412

1513

1614
c.ServerApp.authorizer_class = ReadOnly # type:ignore[name-defined]

examples/authorization/jupyter_nbclassic_rw_config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class ReadWriteOnly(Authorizer):
88

99
def is_authorized(self, handler, user, action, resource):
1010
"""Only allows `read` and `write` operations."""
11-
if action not in {"read", "write"}:
12-
return False
13-
return True
11+
return action in {"read", "write"}
1412

1513

1614
c.ServerApp.authorizer_class = ReadWriteOnly # type:ignore[name-defined]

examples/authorization/jupyter_temporary_config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class TemporaryServerPersonality(Authorizer):
88

99
def is_authorized(self, handler, user, action, resource):
1010
"""Allow everything but write on contents"""
11-
if action == "write" and resource == "contents":
12-
return False
13-
return True
11+
return not (action == "write" and resource == "contents")
1412

1513

1614
c.ServerApp.authorizer_class = TemporaryServerPersonality # type:ignore[name-defined]

jupyter_server/base/handlers.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import warnings
1616
from collections.abc import Awaitable, Coroutine, Sequence
1717
from http.client import responses
18-
from logging import Logger
1918
from typing import TYPE_CHECKING, Any, cast
2019
from urllib.parse import urlparse
2120

@@ -44,6 +43,8 @@
4443
)
4544

4645
if TYPE_CHECKING:
46+
from logging import Logger
47+
4748
from jupyter_client.kernelspec import KernelSpecManager
4849
from jupyter_events import EventLogger
4950
from jupyter_server_terminals.terminalmanager import TerminalManager
@@ -774,7 +775,7 @@ def write_error(self, status_code: int, **kwargs: Any) -> None:
774775
# backward-compatibility: traceback field is present,
775776
# but always empty
776777
reply["traceback"] = ""
777-
self.log.warning("wrote error: %r", reply["message"], exc_info=True)
778+
self.log.warning("wrote error: %r", reply["message"])
778779
self.finish(json.dumps(reply))
779780

780781
def get_login_url(self) -> str:
@@ -1055,7 +1056,7 @@ def get_absolute_path(cls, roots: Sequence[str], path: str) -> str:
10551056
log().debug(f"Path {path} served from {abspath}")
10561057
return abspath
10571058

1058-
def validate_absolute_path(self, root: str, absolute_path: str) -> str | None:
1059+
def validate_absolute_path(self, _root: str, absolute_path: str) -> str | None:
10591060
"""check if the file should be served (raises 404, 403, etc.)"""
10601061
if not absolute_path:
10611062
raise web.HTTPError(404)
@@ -1115,7 +1116,7 @@ class FilesRedirectHandler(JupyterHandler):
11151116
"""Handler for redirecting relative URLs to the /files/ handler"""
11161117

11171118
@staticmethod
1118-
async def redirect_to_files(self: Any, path: str) -> None:
1119+
async def redirect_to_files(self: Any, path: str) -> None: # noqa: PLW0211
11191120
"""make redirect logic a reusable static method
11201121
11211122
so it can be called from other handlers.

jupyter_server/extension/handler.py

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

33
from __future__ import annotations
44

5-
from logging import Logger
65
from typing import TYPE_CHECKING, Any, cast
76

8-
from jinja2 import Template
97
from jinja2.exceptions import TemplateNotFound
108

119
from jupyter_server.base.handlers import FileFindHandler
1210

1311
if TYPE_CHECKING:
12+
from logging import Logger
13+
14+
from jinja2 import Template
1415
from traitlets.config import Config
1516

1617
from jupyter_server.extension.application import ExtensionApp

jupyter_server/gateway/gateway_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def gateway_enabled(self):
534534
return bool(self.url is not None and len(self.url) > 0)
535535

536536
# Ensure KERNEL_LAUNCH_TIMEOUT has a default value.
537-
KERNEL_LAUNCH_TIMEOUT = int(os.environ.get("KERNEL_LAUNCH_TIMEOUT", 40))
537+
KERNEL_LAUNCH_TIMEOUT = int(os.environ.get("KERNEL_LAUNCH_TIMEOUT", "40"))
538538

539539
_connection_args: dict[str, ty.Any] # initialized on first use
540540

jupyter_server/kernelspecs/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async def get(self, kernel_name, path, include_body=True):
2929
"""Get a kernelspec resource."""
3030
ksm = self.kernel_spec_manager
3131
if path.lower().endswith(".png"):
32-
self.set_header("Cache-Control", f"max-age={60*60*24*30}")
32+
self.set_header("Cache-Control", f"max-age={60 * 60 * 24 * 30}")
3333
ksm = self.kernel_spec_manager
3434
if hasattr(ksm, "get_kernel_spec_resource"):
3535
# If the kernel spec manager defines a method to get kernelspec resources,

jupyter_server/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _scrub_uri(uri: str, extra_param_keys=None) -> str:
3333
parts = parsed.query.split("&")
3434
changed = False
3535
for i, s in enumerate(parts):
36-
key, sep, value = s.partition("=")
36+
key, sep, _value = s.partition("=")
3737
for substring in scrub_param_keys:
3838
if substring in key:
3939
parts[i] = f"{key}{sep}[secret]"

jupyter_server/nbconvert/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def get(self, format, path):
104104
# give its path to nbconvert.
105105
if hasattr(self.contents_manager, "_get_os_path"):
106106
os_path = self.contents_manager._get_os_path(path)
107-
ext_resources_dir, basename = os.path.split(os_path)
107+
ext_resources_dir, _basename = os.path.split(os_path)
108108
else:
109109
ext_resources_dir = None
110110

jupyter_server/serverapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,7 @@ def _confirm_exit(self) -> None:
24722472
no = _i18n("n")
24732473
sys.stdout.write(_i18n("Shut down this Jupyter server (%s/[%s])? ") % (yes, no))
24742474
sys.stdout.flush()
2475-
r, w, x = select.select([sys.stdin], [], [], 5)
2475+
r, _w, _x = select.select([sys.stdin], [], [], 5)
24762476
if r:
24772477
line = sys.stdin.readline()
24782478
if line.lower().startswith(yes) and no not in line.lower():

0 commit comments

Comments
 (0)