Skip to content

Commit

Permalink
Update types for terminado 0.18 (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Nov 10, 2023
1 parent 8b8f78a commit 554cfb3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ repos:
stages: [manual]
args: ["--install-types", "--non-interactive"]
additional_dependencies:
["traitlets>=5.13", "jupyter_server>=2.10", "terminado>=0.17.1"]
["traitlets>=5.13", "jupyter_server>=2.10", "terminado>=0.18"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.5
Expand Down
6 changes: 3 additions & 3 deletions jupyter_server_terminals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize( # type:ignore[override]
self, name: str, term_manager: NamedTermManager, **kwargs: t.Any
) -> None:
"""Initialize the socket."""
BaseTermSocket.initialize(self, term_manager, **kwargs) # type:ignore[no-untyped-call]
BaseTermSocket.initialize(self, term_manager, **kwargs)
TerminalsMixin.initialize(self, name)

def origin_check(self, origin: t.Any = None) -> bool:
Expand All @@ -50,7 +50,7 @@ async def get(self, *args: t.Any, **kwargs: t.Any) -> None:
elif not self.authorizer.is_authorized(self, user, "execute", self.auth_resource):
raise web.HTTPError(403)

if args[0] not in self.term_manager.terminals:
if args[0] not in self.term_manager.terminals: # type:ignore[attr-defined]
raise web.HTTPError(404)
resp = super().get(*args, **kwargs)
if resp is not None:
Expand All @@ -70,4 +70,4 @@ def _update_activity(self) -> None:
self.application.settings["terminal_last_activity"] = utcnow()
# terminal may not be around on deletion/cull
if self.term_name in self.terminal_manager.terminals:
self.terminal_manager.terminals[self.term_name].last_activity = utcnow()
self.terminal_manager.terminals[self.term_name].last_activity = utcnow() # type:ignore[attr-defined]
10 changes: 5 additions & 5 deletions jupyter_server_terminals/terminalmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class TerminalManager(LoggingConfigurable, NamedTermManager): # type:ignore[mis
# -------------------------------------------------------------------------
def create(self, **kwargs: t.Any) -> MODEL:
"""Create a new terminal."""
name, term = self.new_named_terminal(**kwargs) # type:ignore[no-untyped-call]
name, term = self.new_named_terminal(**kwargs)
# Monkey-patch last-activity, similar to kernels. Should we need
# more functionality per terminal, we can look into possible sub-
# classing or containment then.
term.last_activity = utcnow()
term.last_activity = utcnow() # type:ignore[attr-defined]
model = self.get_terminal_model(name)
# Increase the metric by one because a new terminal was created
RUNNING_TOTAL.inc()
Expand All @@ -76,7 +76,7 @@ def list(self) -> list[MODEL]: # noqa
async def terminate(self, name: str, force: bool = False) -> None:
"""Terminate terminal 'name'."""
self._check_terminal(name)
await super().terminate(name, force=force) # type:ignore[no-untyped-call]
await super().terminate(name, force=force)

# Decrease the metric below by one
# because a terminal has been shutdown
Expand All @@ -96,7 +96,7 @@ def get_terminal_model(self, name: str) -> MODEL:
term = self.terminals[name]
model = {
"name": name,
"last_activity": isoformat(term.last_activity),
"last_activity": isoformat(term.last_activity), # type:ignore[attr-defined]
}
return model

Expand Down Expand Up @@ -153,7 +153,7 @@ async def _cull_inactive_terminal(self, name: str) -> None:
except KeyError:
return # KeyErrors are somewhat expected since the terminal can be terminated as the culling check is made.

self.log.debug("name=%s, last_activity=%s", name, term.last_activity)
self.log.debug("name=%s, last_activity=%s", name, term.last_activity) # type:ignore[attr-defined]
if hasattr(term, "last_activity"):
dt_now = utcnow()
dt_inactive = dt_now - term.last_activity
Expand Down

0 comments on commit 554cfb3

Please sign in to comment.