From d40407b0e019c4cdd1bf68ecbfef638ec4922540 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Wed, 27 Oct 2021 11:35:13 +0100 Subject: [PATCH 1/3] Run linters on stubs --- .github/workflows/pipeline.yml | 6 +++--- scripts-dev/lint.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index ab1c32e0..199aeaac 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -12,9 +12,9 @@ jobs: with: python-version: '3.6' - run: python -m pip install -e .[dev] - - run: black --check --diff sydent/ tests/ matrix_is_test/ scripts/ setup.py - - run: flake8 sydent/ tests/ matrix_is_test/ scripts/ setup.py - - run: isort --check-only --diff sydent/ tests/ matrix_is_test/ scripts/ setup.py + - run: black --check --diff sydent/ stubs/ tests/ matrix_is_test/ scripts/ setup.py + - run: flake8 sydent/ stubs/ tests/ matrix_is_test/ scripts/ setup.py + - run: isort --check-only --diff sydent/ stubs/ tests/ matrix_is_test/ scripts/ setup.py run-unit-tests: needs: [check-code-style] diff --git a/scripts-dev/lint.sh b/scripts-dev/lint.sh index 53fa80b6..a75ddc58 100755 --- a/scripts-dev/lint.sh +++ b/scripts-dev/lint.sh @@ -1,7 +1,7 @@ #! /usr/bin/env bash set -ex -black sydent/ tests/ matrix_is_test/ scripts/ setup.py -flake8 sydent/ tests/ matrix_is_test/ scripts/ setup.py -isort sydent/ tests/ matrix_is_test/ scripts/ setup.py +black sydent/ stubs/ tests/ matrix_is_test/ scripts/ setup.py +flake8 sydent/ stubs/ tests/ matrix_is_test/ scripts/ setup.py +isort sydent/ stubs/ tests/ matrix_is_test/ scripts/ setup.py mypy From 7c4ce4dc5cb2c677a079dce8f054063e5d1c8694 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Wed, 27 Oct 2021 15:05:38 +0100 Subject: [PATCH 2/3] Reformat stubs --- stubs/twisted/internet/error.pyi | 5 ++--- stubs/twisted/internet/ssl.pyi | 4 +--- stubs/twisted/names/dns.pyi | 7 ++----- stubs/twisted/python/failure.pyi | 12 +++++------- stubs/twisted/python/log.pyi | 6 ++---- stubs/twisted/web/client.pyi | 7 +++---- stubs/twisted/web/http.pyi | 7 ++----- 7 files changed, 17 insertions(+), 31 deletions(-) diff --git a/stubs/twisted/internet/error.pyi b/stubs/twisted/internet/error.pyi index 5a8f459a..0b1862c2 100644 --- a/stubs/twisted/internet/error.pyi +++ b/stubs/twisted/internet/error.pyi @@ -1,5 +1,4 @@ -from typing import Optional, Any - +from typing import Any, Optional class ConnectError(Exception): - def __init__(self, osError: Optional[Any] = None, string: str = ""): ... \ No newline at end of file + def __init__(self, osError: Optional[Any] = None, string: str = ""): ... diff --git a/stubs/twisted/internet/ssl.pyi b/stubs/twisted/internet/ssl.pyi index 62db32bd..3ae991e3 100644 --- a/stubs/twisted/internet/ssl.pyi +++ b/stubs/twisted/internet/ssl.pyi @@ -1,4 +1,4 @@ -from typing import Optional, Any, List, Dict, AnyStr, TypeVar, Type +from typing import Any, AnyStr, Dict, List, Optional, Type, TypeVar import OpenSSL.SSL @@ -6,7 +6,6 @@ import OpenSSL.SSL # anywhere else in twisted. from twisted.internet._sslverify import IOpenSSLTrustRoot from twisted.internet.interfaces import IOpenSSLClientConnectionCreator - from zope.interface import implementer C = TypeVar("C") @@ -37,7 +36,6 @@ def optionsForClientTLS( extraCertificateOptions: Optional[Dict[Any, Any]] = None, ) -> IOpenSSLClientConnectionCreator: ... - # Type safety: I don't want to respecify the methods on the interface that we # don't use. @implementer(IOpenSSLTrustRoot) # type: ignore[misc] diff --git a/stubs/twisted/names/dns.pyi b/stubs/twisted/names/dns.pyi index fe0298b2..70ee78d8 100644 --- a/stubs/twisted/names/dns.pyi +++ b/stubs/twisted/names/dns.pyi @@ -1,14 +1,11 @@ -from typing import ClassVar, Generic, TypeVar, Optional - +from typing import ClassVar, Generic, Optional, TypeVar class Name: name: bytes - def __init__(self, name: bytes = b""): ... SRV: int - class Record_SRV: priority: int weight: int @@ -16,8 +13,8 @@ class Record_SRV: target: Name ttl: int - Payload = TypeVar("Payload") # should be bound to IEncodableRecord + class RRHeader(Generic[Payload]): fmt: ClassVar[str] name: Name diff --git a/stubs/twisted/python/failure.pyi b/stubs/twisted/python/failure.pyi index c1f69ee9..e73ac81e 100644 --- a/stubs/twisted/python/failure.pyi +++ b/stubs/twisted/python/failure.pyi @@ -1,21 +1,19 @@ from types import TracebackType -from typing import Type, Optional, Union, TypeVar, overload +from typing import Optional, Type, TypeVar, Union, overload E = TypeVar("E") - class Failure(BaseException): - def __init__( self, exc_value: Optional[BaseException] = None, exc_type: Optional[Type[BaseException]] = None, exc_tb: Optional[TracebackType] = None, captureVars: bool = False, - ): - ... - + ): ... @overload def check(self, singleErrorType: Type[E]) -> Optional[E]: ... @overload - def check(self, *errorTypes: Union[str, Type[Exception]]) -> Optional[Exception]: ... + def check( + self, *errorTypes: Union[str, Type[Exception]] + ) -> Optional[Exception]: ... diff --git a/stubs/twisted/python/log.pyi b/stubs/twisted/python/log.pyi index 8ba10590..9d9fa686 100644 --- a/stubs/twisted/python/log.pyi +++ b/stubs/twisted/python/log.pyi @@ -1,11 +1,9 @@ -from typing import Optional, Union, Any +from typing import Any, Optional, Union from twisted.python.failure import Failure - def err( _stuff: Union[None, Exception, Failure] = None, _why: Optional[str] = None, **kw: Any, -)-> None: - ... \ No newline at end of file +) -> None: ... diff --git a/stubs/twisted/web/client.pyi b/stubs/twisted/web/client.pyi index dff7dfdc..04fe3cda 100644 --- a/stubs/twisted/web/client.pyi +++ b/stubs/twisted/web/client.pyi @@ -1,16 +1,15 @@ -from typing import BinaryIO, Any, Optional +from typing import Any, BinaryIO, Optional import twisted.internet from twisted.internet.defer import Deferred from twisted.internet.interfaces import ( - IOpenSSLClientConnectionCreator, IConsumer, + IOpenSSLClientConnectionCreator, IProtocol, ) from twisted.internet.task import Cooperator from twisted.web.http_headers import Headers - -from twisted.web.iweb import IResponse, IAgent, IBodyProducer, IPolicyForHTTPS +from twisted.web.iweb import IAgent, IBodyProducer, IPolicyForHTTPS, IResponse from zope.interface import implementer @implementer(IPolicyForHTTPS) diff --git a/stubs/twisted/web/http.pyi b/stubs/twisted/web/http.pyi index dcab10c6..42ad216a 100644 --- a/stubs/twisted/web/http.pyi +++ b/stubs/twisted/web/http.pyi @@ -1,8 +1,8 @@ import typing -from typing import AnyStr, Optional, Dict, List +from typing import AnyStr, Dict, List, Optional from twisted.internet.defer import Deferred -from twisted.internet.interfaces import ITCPTransport, IAddress +from twisted.internet.interfaces import IAddress, ITCPTransport from twisted.logger import Logger from twisted.web.http_headers import Headers @@ -39,10 +39,7 @@ class Request: # - we use `self.transport.abortConnection`, which belongs to that interface # - twisted does too! in its implementation of HTTPChannel.forceAbortClient transport: Optional[ITCPTransport] - - def getHeader(self, key: AnyStr) -> Optional[AnyStr]: ... - def handleContentChunk(self, data: bytes) -> None: ... class PotentialDataLoss(Exception): ... From 036d8621ce3172259ec064f37b7c045369dedfa9 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Wed, 27 Oct 2021 15:06:19 +0100 Subject: [PATCH 3/3] Changelog --- changelog.d/441.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/441.misc diff --git a/changelog.d/441.misc b/changelog.d/441.misc new file mode 100644 index 00000000..9b5a24ac --- /dev/null +++ b/changelog.d/441.misc @@ -0,0 +1 @@ +Run linters over stub files. \ No newline at end of file