Merge pull request #1004 from LeastAuthority/3638.mypy-vs-allmydata-scripts

Fix src/allmydata/scripts/ mypy errors

Fixes: ticket:3638
This commit is contained in:
Jean-Paul Calderone 2021-03-23 16:06:33 -04:00 committed by GitHub
commit 5b7f0f2477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 12 deletions

0
newsfragments/3638.minor Normal file
View File

View File

@ -14,7 +14,11 @@ import os
import json
try:
from allmydata.scripts.types_ import SubCommands
from allmydata.scripts.types_ import (
SubCommands,
Parameters,
Flags,
)
except ImportError:
pass
@ -57,29 +61,29 @@ WHERE_OPTS = [
"Hostname to automatically set --location/--port when --listen=tcp"),
("listen", None, "tcp",
"Comma-separated list of listener types (tcp,tor,i2p,none)."),
]
] # type: Parameters
TOR_OPTS = [
("tor-control-port", None, None,
"Tor's control port endpoint descriptor string (e.g. tcp:127.0.0.1:9051 or unix:/var/run/tor/control)"),
("tor-executable", None, None,
"The 'tor' executable to run (default is to search $PATH)."),
]
] # type: Parameters
TOR_FLAGS = [
("tor-launch", None, "Launch a tor instead of connecting to a tor control port."),
]
] # type: Flags
I2P_OPTS = [
("i2p-sam-port", None, None,
"I2P's SAM API port endpoint descriptor string (e.g. tcp:127.0.0.1:7656)"),
("i2p-executable", None, None,
"(future) The 'i2prouter' executable to run (default is to search $PATH)."),
]
] # type: Parameters
I2P_FLAGS = [
("i2p-launch", None, "(future) Launch an I2P router instead of connecting to a SAM API port."),
]
] # type: Flags
def validate_where_options(o):
if o['listen'] == "none":
@ -185,7 +189,7 @@ class CreateClientOptions(_CreateBaseOptions):
("shares-happy", None, 7, "How many servers new files must be placed on."),
("shares-total", None, 10, "Total shares required for uploaded files."),
("join", None, None, "Join a grid with the given Invite Code."),
]
] # type: Parameters
# This is overridden in order to ensure we get a "Wrong number of
# arguments." error when more than one argument is given.

View File

@ -122,7 +122,7 @@ class FakeTransport(object):
disconnecting = False
class DeepCheckOutput(LineOnlyReceiver, object):
delimiter = "\n"
delimiter = b"\n"
def __init__(self, streamer, options):
self.streamer = streamer
self.transport = FakeTransport()
@ -181,7 +181,7 @@ class DeepCheckOutput(LineOnlyReceiver, object):
% (self.num_objects, self.files_healthy, self.files_unhealthy), file=stdout)
class DeepCheckAndRepairOutput(LineOnlyReceiver, object):
delimiter = "\n"
delimiter = b"\n"
def __init__(self, streamer, options):
self.streamer = streamer
self.transport = FakeTransport()

View File

@ -13,7 +13,7 @@ class FakeTransport(object):
disconnecting = False
class ManifestStreamer(LineOnlyReceiver, object):
delimiter = "\n"
delimiter = b"\n"
def __init__(self):
self.transport = FakeTransport()

View File

@ -5,14 +5,16 @@ Type definitions used by modules in this package.
# Python 3 only
from typing import List, Tuple, Type, Sequence, Any
from allmydata.scripts.common import BaseOptions
from twisted.python.usage import Options
# Historically, subcommands were implemented as lists, but due to a
# [designed contraint in mypy](https://stackoverflow.com/a/52559625/70170),
# a Tuple is required.
SubCommand = Tuple[str, None, Type[BaseOptions], str]
SubCommand = Tuple[str, None, Type[Options], str]
SubCommands = List[SubCommand]
Parameters = List[Sequence[Any]]
Flags = List[Tuple[str, None, str]]