Skip to content

Commit

Permalink
Strip unnecessary # noqas
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Oct 22, 2020
1 parent de08b09 commit c1ec888
Show file tree
Hide file tree
Showing 37 changed files with 60 additions and 71 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ repos:
hooks:
- id: flake8

- repo: https://github.com/asottile/yesqa
rev: v1.2.2
hooks:
- id: yesqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

if __name__ == "__main__":
sys.exit(
load_entry_point("Twisted", "console_scripts", "twist")() # type: ignore[func-returns-value] # noqa
load_entry_point("Twisted", "console_scripts", "twist")() # type: ignore[func-returns-value]
)
2 changes: 1 addition & 1 deletion src/twisted/_threads/test/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .. import IWorker, Team, createMemoryWorker, AlreadyQuit


class ContextualWorker(proxyForInterface(IWorker, "_realWorker")): # type: ignore[misc] # noqa
class ContextualWorker(proxyForInterface(IWorker, "_realWorker")): # type: ignore[misc]
"""
A worker implementation that supplies a context.
"""
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 @@ -42,7 +42,7 @@ class ClientOptions(options.ConchOptions):
["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]]]] # noqa
] # type: List[List[Optional[Union[str, int]]]]

compData = usage.Completions(
descriptions={"buffersize": "Size of send/receive buffer (default: 32768)"},
Expand Down Expand Up @@ -779,7 +779,7 @@ def _cbReadFile(self, files, matchedFiles, directory, glob):
return matchedFiles

def _abbrevSize(self, size):
# from http://mail.python.org/pipermail/python-list/1999-December/018395.html # noqa
# from http://mail.python.org/pipermail/python-list/1999-December/018395.html
_abbrevs = [
(1 << 50, "PB"),
(1 << 40, "TB"),
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/ssh/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
decode_dss_signature,
)
except ImportError:
from cryptography.hazmat.primitives.asymmetric.utils import ( # type: ignore[no-redef,attr-defined] # noqa
from cryptography.hazmat.primitives.asymmetric.utils import ( # type: ignore[no-redef,attr-defined]
encode_rfc6979_signature as encode_dss_signature,
decode_rfc6979_signature as decode_dss_signature,
)
Expand Down
8 changes: 3 additions & 5 deletions src/twisted/conch/test/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,7 @@ class BaseSSHTransportBaseCase:
Base case for TransportBase tests.
"""

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


class BaseSSHTransportTests(BaseSSHTransportBaseCase, TransportTestCase):
Expand Down Expand Up @@ -1370,7 +1368,7 @@ class ServerSSHTransportBaseCase(ServerAndClientSSHTransportBaseCase):

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

def setUp(self):
TransportTestCase.setUp(self)
Expand Down Expand Up @@ -1925,7 +1923,7 @@ class ClientSSHTransportBaseCase(ServerAndClientSSHTransportBaseCase):

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

def verifyHostKey(self, pubKey, fingerprint):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/internet/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ class CertificateError(Exception):
errno.ETIMEDOUT: TCPTimedOutError,
}
if hasattr(errno, "WSAECONNREFUSED"):
errnoMapping[errno.WSAECONNREFUSED] = ConnectionRefusedError # type: ignore[attr-defined] # noqa
errnoMapping[errno.WSAENETUNREACH] = NoRouteError # type: ignore[attr-defined] # noqa
errnoMapping[errno.WSAECONNREFUSED] = ConnectionRefusedError # type: ignore[attr-defined]
errnoMapping[errno.WSAENETUNREACH] = NoRouteError # type: ignore[attr-defined]
except ImportError:
errnoMapping = {}

Expand Down
4 changes: 2 additions & 2 deletions src/twisted/internet/iocpreactor/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

# ConnectEx returns these. XXX: find out what it does for timeout
connectExErrors = {
ERROR_CONNECTION_REFUSED: errno.WSAECONNREFUSED, # type: ignore[attr-defined] # noqa
ERROR_NETWORK_UNREACHABLE: errno.WSAENETUNREACH, # type: ignore[attr-defined] # noqa
ERROR_CONNECTION_REFUSED: errno.WSAECONNREFUSED, # type: ignore[attr-defined]
ERROR_NETWORK_UNREACHABLE: errno.WSAENETUNREACH, # type: ignore[attr-defined]
}


Expand Down
2 changes: 1 addition & 1 deletion src/twisted/internet/selectreactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def win32select(r, w, e, timeout=None):


@implementer(IReactorFDSet)
class SelectReactor(posixbase.PosixReactorBase, _extraBase): # type: ignore[misc,valid-type] # noqa
class SelectReactor(posixbase.PosixReactorBase, _extraBase): # type: ignore[misc,valid-type]
"""
A select() based reactor - runs on all POSIX platforms and on Win32.
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/internet/serialport.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ def setRTS(self, on=1):
if platform.isWindows():
from twisted.internet._win32serialport import SerialPort
else:
from twisted.internet._posixserialport import SerialPort # type: ignore[misc] # noqa
from twisted.internet._posixserialport import SerialPort # type: ignore[misc]
2 changes: 1 addition & 1 deletion src/twisted/internet/stdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
from twisted.internet._win32stdio import StandardIO, Win32PipeAddress as PipeAddress

else:
from twisted.internet._posixstdio import StandardIO, PipeAddress # type: ignore[misc] # noqa
from twisted.internet._posixstdio import StandardIO, PipeAddress # type: ignore[misc]

__all__ = ["StandardIO", "PipeAddress"]
2 changes: 1 addition & 1 deletion src/twisted/internet/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def __exit__(self, excType, excValue, traceback):
if platformType == "win32":
_reservedFD = _NullFileDescriptorReservation()
else:
_reservedFD = _FileDescriptorReservation(lambda: open(os.devnull)) # type: ignore[assignment] # noqa
_reservedFD = _FileDescriptorReservation(lambda: open(os.devnull)) # type: ignore[assignment]


# Linux and other UNIX-like operating systems return EMFILE when a
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/internet/test/reactormixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,12 @@ def makeTestCaseClasses(
"""
classes = (
{}
) # type: Dict[str, Union[Type['ReactorBuilder'], Type[SynchronousTestCase]]] # noqa
) # type: Dict[str, Union[Type['ReactorBuilder'], Type[SynchronousTestCase]]]
for reactor in cls._reactors:
shortReactorName = reactor.split(".")[-1]
name = (cls.__name__ + "." + shortReactorName + "Tests").replace(".", "_")

class testcase(cls, SynchronousTestCase): # type: ignore[valid-type,misc] # noqa
class testcase(cls, SynchronousTestCase): # type: ignore[valid-type,misc]
__module__ = cls.__module__
if reactor in cls.skippedReactors:
skip = cls.skippedReactors[reactor]
Expand Down
8 changes: 2 additions & 6 deletions src/twisted/internet/test/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,9 +1500,7 @@ class TCPPortTestsMixin:
Tests for L{IReactorTCP.listenTCP}
"""

requiredInterfaces = (
IReactorTCP,
) # type: Optional[Sequence[Type[Interface]]] # noqa
requiredInterfaces = (IReactorTCP,) # type: Optional[Sequence[Type[Interface]]]

def getExpectedStartListeningLogMessage(self, port, factory):
"""
Expand Down Expand Up @@ -2066,9 +2064,7 @@ class WriteSequenceTestsMixin:
Test for L{twisted.internet.abstract.FileDescriptor.writeSequence}.
"""

requiredInterfaces = (
IReactorTCP,
) # type: Optional[Sequence[Type[Interface]]] # noqa
requiredInterfaces = (IReactorTCP,) # type: Optional[Sequence[Type[Interface]]]

def setWriteBufferSize(self, transport, value):
"""
Expand Down
4 changes: 1 addition & 3 deletions src/twisted/internet/test/test_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@


class TLSMixin:
requiredInterfaces = [
IReactorSSL
] # type: Optional[Sequence[Type[Interface]]] # noqa
requiredInterfaces = [IReactorSSL] # type: Optional[Sequence[Type[Interface]]]

if platform.isWindows():
msg = (
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/internet/test/test_udp_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from twisted.python.runtime import platformType

if platformType == "win32":
from errno import WSAEWOULDBLOCK as EWOULDBLOCK # type: ignore[attr-defined] # noqa
from errno import WSAEWOULDBLOCK as EWOULDBLOCK # type: ignore[attr-defined]
else:
from errno import EWOULDBLOCK

Expand Down
6 changes: 2 additions & 4 deletions src/twisted/internet/test/test_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ class SocketUNIXMixin:
requiredInterfaces = (
IReactorUNIX,
IReactorSocket,
) # type: Optional[Sequence[Type[Interface]]] # noqa
) # type: Optional[Sequence[Type[Interface]]]

def getListeningPort(self, reactor, factory):
"""
Expand Down Expand Up @@ -799,9 +799,7 @@ def connectToListener(self, reactor, address, factory):


class UNIXPortTestsMixin:
requiredInterfaces = (
IReactorUNIX,
) # type: Optional[Sequence[Type[Interface]]] # noqa
requiredInterfaces = (IReactorUNIX,) # type: Optional[Sequence[Type[Interface]]]

def getExpectedStartListeningLogMessage(self, port, factory):
"""
Expand Down
8 changes: 4 additions & 4 deletions src/twisted/mail/test/test_pop3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ def test_LISTWithBadArgument(self):
"""
return CommandMixin.test_LISTWithBadArgument(self)

test_LISTWithBadArgument.suppress = [_listMessageSuppression] # type: ignore[attr-defined] # noqa
test_LISTWithBadArgument.suppress = [_listMessageSuppression] # type: ignore[attr-defined]

def test_UIDLWithBadArgument(self):
"""
Expand All @@ -1432,7 +1432,7 @@ def test_UIDLWithBadArgument(self):
"""
return CommandMixin.test_UIDLWithBadArgument(self)

test_UIDLWithBadArgument.suppress = [_getUidlSuppression] # type: ignore[attr-defined] # noqa
test_UIDLWithBadArgument.suppress = [_getUidlSuppression] # type: ignore[attr-defined]

def test_TOPWithBadArgument(self):
"""
Expand All @@ -1442,7 +1442,7 @@ def test_TOPWithBadArgument(self):
"""
return CommandMixin.test_TOPWithBadArgument(self)

test_TOPWithBadArgument.suppress = [_listMessageSuppression] # type: ignore[attr-defined] # noqa
test_TOPWithBadArgument.suppress = [_listMessageSuppression] # type: ignore[attr-defined]

def test_RETRWithBadArgument(self):
"""
Expand All @@ -1452,7 +1452,7 @@ def test_RETRWithBadArgument(self):
"""
return CommandMixin.test_RETRWithBadArgument(self)

test_RETRWithBadArgument.suppress = [_listMessageSuppression] # type: ignore[attr-defined] # noqa
test_RETRWithBadArgument.suppress = [_listMessageSuppression] # type: ignore[attr-defined]


class ValueErrorCommandTests(CommandMixin, unittest.TestCase):
Expand Down
4 changes: 1 addition & 3 deletions src/twisted/pair/tuntap.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ def __init__(self, interface, proto, maxPacketSize=8192, reactor=None, system=No
self.logstr = "%s (%s)" % (logPrefix, self._mode.name)

def __repr__(self) -> str:
args = (
fullyQualifiedName(self.protocol.__class__),
) # type: Tuple[str, ...] # noqa
args = (fullyQualifiedName(self.protocol.__class__),) # type: Tuple[str, ...]
if self.connected:
args = args + ("",)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/protocols/amp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ def _massageError(error):
# Python 3 ignores the __metaclass__ attribute and has instead new syntax
# for setting the metaclass. Unfortunately it's not valid Python 2 syntax
# so we work-around it by recreating Command using the metaclass here.
Command = Command.__metaclass__("Command", (Command,), {}) # type: ignore[assignment,misc] # noqa
Command = Command.__metaclass__("Command", (Command,), {}) # type: ignore[assignment,misc]


class _NoCertificate:
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/python/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,4 +1007,4 @@ def portCoerce(value):
return value


portCoerce.coerceDoc = "Must be an int between 0 and 65535." # type: ignore[attr-defined] # noqa
portCoerce.coerceDoc = "Must be an int between 0 and 65535." # type: ignore[attr-defined]
2 changes: 1 addition & 1 deletion src/twisted/python/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ class FancyStrMixin:
"""

# Override in subclasses:
showAttributes = () # type: Sequence[Union[str, Tuple[str, str, str], Tuple[str, Callable]]] # noqa
showAttributes = () # type: Sequence[Union[str, Tuple[str, str, str], Tuple[str, Callable]]]

def __str__(self) -> str:
r = ["<", getattr(self, "fancybasename", self.__class__.__name__)]
Expand Down
10 changes: 3 additions & 7 deletions src/twisted/test/test_amp.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ class Hello(amp.Command):

response = [(b"hello", amp.String()), (b"print", amp.Unicode(optional=True))]

errors = {
UnfriendlyGreeting: b"UNFRIENDLY"
} # type: Dict[Type[Exception], bytes] # noqa
errors = {UnfriendlyGreeting: b"UNFRIENDLY"} # type: Dict[Type[Exception], bytes]

fatalErrors = {DeathThreat: b"DEAD"} # type: Dict[Type[Exception], bytes]

Expand Down Expand Up @@ -2139,9 +2137,7 @@ class BaseCommand(amp.Command):
This provides a command that will be subclassed.
"""

errors = {
InheritedError: b"INHERITED_ERROR"
} # type: Dict[Type[Exception], bytes] # noqa
errors = {InheritedError: b"INHERITED_ERROR"} # type: Dict[Type[Exception], bytes]


class InheritedCommand(BaseCommand):
Expand All @@ -2160,7 +2156,7 @@ class AddErrorsCommand(BaseCommand):
arguments = [(b"other", amp.Boolean())]
errors = {
OtherInheritedError: b"OTHER_INHERITED_ERROR"
} # type: Dict[Type[Exception], bytes] # noqa
} # type: Dict[Type[Exception], bytes]


class NormalCommandProtocol(amp.AMP):
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/test/test_sslverify.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ def test_certificateOptionsSerialization(self):
self.assertTrue(opts.fixBrokenPeers)
self.assertTrue(opts.enableSessionTickets)

test_certificateOptionsSerialization.suppress = [ # type: ignore[attr-defined] # noqa
test_certificateOptionsSerialization.suppress = [ # type: ignore[attr-defined]
util.suppress(
category=DeprecationWarning,
message="twisted\.internet\._sslverify\.*__[gs]etstate__",
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/trial/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import sys

sys.exit(
load_entry_point("Twisted", "console_scripts", "trial")() # type: ignore[func-returns-value] # noqa
load_entry_point("Twisted", "console_scripts", "trial")() # type: ignore[func-returns-value]
)
6 changes: 3 additions & 3 deletions src/twisted/trial/test/detests.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_expectedFailure(self):
d.addCallback(self._cb_error)
return d

test_expectedFailure.todo = "Expected failure" # type: ignore[attr-defined] # noqa
test_expectedFailure.todo = "Expected failure" # type: ignore[attr-defined]


class TimeoutTests(unittest.TestCase):
Expand Down Expand Up @@ -189,13 +189,13 @@ def test_expectedFailure(self):
return defer.Deferred()

test_expectedFailure.timeout = 0.1 # type: ignore[attr-defined]
test_expectedFailure.todo = "i will get it right, eventually" # type: ignore[attr-defined] # noqa
test_expectedFailure.todo = "i will get it right, eventually" # type: ignore[attr-defined]

def test_skip(self):
return defer.Deferred()

test_skip.timeout = 0.1 # type: ignore[attr-defined]
test_skip.skip = "i will get it right, eventually" # type: ignore[attr-defined] # noqa
test_skip.skip = "i will get it right, eventually" # type: ignore[attr-defined]

def test_errorPropagation(self):
def timedOut(err):
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/trial/test/skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def test_todo1(self):
def test_todo2(self):
raise RuntimeError("expected failure")

test_todo2.todo = ((RuntimeError, OSError), "todo2") # type: ignore[attr-defined] # noqa
test_todo2.todo = ((RuntimeError, OSError), "todo2") # type: ignore[attr-defined]

def test_todo3(self):
raise RuntimeError("we had no idea!")
Expand All @@ -209,7 +209,7 @@ def test_todo3(self):
def test_todo4(self):
raise RuntimeError("we had no idea!")

test_todo4.todo = ((OSError, SyntaxError), "todo4") # type: ignore[attr-defined] # noqa
test_todo4.todo = ((OSError, SyntaxError), "todo4") # type: ignore[attr-defined]

def test_todo5(self):
self.fail("deliberate failure")
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/trial/test/suppression.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SuppressionMixin(EmitMixin):
def testSuppressMethod(self):
self._emit()

testSuppressMethod.suppress = [util.suppress(message=METHOD_WARNING_MSG)] # type: ignore[attr-defined] # noqa
testSuppressMethod.suppress = [util.suppress(message=METHOD_WARNING_MSG)] # type: ignore[attr-defined]

def testSuppressClass(self):
self._emit()
Expand Down
Loading

0 comments on commit c1ec888

Please sign in to comment.