From c3e72ce8d5ca5b63bec4c14387a9eb8190cd7e68 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Fri, 9 Dec 2022 11:56:11 +0100 Subject: [PATCH] Support mypy v0.990 new Optional report PEP 484 prohibits implicit Optional Bump pre-commit hooks --- .pre-commit-config.yaml | 6 +++--- duniterpy/api/bma/blockchain.py | 7 +++++-- duniterpy/api/endpoint.py | 18 +++++++++--------- duniterpy/documents/block.py | 2 +- duniterpy/documents/certification.py | 2 +- duniterpy/documents/identity.py | 4 ++-- duniterpy/documents/membership.py | 4 ++-- duniterpy/documents/peer.py | 4 ++-- duniterpy/documents/revocation.py | 4 ++-- duniterpy/grammars/output.py | 12 +++++++----- duniterpy/key/signing_key.py | 4 +++- 11 files changed, 37 insertions(+), 30 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5bb976d..fa1254d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,18 +10,18 @@ repos: - id: isort args: ["--profile", "black"] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.982 + rev: v0.991 hooks: - id: mypy args: - "--install-types" - "--non-interactive" - repo: https://github.com/PyCQA/pylint - rev: v2.15.4 + rev: v2.15.8 hooks: - id: pylint - repo: https://github.com/asottile/pyupgrade - rev: v3.1.0 + rev: v3.3.1 hooks: - id: pyupgrade args: [--py37-plus] diff --git a/duniterpy/api/bma/blockchain.py b/duniterpy/api/bma/blockchain.py index 1849bd0..8110cc6 100644 --- a/duniterpy/api/bma/blockchain.py +++ b/duniterpy/api/bma/blockchain.py @@ -15,7 +15,7 @@ import logging from http.client import HTTPResponse -from typing import Union +from typing import Optional, Union from duniterpy.api.client import RESPONSE_HTTP, Client @@ -266,7 +266,10 @@ def current(client: Client) -> dict: def block( - client: Client, number: int = 0, block_raw: str = None, signature: str = None + client: Client, + number: int = 0, + block_raw: Optional[str] = None, + signature: Optional[str] = None, ) -> Union[dict, HTTPResponse]: """ GET/POST a block from/to the blockchain diff --git a/duniterpy/api/endpoint.py b/duniterpy/api/endpoint.py index 89596fd..829c442 100644 --- a/duniterpy/api/endpoint.py +++ b/duniterpy/api/endpoint.py @@ -67,7 +67,7 @@ class Endpoint: def inline(self) -> str: raise NotImplementedError("inline() is not implemented") - def conn_handler(self, proxy: str = None) -> ConnectionHandler: + def conn_handler(self, proxy: Optional[str] = None) -> ConnectionHandler: raise NotImplementedError("conn_handler is not implemented") def __str__(self) -> str: @@ -114,7 +114,7 @@ class UnknownEndpoint(Endpoint): doc += f" {p}" return doc - def conn_handler(self, proxy: str = None) -> ConnectionHandler: + def conn_handler(self, proxy: Optional[str] = None) -> ConnectionHandler: """ Return connection handler @@ -188,7 +188,7 @@ class BMAEndpoint(Endpoint): ] return f'{self.API} {" ".join(inlined)}' - def conn_handler(self, proxy: str = None) -> ConnectionHandler: + def conn_handler(self, proxy: Optional[str] = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint @@ -285,7 +285,7 @@ class SecuredBMAEndpoint(BMAEndpoint): ] return f'{self.API} {" ".join(inlined)}' - def conn_handler(self, proxy: str = None) -> ConnectionHandler: + def conn_handler(self, proxy: Optional[str] = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint @@ -354,7 +354,7 @@ class WS2PEndpoint(Endpoint): ] return f'{self.API} {" ".join(inlined)}' - def conn_handler(self, proxy: str = None) -> ConnectionHandler: + def conn_handler(self, proxy: Optional[str] = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint @@ -425,7 +425,7 @@ class ESCoreEndpoint(Endpoint): inlined = [str(info) for info in (self.host, self.port) if info] return f'{self.API} {" ".join(inlined)}' - def conn_handler(self, proxy: str = None) -> ConnectionHandler: + def conn_handler(self, proxy: Optional[str] = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint @@ -484,7 +484,7 @@ class ESUserEndpoint(Endpoint): inlined = [str(info) for info in (self.host, self.port) if info] return f'{self.API} {" ".join(inlined)}' - def conn_handler(self, proxy: str = None) -> ConnectionHandler: + def conn_handler(self, proxy: Optional[str] = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint @@ -547,7 +547,7 @@ class ESSubscribtionEndpoint(Endpoint): inlined = [str(info) for info in (self.host, self.port) if info] return f'{self.API} {" ".join(inlined)}' - def conn_handler(self, proxy: str = None) -> ConnectionHandler: + def conn_handler(self, proxy: Optional[str] = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint @@ -646,7 +646,7 @@ class GVAEndpoint(Endpoint): ] return f'{self.API} {" ".join(inlined)}' - def conn_handler(self, proxy: str = None) -> ConnectionHandler: + def conn_handler(self, proxy: Optional[str] = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint diff --git a/duniterpy/documents/block.py b/duniterpy/documents/block.py index a5d4d19..3580159 100644 --- a/duniterpy/documents/block.py +++ b/duniterpy/documents/block.py @@ -168,7 +168,7 @@ class Block(Document): transactions: List[Transaction], inner_hash: str, nonce: int, - signing_key: SigningKey = None, + signing_key: Optional[SigningKey] = None, version: int = VERSION, currency: str = G1_CURRENCY_CODENAME, ) -> None: diff --git a/duniterpy/documents/certification.py b/duniterpy/documents/certification.py index c268b9a..8aa4fd8 100644 --- a/duniterpy/documents/certification.py +++ b/duniterpy/documents/certification.py @@ -57,7 +57,7 @@ class Certification(Document): pubkey_from: str, identity: Union[Identity, str], block_id: BlockID, - signing_key: SigningKey = None, + signing_key: Optional[SigningKey] = None, version: int = VERSION, currency: str = G1_CURRENCY_CODENAME, ) -> None: diff --git a/duniterpy/documents/identity.py b/duniterpy/documents/identity.py index dda8f37..1437320 100644 --- a/duniterpy/documents/identity.py +++ b/duniterpy/documents/identity.py @@ -14,7 +14,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import re -from typing import Any, Type, TypeVar +from typing import Any, Optional, Type, TypeVar from ..constants import ( BLOCK_ID_REGEX, @@ -73,7 +73,7 @@ class Identity(Document): pubkey: str, uid: str, block_id: BlockID, - signing_key: SigningKey = None, + signing_key: Optional[SigningKey] = None, version: int = VERSION, currency: str = G1_CURRENCY_CODENAME, ) -> None: diff --git a/duniterpy/documents/membership.py b/duniterpy/documents/membership.py index 3ce7a40..4ff7ac9 100644 --- a/duniterpy/documents/membership.py +++ b/duniterpy/documents/membership.py @@ -14,7 +14,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import re -from typing import Any, Type, TypeVar +from typing import Any, Optional, Type, TypeVar from ..constants import ( BLOCK_ID_REGEX, @@ -77,7 +77,7 @@ class Membership(Document): membership_block_id: BlockID, uid: str, identity_block_id: BlockID, - signing_key: SigningKey = None, + signing_key: Optional[SigningKey] = None, version: int = VERSION, currency: str = G1_CURRENCY_CODENAME, membership_type: str = "IN", diff --git a/duniterpy/documents/peer.py b/duniterpy/documents/peer.py index cfe5bee..4085491 100644 --- a/duniterpy/documents/peer.py +++ b/duniterpy/documents/peer.py @@ -14,7 +14,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import re -from typing import List, Type, TypeVar +from typing import List, Optional, Type, TypeVar from duniterpy.api.endpoint import Endpoint, endpoint @@ -67,7 +67,7 @@ class Peer(Document): pubkey: str, block_id: BlockID, endpoints: List[Endpoint], - signing_key: SigningKey = None, + signing_key: Optional[SigningKey] = None, version: int = VERSION, currency: str = G1_CURRENCY_CODENAME, ) -> None: diff --git a/duniterpy/documents/revocation.py b/duniterpy/documents/revocation.py index 528ca2d..b30bfa1 100644 --- a/duniterpy/documents/revocation.py +++ b/duniterpy/documents/revocation.py @@ -14,7 +14,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import re -from typing import Any, Type, TypeVar, Union +from typing import Any, Optional, Type, TypeVar, Union from ..constants import ( BLOCK_ID_REGEX, @@ -59,7 +59,7 @@ class Revocation(Document): def __init__( self, identity: Union[Identity, str], - signing_key: SigningKey = None, + signing_key: Optional[SigningKey] = None, version: int = VERSION, currency: str = G1_CURRENCY_CODENAME, ) -> None: diff --git a/duniterpy/grammars/output.py b/duniterpy/grammars/output.py index f9e0ef5..a87d482 100644 --- a/duniterpy/grammars/output.py +++ b/duniterpy/grammars/output.py @@ -151,7 +151,7 @@ class CSV: return csv def compose( - self, parser: Any = None, grammar: Any = None, attr_of: str = None + self, parser: Any = None, grammar: Any = None, attr_of: Optional[str] = None ) -> str: """ Return the CSV(time) expression as string format @@ -210,7 +210,7 @@ class CLTV: return cltv def compose( - self, parser: Any = None, grammar: Any = None, attr_of: str = None + self, parser: Any = None, grammar: Any = None, attr_of: Optional[str] = None ) -> str: """ Return the CLTV(timestamp) expression as string format @@ -269,7 +269,7 @@ class XHX: return xhx def compose( - self, parser: Any = None, grammar: Any = None, attr_of: str = None + self, parser: Any = None, grammar: Any = None, attr_of: Optional[str] = None ) -> str: """ Return the XHX(sha_hash) expression as string format @@ -305,7 +305,7 @@ class Operator(Keyword): return op def compose( - self, parser: Any = None, grammar: Any = None, attr_of: str = None + self, parser: Any = None, grammar: Any = None, attr_of: Optional[str] = None ) -> str: """ Return the Operator keyword as string format @@ -382,7 +382,9 @@ class Condition: condition.right = right return condition - def compose(self, parser: Any, grammar: Any = None, attr_of: str = None) -> str: + def compose( + self, parser: Any, grammar: Any = None, attr_of: Optional[str] = None + ) -> str: """ Return the Condition as string format diff --git a/duniterpy/key/signing_key.py b/duniterpy/key/signing_key.py index 08d0800..53e2fe8 100644 --- a/duniterpy/key/signing_key.py +++ b/duniterpy/key/signing_key.py @@ -500,7 +500,9 @@ Data: {ewif_key}" @classmethod def from_dubp_mnemonic( - cls: Type[SigningKeyType], mnemonic: str, scrypt_params: ScryptParams = None + cls: Type[SigningKeyType], + mnemonic: str, + scrypt_params: Optional[ScryptParams] = None, ) -> SigningKeyType: """ Generate key pair instance from a DUBP mnemonic passphrase -- GitLab