From 55d62d609b286f3778bb290f344ef03c652c1176 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 14 Jun 2023 16:50:02 -0400 Subject: [PATCH] Fix some mypy errors. --- src/allmydata/web/common.py | 8 ++++++-- src/allmydata/web/operations.py | 5 +++-- src/allmydata/webish.py | 4 +++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/allmydata/web/common.py b/src/allmydata/web/common.py index bd1e3838e..a8de54c0d 100644 --- a/src/allmydata/web/common.py +++ b/src/allmydata/web/common.py @@ -86,6 +86,8 @@ from allmydata.util.encodingutil import ( ) from allmydata.util import abbreviate from allmydata.crypto.rsa import PrivateKey, PublicKey, create_signing_keypair_from_string +from ..webish import TahoeLAFSRequest + class WebError(Exception): def __init__(self, text, code=http.BAD_REQUEST): @@ -723,13 +725,15 @@ def get_arg(req: IRequest, argname: str | bytes, default: Optional[T] = None, *, :return: Either bytes or tuple of bytes. """ + # This is not... obvious to callers, let's say, but it does happen. + assert isinstance(req, TahoeLAFSRequest) if isinstance(argname, str): argname_bytes = argname.encode("utf-8") else: argname_bytes = argname - results = [] - if argname_bytes in req.args: + results : list[bytes] = [] + if req.args is not None and argname_bytes in req.args: results.extend(req.args[argname_bytes]) argname_unicode = str(argname_bytes, "utf-8") if req.fields and argname_unicode in req.fields: diff --git a/src/allmydata/web/operations.py b/src/allmydata/web/operations.py index aedf33f37..a564f8484 100644 --- a/src/allmydata/web/operations.py +++ b/src/allmydata/web/operations.py @@ -43,8 +43,9 @@ DAY = 24*HOUR class OphandleTable(resource.Resource, service.Service): """Renders /operations/%d.""" - - name = "operations" + # The type in Twisted for services is wrong in 22.10... + # https://github.com/twisted/twisted/issues/10135 + name = "operations" # type: ignore[assignment] UNCOLLECTED_HANDLE_LIFETIME = 4*DAY COLLECTED_HANDLE_LIFETIME = 1*DAY diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 1b2b8192a..ec2582f80 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -242,7 +242,9 @@ class TahoeLAFSSite(Site, object): class WebishServer(service.MultiService): - name = "webish" + # The type in Twisted for services is wrong in 22.10... + # https://github.com/twisted/twisted/issues/10135 + name = "webish" # type: ignore[assignment] def __init__(self, client, webport, tempdir, nodeurl_path=None, staticdir=None, clock=None, now_fn=time.time):