Skip to content

Commit

Permalink
Fix mypy check on travis [ECR-3935] (#52)
Browse files Browse the repository at this point in the history
* Fix mypy errors

* Fix formatting

* Update '.travis.yml'

* Update '.travis.yml'
  • Loading branch information
Parfyonator authored and popzxc committed Dec 18, 2019
1 parent 7f454a8 commit 7ec69f1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -29,7 +29,7 @@ jobs:
script:
- black --check -l 120 . --exclude=".*_pb2.py"
- mypy --ignore-missing-imports --disallow-untyped-defs ./exonum_client ./examples
- pylint exonum_client --max-line-length=120 --disable=fixme,bad-continuation,too-few-public-methods; exit $(($? & 3))
- pylint exonum_client --max-line-length=120 --disable=fixme,bad-continuation,too-few-public-methods
- name: docs
install:
- pip install sphinx
Expand Down
4 changes: 2 additions & 2 deletions examples/deploy.py
Expand Up @@ -35,7 +35,7 @@ def run() -> None:

instance_id = start_service(client, service_name, instance_name)

# If no exception has occured during the previous calls, the service
# If no exception has occurred during the previous calls, the service
# has started successfully:
print(f"Service instance '{instance_name}' (artifact '{service_name}') started with ID {instance_id}.")
except RuntimeError as err:
Expand Down Expand Up @@ -119,7 +119,7 @@ def send_request(client: ExonumClient, endpoint: str, data: bytes) -> None:
response = client.post_service("supervisor", endpoint, json_request, private=True)

if response.status_code != 200:
error_msg = f"Error occured during the request to the '{endpoint}' endpoint: {response.content}"
error_msg = f"Error occurred during the request to the '{endpoint}' endpoint: {response.content!r}"
raise RuntimeError(error_msg)

# Wait for 10 seconds.
Expand Down
2 changes: 1 addition & 1 deletion examples/transactions.py
Expand Up @@ -154,7 +154,7 @@ def get_balance(client: ExonumClient, key: PublicKey) -> int:
def ensure_status_code(response: requests.Response) -> None:
"""Raises an error if the status code is not 200."""
if response.status_code != 200:
raise RuntimeError(f"Received non-ok response: {response.content}")
raise RuntimeError(f"Received non-ok response: {response.content!r}")


def ensure_transaction_success(client: ExonumClient, tx_hash: str) -> None:
Expand Down
24 changes: 15 additions & 9 deletions exonum_client/client.py
Expand Up @@ -148,12 +148,18 @@ def send_transaction(self, message: ExonumMessage) -> str:
Result of the WebSocket request.
If a transaction is correct and it is accepted, it will contain a JSON with a hash of the transaction.
"""
body_raw = message.signed_raw()
if body_raw is None:
logger.critical("Attempt to send an unsigned message through websocket.")
raise RuntimeError("Attempt to send an unsigned message.")
data = json.dumps({"type": "transaction", "payload": {"tx_body": body_raw.hex()}})

ws_client = WebSocket()
ws_client.connect(self._address)
data = json.dumps({"type": "transaction", "payload": {"tx_body": message.signed_raw().hex()}})
ws_client.send(data)
response = ws_client.recv()
ws_client.close()

return response


Expand Down Expand Up @@ -200,12 +206,12 @@ def __init__(self, hostname: str, public_api_port: int = 80, private_api_port: i

def __repr__(self) -> str:
""" Conversion to a string. """
d = dict()

d["object"] = f"<{self.__class__.__name__} instance at {id(self)}>"
d["host"] = self.hostname
d["public_port"] = self.public_api_port
d["private_port"] = self.private_api_port
d = {
"object": f"<{self.__class__.__name__} instance at {id(self)}>",
"host": self.hostname,
"public_port": str(self.public_api_port),
"private_port": str(self.private_api_port),
}

return json.dumps(d, indent=2)

Expand Down Expand Up @@ -634,7 +640,7 @@ def get_peers(self) -> requests.Response:
"""
return _get(self._system_private_endpoint("peers"))

def set_consensus_interaction(self, enabled: True) -> requests.Response:
def set_consensus_interaction(self, enabled: bool = True) -> requests.Response:
"""
Performs a POST request to the '{system_base_path}/consensus_enabled'
to switch consensus interaction of the node on or off.
Expand Down Expand Up @@ -716,7 +722,7 @@ def _get_proto_sources(self, params: Optional[Dict[str, str]] = None) -> List[Pr
response.status_code,
json.dumps(response.json(), indent=2),
)
raise RuntimeError("Unsuccessfully attempted to retrieve Protobuf sources: {}".format(response.content))
raise RuntimeError("Unsuccessfully attempted to retrieve Protobuf sources: {!r}".format(response.content))
logger.debug("Protobuf sources retrieved successfully.")

proto_files = [
Expand Down
2 changes: 1 addition & 1 deletion exonum_client/proofs/map_proof/errors.py
Expand Up @@ -65,7 +65,7 @@ def malformed_entry(cls, entry: Any, additional_info: Any = None) -> "MalformedM

@classmethod
def invalid_key_size(cls, key: bytes) -> "MalformedMapProofError":
error_msg = f"Invalid key '{key}' for raw MapProof, expected size {KEY_SIZE}, actual {len(key)}"
error_msg = f"Invalid key '{key!r}' for raw MapProof, expected size {KEY_SIZE}, actual {len(key)}"

error_data = {"kind": cls.ErrorKind.INVALID_KEY_SIZE, "key": key}

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -19,7 +19,7 @@ lazy-object-proxy==1.4.2
MarkupSafe==1.1.1
mccabe==0.6.1
more-itertools==7.2.0
mypy==0.730
mypy==0.740
mypy-extensions==0.4.1
packaging==19.2
pkginfo==1.5.0.1
Expand Down

0 comments on commit 7ec69f1

Please sign in to comment.