Fix some mypy errors.

This commit is contained in:
Itamar Turner-Trauring 2023-06-14 16:50:02 -04:00
parent 11e0151838
commit 55d62d609b
3 changed files with 12 additions and 5 deletions

View File

@ -86,6 +86,8 @@ from allmydata.util.encodingutil import (
) )
from allmydata.util import abbreviate from allmydata.util import abbreviate
from allmydata.crypto.rsa import PrivateKey, PublicKey, create_signing_keypair_from_string from allmydata.crypto.rsa import PrivateKey, PublicKey, create_signing_keypair_from_string
from ..webish import TahoeLAFSRequest
class WebError(Exception): class WebError(Exception):
def __init__(self, text, code=http.BAD_REQUEST): 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. :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): if isinstance(argname, str):
argname_bytes = argname.encode("utf-8") argname_bytes = argname.encode("utf-8")
else: else:
argname_bytes = argname argname_bytes = argname
results = [] results : list[bytes] = []
if argname_bytes in req.args: if req.args is not None and argname_bytes in req.args:
results.extend(req.args[argname_bytes]) results.extend(req.args[argname_bytes])
argname_unicode = str(argname_bytes, "utf-8") argname_unicode = str(argname_bytes, "utf-8")
if req.fields and argname_unicode in req.fields: if req.fields and argname_unicode in req.fields:

View File

@ -43,8 +43,9 @@ DAY = 24*HOUR
class OphandleTable(resource.Resource, service.Service): class OphandleTable(resource.Resource, service.Service):
"""Renders /operations/%d.""" """Renders /operations/%d."""
# The type in Twisted for services is wrong in 22.10...
name = "operations" # https://github.com/twisted/twisted/issues/10135
name = "operations" # type: ignore[assignment]
UNCOLLECTED_HANDLE_LIFETIME = 4*DAY UNCOLLECTED_HANDLE_LIFETIME = 4*DAY
COLLECTED_HANDLE_LIFETIME = 1*DAY COLLECTED_HANDLE_LIFETIME = 1*DAY

View File

@ -242,7 +242,9 @@ class TahoeLAFSSite(Site, object):
class WebishServer(service.MultiService): 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, def __init__(self, client, webport, tempdir, nodeurl_path=None, staticdir=None,
clock=None, now_fn=time.time): clock=None, now_fn=time.time):