From 64861d7c367826f56c5098c1962f67193cac360e Mon Sep 17 00:00:00 2001 From: kukushechkin Date: Mon, 29 Aug 2022 10:48:35 +0300 Subject: [PATCH] mypy support --- .mypy.ini | 2 ++ CHANGELOG.rst | 5 +++++ setup.cfg | 2 ++ src/iqm_client/iqm_client.py | 26 ++++++++++++++------------ src/iqm_client/py.typed | 0 tox.ini | 4 ++-- 6 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 .mypy.ini create mode 100644 src/iqm_client/py.typed diff --git a/.mypy.ini b/.mypy.ini new file mode 100644 index 000000000..0a460c6f0 --- /dev/null +++ b/.mypy.ini @@ -0,0 +1,2 @@ +[mypy-mockito.*] +ignore_missing_imports = True \ No newline at end of file diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7751c9b53..5beebcac0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,11 @@ Changelog ========= +Version 6.2 +=========== + +* Add mypy support. `#41 `_ + Version 6.1 =========== diff --git a/setup.cfg b/setup.cfg index 6bbf06705..5b5745cb2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -67,6 +67,8 @@ testing = jsons==1.6.1 jsonschema==4.4.0 mockito==1.3.0 + types-requests == 2.28.9 + types-jsonschema == 4.14.0 cicd = twine >= 3.3.0, < 4.0 wheel >= 0.36.2, < 1.0 diff --git a/src/iqm_client/iqm_client.py b/src/iqm_client/iqm_client.py index 230a7ccd3..06e7a8ec6 100644 --- a/src/iqm_client/iqm_client.py +++ b/src/iqm_client/iqm_client.py @@ -500,6 +500,7 @@ def __del__(self): except Exception: # pylint: disable=broad-except pass + # pylint: disable=too-many-locals def submit_circuits( self, circuits: list[Circuit], @@ -523,6 +524,7 @@ def submit_circuits( Returns: ID for the created task. This ID is needed to query the status and the execution results. """ + serialized_qubit_mapping: Optional[list[SingleQubitMapping]] = None if qubit_mapping is not None: # check if qubit mapping is injective target_qubits = set(qubit_mapping.values()) @@ -543,13 +545,13 @@ def submit_circuits( if diff: raise ValueError(f'The physical qubits {diff} in the qubit mapping are not defined in settings.') - qubit_mapping = serialize_qubit_mapping(qubit_mapping) + serialized_qubit_mapping = serialize_qubit_mapping(qubit_mapping) # ``bearer_token`` can be ``None`` if cocos we're connecting does not use authentication bearer_token = self._get_bearer_token() data = RunRequest( - qubit_mapping=qubit_mapping, + qubit_mapping=serialized_qubit_mapping, circuits=circuits, settings=settings, calibration_set_id=calibration_set_id, @@ -593,13 +595,13 @@ def get_run(self, job_id: UUID) -> RunResult: timeout = 10 ) result.raise_for_status() - result = RunResult.from_dict(result.json()) - if result.warnings: - for warning in result.warnings: + run_result = RunResult.from_dict(result.json()) + if run_result.warnings: + for warning in run_result.warnings: warnings.warn(warning) - if result.status == Status.FAILED: - raise CircuitExecutionError(result.message) - return result + if run_result.status == Status.FAILED: + raise CircuitExecutionError(run_result.message) + return run_result def get_run_status(self, job_id: UUID) -> RunStatus: """Query the status of the running task. @@ -621,11 +623,11 @@ def get_run_status(self, job_id: UUID) -> RunStatus: timeout=REQUESTS_TIMEOUT ) result.raise_for_status() - result = RunStatus.from_dict(result.json()) - if result.warnings: - for warning in result.warnings: + run_result = RunStatus.from_dict(result.json()) + if run_result.warnings: + for warning in run_result.warnings: warnings.warn(warning) - return result + return run_result def wait_for_results(self, job_id: UUID, timeout_secs: float = DEFAULT_TIMEOUT_SECONDS) -> RunResult: """Poll results until run is ready, failed, or timed out. diff --git a/src/iqm_client/py.typed b/src/iqm_client/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/tox.ini b/tox.ini index 908e9444f..5079366b7 100644 --- a/tox.ini +++ b/tox.ini @@ -16,8 +16,8 @@ extras = testing commands = pytest tests --verbose --cov --cov-report term-missing --junitxml=test_report.xml --doctest-modules src - pytest --pylint src/ - pytest --pylint tests/ --pylint-rcfile=tests/.pylintrc + pytest --mypy --pylint src/ + pytest --mypy --pylint tests/ --pylint-rcfile=tests/.pylintrc pytest --isort tests/ src/ --verbose [testenv:docs]