Skip to content

Commit

Permalink
apply com2ann
Browse files Browse the repository at this point in the history
pipx run com2ann --python-minor-version=6 -s src
  • Loading branch information
graingert committed Mar 1, 2021
1 parent cc50c36 commit fa6d53b
Show file tree
Hide file tree
Showing 134 changed files with 325 additions and 327 deletions.
6 changes: 3 additions & 3 deletions src/twisted/application/internet.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _maybeGlobalReactor(maybeReactor):

class _VolatileDataService(service.Service):

volatile = [] # type: List[str]
volatile: List[str] = []

def __getstate__(self):
d = service.Service.__getstate__(self)
Expand Down Expand Up @@ -100,7 +100,7 @@ class _AbstractServer(_VolatileDataService):
"""

volatile = ["_port"]
method = "" # type: str
method: str = ""
reactor = None

_port = None
Expand Down Expand Up @@ -163,7 +163,7 @@ class _AbstractClient(_VolatileDataService):
"""

volatile = ["_connection"]
method = "" # type: str
method: str = ""
reactor = None

_connection = None
Expand Down
10 changes: 5 additions & 5 deletions src/twisted/application/runner/test/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_startLogging(self) -> None:
# running (started by trial) logging system.

class LogBeginner:
observers = [] # type: List[ILogObserver]
observers: List[ILogObserver] = []

def beginLoggingTo(self, observers: Iterable[ILogObserver]) -> None:
LogBeginner.observers = list(observers)
Expand All @@ -227,8 +227,8 @@ def beginLoggingTo(self, observers: Iterable[ILogObserver]) -> None:
# Patch FilteringLogObserver so we can capture its arguments

class MockFilteringLogObserver(FilteringLogObserver):
observer = None # type: Optional[ILogObserver]
predicates = [] # type: List[LogLevelFilterPredicate]
observer: Optional[ILogObserver] = None
predicates: List[LogLevelFilterPredicate] = []

def __init__(
self,
Expand All @@ -247,7 +247,7 @@ def __init__(
# Patch FileLogObserver so we can capture its arguments

class MockFileLogObserver(FileLogObserver):
outFile = None # type: Optional[TextIO]
outFile: Optional[TextIO] = None

def __init__(self, outFile: TextIO) -> None:
MockFileLogObserver.outFile = outFile
Expand Down Expand Up @@ -426,7 +426,7 @@ class DummyKill:
"""

def __init__(self) -> None:
self.calls = [] # type: List[Tuple[int, int]]
self.calls: List[Tuple[int, int]] = []

def __call__(self, pid: int, sig: int) -> None:
self.calls.append((pid, sig))
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/application/twist/test/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def patchOpen(self) -> None:
"""
Patch L{_options.open} so we can capture usage and prevent actual opens.
"""
self.opened = [] # type: List[Tuple[str, Optional[str]]]
self.opened: List[Tuple[str, Optional[str]]] = []

def fakeOpen(name: str, mode: Optional[str] = None) -> object:
if name == "nocanopen":
Expand All @@ -61,7 +61,7 @@ def patchInstallReactor(self) -> None:
Patch C{_options.installReactor} so we can capture usage and prevent
actual installs.
"""
self.installedReactors = {} # type: Dict[str, IReactorCore]
self.installedReactors: Dict[str, IReactorCore] = {}

def installReactor(name: str) -> IReactorCore:
if name != "fusion":
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/application/twist/test/test_twist.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def patchInstallReactor(self) -> None:
Patch C{_options.installReactor} so we can capture usage and prevent
actual installs.
"""
self.installedReactors = {} # type: Dict[str, IReactorCore]
self.installedReactors: Dict[str, IReactorCore] = {}

def installReactor(_: TwistOptions, name: str) -> IReactorCore:
reactor = MemoryReactor()
Expand All @@ -57,7 +57,7 @@ def patchStartService(self) -> None:
Patch L{MultiService.startService} so we can capture usage and prevent
actual starts.
"""
self.serviceStarts = [] # type: List[IService]
self.serviceStarts: List[IService] = []

def startService(service: IService) -> None:
self.serviceStarts.append(service)
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/conch/client/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ConchOptions(usage.Options):

optParameters = [
optParameters: List[List[Optional[Union[str, int]]]] = [
["user", "l", None, "Log in using this user name."],
["identity", "i", None],
["ciphers", "c", None],
Expand All @@ -22,7 +22,7 @@ class ConchOptions(usage.Options):
["known-hosts", "", None, "File to check for host keys"],
["user-authentications", "", None, "Types of user authentications to use."],
["logfile", "", None, "File to log to, or - for stdout"],
] # type: List[List[Optional[Union[str, int]]]]
]

optFlags = [
["version", "V", "Display version number only."],
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/conch/manhole_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def requestAvatar(self, avatarId, mind, *interfaces):


class ConchFactory(factory.SSHFactory):
publicKeys = {} # type: Dict[bytes, bytes]
privateKeys = {} # type: Dict[bytes, bytes]
publicKeys: Dict[bytes, bytes] = {}
privateKeys: Dict[bytes, bytes] = {}

def __init__(self, portal):
self.portal = portal
2 changes: 1 addition & 1 deletion src/twisted/conch/recvline.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from twisted.python.compat import iterbytes
from twisted.logger import Logger

_counters = {} # type: Dict[str, int]
_counters: Dict[str, int] = {}


class Logging:
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/conch/scripts/cftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class ClientOptions(options.ConchOptions):
"executing commands to send and receive file information"
)

optParameters = [
optParameters: List[List[Optional[Union[str, int]]]] = [
["buffersize", "B", 32768, "Size of the buffer to use for sending/receiving."],
["batchfile", "b", None, "File to read commands from, or '-' for stdin."],
["requests", "R", 5, "Number of requests to make before waiting for a reply."],
["subsystem", "s", "sftp", "Subsystem/server program to connect to."],
] # type: List[List[Optional[Union[str, int]]]]
]

compData = usage.Completions(
descriptions={"buffersize": "Size of send/receive buffer (default: 32768)"},
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/conch/scripts/conch.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class ClientOptions(ConchOptions):
],
)

localForwards = [] # type: List[Tuple[int, Tuple[int, int]]]
remoteForwards = [] # type: List[Tuple[int, Tuple[int, int]]]
localForwards: List[Tuple[int, Tuple[int, int]]] = []
remoteForwards: List[Tuple[int, Tuple[int, int]]] = []

def opt_escape(self, esc):
"""
Expand Down
8 changes: 4 additions & 4 deletions src/twisted/conch/scripts/tkconch.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ class GeneralOptions(usage.Options):
],
)

identitys = [] # type: List[str]
localForwards = [] # type: List[Tuple[int, Tuple[int, int]]]
remoteForwards = [] # type: List[Tuple[int, Tuple[int, int]]]
identitys: List[str] = []
localForwards: List[Tuple[int, Tuple[int, int]]] = []
remoteForwards: List[Tuple[int, Tuple[int, int]]] = []

def opt_identity(self, i):
self.identitys.append(i)
Expand Down Expand Up @@ -499,7 +499,7 @@ def connectionSecure(self):


class SSHUserAuthClient(userauth.SSHUserAuthClient):
usedFiles = [] # type: List[str]
usedFiles: List[str] = []

def getPassword(self, prompt=None):
if not prompt:
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/ssh/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SSHChannel(log.Logger):
"""

_log = Logger()
name = None # type: bytes # only needed for client channels
name: bytes = None # only needed for client channels

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/ssh/filetransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FileTransferBase(protocol.Protocol):

versions = (3,)

packetTypes = {} # type: Dict[int, str]
packetTypes: Dict[int, str] = {}

def __init__(self):
self.buf = b""
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/conch/ssh/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@


class SSHService:
name = None # type: bytes # this is the ssh name for the service
protocolMessages = {} # type: Dict[int, str] # map #'s -> protocol names
name: bytes = None # this is the ssh name for the service
protocolMessages: Dict[int, str] = {} # map #'s -> protocol names
transport = None # gets set later

_log = Logger()
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/test/test_insults.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def testByte%(groupName)s(self):


class ByteGroupingsMixin(MockMixin):
protocolFactory = None # type: Optional[Type[Protocol]]
protocolFactory: Optional[Type[Protocol]] = None

for word, n in [
("Pairs", 2),
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/test/test_manhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import traceback
from typing import Optional

ssh = None # type: Optional[bool]
ssh: Optional[bool] = None

from twisted.trial import unittest
from twisted.internet import error, defer
Expand Down
12 changes: 4 additions & 8 deletions src/twisted/conch/test/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class TransportTestCase(TestCase):
Base class for transport test cases.
"""

klass = None # type: Optional[Type[transport.SSHTransportBase]]
klass: Optional[Type[transport.SSHTransportBase]] = None

if dependencySkip:
skip = dependencySkip
Expand Down Expand Up @@ -462,7 +462,7 @@ class BaseSSHTransportBaseCase:
Base case for TransportBase tests.
"""

klass = MockTransportBase # type: Optional[Type[transport.SSHTransportBase]]
klass: Optional[Type[transport.SSHTransportBase]] = MockTransportBase


class BaseSSHTransportTests(BaseSSHTransportBaseCase, TransportTestCase):
Expand Down Expand Up @@ -1366,9 +1366,7 @@ class ServerSSHTransportBaseCase(ServerAndClientSSHTransportBaseCase):
Base case for SSHServerTransport tests.
"""

klass = (
transport.SSHServerTransport
) # type: Optional[Type[transport.SSHTransportBase]]
klass: Optional[Type[transport.SSHTransportBase]] = transport.SSHServerTransport

def setUp(self):
TransportTestCase.setUp(self)
Expand Down Expand Up @@ -1921,9 +1919,7 @@ class ClientSSHTransportBaseCase(ServerAndClientSSHTransportBaseCase):
Base case for SSHClientTransport tests.
"""

klass = (
transport.SSHClientTransport
) # type: Optional[Type[transport.SSHTransportBase]]
klass: Optional[Type[transport.SSHTransportBase]] = transport.SSHClientTransport

def verifyHostKey(self, pubKey, fingerprint):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/test/test_userauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from twisted.python.reflect import requireModule
from twisted.trial import unittest

keys = None # type: Optional[ModuleType]
keys: Optional[ModuleType] = None
if requireModule("cryptography") and requireModule("pyasn1"):
from twisted.conch.ssh.common import NS
from twisted.conch.checkers import SSHProtocolChecker
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/cred/strcred.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class AuthOptionMixin:
will send all help-related output. Default: L{sys.stdout}
"""

supportedInterfaces = None # type: Optional[Sequence[Type[Interface]]]
supportedInterfaces: Optional[Sequence[Type[Interface]]] = None
authOutput = sys.stdout

def supportsInterface(self, interface):
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/cred/test/test_strcred.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ class OptionsSupportsAllInterfaces(usage.Options, strcred.AuthOptionMixin):


class OptionsSupportsNoInterfaces(usage.Options, strcred.AuthOptionMixin):
supportedInterfaces = [] # type: Sequence[Type[Interface]]
supportedInterfaces: Sequence[Type[Interface]] = []


class LimitingInterfacesTests(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/internet/_baseprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@


class BaseProcess:
pid = None # type: Optional[int]
status = None # type: Optional[int]
pid: Optional[int] = None
status: Optional[int] = None
lostProcess = 0
proto = None

Expand Down
2 changes: 1 addition & 1 deletion src/twisted/internet/_producer_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


# This module exports nothing public, it's for internal Twisted use only.
__all__ = [] # type: List[str]
__all__: List[str] = []


@implementer(IPushProducer)
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/internet/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def __init__(self, reactor: Optional[interfaces.IReactorFDSet] = None):
reactor = _reactor # type: ignore[assignment]
self.reactor = reactor
# will be added to dataBuffer in doWrite
self._tempDataBuffer = [] # type: List[bytes]
self._tempDataBuffer: List[bytes] = []
self._tempDataLen = 0

def connectionLost(self, reason):
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/internet/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class UNIXAddress:
@type name: C{bytes}
"""

name = attr.ib(
name: Optional[bytes] = attr.ib(
converter=attr.converters.optional(_asFilesystemBytes)
) # type: Optional[bytes]
)

if getattr(os.path, "samefile", None) is not None:

Expand Down
8 changes: 4 additions & 4 deletions src/twisted/internet/asyncioreactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class AsyncioSelectorReactor(PosixReactorBase):

def __init__(self, eventloop: Optional[SelectorEventLoop] = None):
if eventloop is None:
_eventloop = get_event_loop() # type: AbstractEventLoop
_eventloop: AbstractEventLoop = get_event_loop()
else:
_eventloop = eventloop

Expand All @@ -59,9 +59,9 @@ def __init__(self, eventloop: Optional[SelectorEventLoop] = None):
if not isinstance(_eventloop, SelectorEventLoop):
raise TypeError(f"SelectorEventLoop required, instead got: {_eventloop}")

self._asyncioEventloop = _eventloop # type: SelectorEventLoop
self._writers = {} # type: Dict[Type[FileDescriptor], int]
self._readers = {} # type: Dict[Type[FileDescriptor], int]
self._asyncioEventloop: SelectorEventLoop = _eventloop
self._writers: Dict[Type[FileDescriptor], int] = {}
self._readers: Dict[Type[FileDescriptor], int] = {}
self._continuousPolling = _ContinuousPolling(self)

self._scheduledAt = None
Expand Down
Loading

0 comments on commit fa6d53b

Please sign in to comment.