Fix mypy errors

This commit is contained in:
Itamar Turner-Trauring 2023-11-21 08:31:34 -05:00
parent c99362f54d
commit 774b4f2861
4 changed files with 9 additions and 6 deletions

View File

@ -11,6 +11,7 @@ from typing import (
Optional,
Union,
List,
IO
)
from twisted.python.filepath import FilePath
@ -178,6 +179,7 @@ def load_grid_manager(config_path: Optional[FilePath]):
:raises: ValueError if the confguration is invalid or IOError if
expected files can't be opened.
"""
config_file: Union[IO[bytes], IO[str]]
if config_path is None:
config_file = sys.stdin
else:

View File

@ -200,14 +200,14 @@ def read_config(basedir, portnumfile, generated_files: Iterable = (), _valid_con
config_path = FilePath(basedir).child("tahoe.cfg")
try:
config_str = config_path.getContent()
config_bytes = config_path.getContent()
except EnvironmentError as e:
if e.errno != errno.ENOENT:
raise
# The file is missing, just create empty ConfigParser.
config_str = u""
else:
config_str = config_str.decode("utf-8-sig")
config_str = config_bytes.decode("utf-8-sig")
return config_from_string(
basedir,

View File

@ -15,7 +15,7 @@ scheduler affinity or cgroups, but that's not the end of the world.
"""
import os
from typing import TypeVar, Callable
from typing import TypeVar, Callable, cast
from functools import partial
import threading
from typing_extensions import ParamSpec
@ -24,8 +24,9 @@ from unittest import TestCase
from twisted.python.threadpool import ThreadPool
from twisted.internet.threads import deferToThreadPool
from twisted.internet import reactor
from twisted.internet.interfaces import IReactorFromThreads
_CPU_THREAD_POOL = ThreadPool(minthreads=0, maxthreads=os.cpu_count(), name="TahoeCPU")
_CPU_THREAD_POOL = ThreadPool(minthreads=0, maxthreads=os.cpu_count() or 1, name="TahoeCPU")
if hasattr(threading, "_register_atexit"):
# This is a private API present in Python 3.8 or later, specifically
# designed for thread pool shutdown. Since it's private, it might go away
@ -64,7 +65,7 @@ async def defer_to_thread(f: Callable[P, R], *args: P.args, **kwargs: P.kwargs)
return f(*args, **kwargs)
# deferToThreadPool has no type annotations...
result = await deferToThreadPool(reactor, _CPU_THREAD_POOL, f, *args, **kwargs)
result = await deferToThreadPool(cast(IReactorFromThreads, reactor), _CPU_THREAD_POOL, f, *args, **kwargs)
return result

View File

@ -874,6 +874,6 @@ def add_static_children(root: IResource):
for child in static_dir.iterdir():
child_path = child.name.encode("utf-8")
root.putChild(child_path, static.File(
temporary_file_manager.enter_context(as_file(child))
str(temporary_file_manager.enter_context(as_file(child)))
))
weakref.finalize(root, temporary_file_manager.close)