Skip to content

Commit 4513527

Browse files
authored
Update ruff (#1230)
1 parent c71320a commit 4513527

File tree

18 files changed

+64
-71
lines changed

18 files changed

+64
-71
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ repos:
3535
- id: black
3636

3737
- repo: https://github.com/charliermarsh/ruff-pre-commit
38-
rev: v0.0.242
38+
rev: v0.0.254
3939
hooks:
4040
- id: ruff
4141
args: ["--fix"]

jupyter_server/auth/identity.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,11 @@ def validate_security(
520520
f"{warning} and not using authentication. "
521521
"This is highly insecure and not recommended."
522522
)
523-
else:
524-
if not self.auth_enabled:
525-
app.log.warning(
526-
"All authentication is disabled."
527-
" Anyone who can connect to this server will be able to run code."
528-
)
523+
elif not self.auth_enabled:
524+
app.log.warning(
525+
"All authentication is disabled."
526+
" Anyone who can connect to this server will be able to run code."
527+
)
529528

530529
def process_login_form(self, handler: JupyterHandler) -> User | None:
531530
"""Process login form data

jupyter_server/auth/login.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,11 @@ def validate_security(cls, app, ssl_options=None):
258258
f"{warning} and not using authentication. "
259259
"This is highly insecure and not recommended."
260260
)
261-
else:
262-
if not app.password and not app.token:
263-
app.log.warning(
264-
"All authentication is disabled."
265-
" Anyone who can connect to this server will be able to run code."
266-
)
261+
elif not app.password and not app.token:
262+
app.log.warning(
263+
"All authentication is disabled."
264+
" Anyone who can connect to this server will be able to run code."
265+
)
267266

268267
@classmethod
269268
def password_from_settings(cls, settings):

jupyter_server/base/handlers.py

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

5353
def json_sys_info():
5454
"""Get sys info as json."""
55-
global _sys_info_cache
55+
global _sys_info_cache # noqa
5656
if _sys_info_cache is None:
5757
_sys_info_cache = json.dumps(get_sys_info())
5858
return _sys_info_cache
@@ -681,8 +681,8 @@ def write_error(self, status_code, **kwargs):
681681
# get the custom message, if defined
682682
try:
683683
message = exception.log_message % exception.args
684-
except Exception:
685-
pass # noqa
684+
except Exception: # noqa
685+
pass
686686

687687
# construct the custom reason, if defined
688688
reason = getattr(exception, "reason", "")

jupyter_server/config_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ def remove_defaults(data, defaults):
4141
remove_defaults(data[key], defaults[key])
4242
if not data[key]: # prune empty subdicts
4343
del data[key]
44-
else:
45-
if value == defaults[key]:
46-
del data[key]
44+
elif value == defaults[key]:
45+
del data[key]
4746

4847

4948
class BaseJSONConfigManager(LoggingConfigurable):

jupyter_server/extension/application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ def _default_serverapp(self):
214214
if ServerApp.initialized():
215215
try:
216216
return ServerApp.instance()
217-
except Exception:
217+
except Exception: # noqa
218218
# error retrieving instance, e.g. MultipleInstanceError
219-
pass # noqa
219+
pass
220220

221221
# serverapp accessed before it was defined,
222222
# declare an empty one

jupyter_server/files/handlers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ async def get(self, path, include_body=True):
7777
self.set_header("Content-Type", "application/octet-stream")
7878
elif cur_mime is not None:
7979
self.set_header("Content-Type", cur_mime)
80+
elif model["format"] == "base64":
81+
self.set_header("Content-Type", "application/octet-stream")
8082
else:
81-
if model["format"] == "base64":
82-
self.set_header("Content-Type", "application/octet-stream")
83-
else:
84-
self.set_header("Content-Type", "text/plain; charset=UTF-8")
83+
self.set_header("Content-Type", "text/plain; charset=UTF-8")
8584

8685
if include_body:
8786
if model["format"] == "base64":

jupyter_server/gateway/managers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,9 @@ async def kernel_culled(self, kernel_id: str) -> bool: # typing: ignore
337337
# Note that should the redundant polling be consolidated, or replaced with an event-based
338338
# notification model, this will need to be revisited.
339339
km = self.kernel_manager.get_kernel(kernel_id)
340-
except Exception: # Let exceptions here reflect culled kernel
341-
pass # noqa
340+
except Exception: # noqa
341+
# Let exceptions here reflect culled kernel
342+
pass
342343
return km is None
343344

344345

jupyter_server/serverapp.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,14 +1183,13 @@ def _warn_deprecated_config(self, change, clsname, new_name=None):
11831183
f"ServerApp.{change.name} config is deprecated in 2.0. Use {clsname}.{new_name}."
11841184
)
11851185
self.config[clsname][new_name] = change.new
1186-
else:
1187-
# Deprecated config used, new config also used.
1188-
# Warn only if the values differ.
1189-
# If the values are the same, assume intentional backward-compatible config.
1190-
if self.config[clsname][new_name] != change.new:
1191-
self.log.warning(
1192-
f"Ignoring deprecated ServerApp.{change.name} config. Using {clsname}.{new_name}."
1193-
)
1186+
# Deprecated config used, new config also used.
1187+
# Warn only if the values differ.
1188+
# If the values are the same, assume intentional backward-compatible config.
1189+
elif self.config[clsname][new_name] != change.new:
1190+
self.log.warning(
1191+
f"Ignoring deprecated ServerApp.{change.name} config. Using {clsname}.{new_name}."
1192+
)
11941193

11951194
@observe("password")
11961195
def _deprecated_password(self, change):

jupyter_server/services/contents/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _validate_preferred_dir(self, proposal):
104104
if value != self.parent.preferred_dir:
105105
self.parent.preferred_dir = os.path.join(self.root_dir, *value.split("/"))
106106
except (AttributeError, TraitError):
107-
pass # noqa
107+
pass
108108
return value
109109

110110
allow_hidden = Bool(False, config=True, help="Allow access to hidden files")

0 commit comments

Comments
 (0)