Skip to content

Commit a469184

Browse files
committed
feat(pyrefly): add pyrefly type checker integration
- Add pyrefly as a dev dependency in pyproject.toml and poetry.lock. - Configure pyrefly with project-specific settings. - Integrate pyrefly into pre-commit hooks for Python files. - Add type ignore comments for pyrefly in various modules to suppress specific errors and improve compatibility. - Refactor some type annotations and variable initializations for better type checking. - Remove unused method from dbsync_service_manager.Table.
1 parent 79bac02 commit a469184

21 files changed

+91
-31
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ repos:
3434
additional_dependencies: [sphinx, toml]
3535
- repo: local
3636
hooks:
37+
- id: pyrefly
38+
name: pyrefly
39+
entry: pyrefly
40+
args: [ check, --remove-unused-ignores ]
41+
pass_filenames: false
42+
language: system
43+
types: [python]
3744
- id: mypy
3845
name: mypy
3946
entry: mypy

cardano_node_tests/cardano_cli_coverage.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ def merge_coverage(dict_a: dict, dict_b: dict) -> dict:
105105
mergeable = (list, set, tuple)
106106
addable = (int, float)
107107
for key, value in dict_b.items():
108+
# pyrefly: ignore # invalid-argument
108109
if key in dict_a and isinstance(value, mergeable) and isinstance(dict_a[key], mergeable):
109110
new_list = set(dict_a[key]).union(value)
110111
dict_a[key] = sorted(new_list)
112+
# pyrefly: ignore # invalid-argument
111113
elif key in dict_a and isinstance(value, addable) and isinstance(dict_a[key], addable):
112114
dict_a[key] += value
113115
# Skipped arguments and commands are not in the available commands dict
@@ -126,6 +128,7 @@ def cli(cli_args: tp.Iterable[str]) -> str:
126128
assert not isinstance(cli_args, str), "`cli_args` must be sequence of strings"
127129
with subprocess.Popen(list(cli_args), stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p:
128130
__, stderr = p.communicate()
131+
# pyrefly: ignore # missing-attribute
129132
return stderr.decode()
130133

131134

cardano_node_tests/pytest_plugins/xdist_scheduler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def _assign_work_unit(self, node: workermanage.WorkerController) -> None:
104104
scope, work_unit = None, None
105105

106106
# Check if there are any long-running tests already pending
107+
# pyrefly: ignore # bad-argument-type
107108
long_pending = self._is_long_pending(assigned_to_node)
108109

109110
if long_pending:

cardano_node_tests/tests/test_dbsync.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ def test_blocks(self, cluster: clusterlib.ClusterLib): # noqa: C901
197197
f"Expected: value > {prev_rec.epoch_slot_no} vs Returned: {rec.epoch_slot_no}"
198198
)
199199

200-
if rec.block_no is None or (
201-
prev_rec.block_no and rec.block_no != prev_rec.block_no + 1
200+
if (rec.block_no is None and prev_rec.block_no is not None) or (
201+
prev_rec.block_no is not None and rec.block_no != prev_rec.block_no + 1
202202
):
203203
errors.append(
204204
"'block_no' value is different than expected; "
@@ -211,6 +211,7 @@ def test_blocks(self, cluster: clusterlib.ClusterLib): # noqa: C901
211211
f"Expected: {prev_rec.id} vs Returned: {rec.previous_id}"
212212
)
213213

214+
# pyrefly: ignore # unknown
214215
prev_rec = rec
215216

216217
if errors:

cardano_node_tests/tests/test_kes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ def _check_kes_period_info(
290290
ignore_file_id=worker_id,
291291
)
292292
# Search for expected errors only in log file corresponding to pool with expired KES
293-
expected_errors = [(f"{expire_node_name}.stdout", err) for err in expected_err_regexes]
293+
expected_errors: list[tuple[str, str]] = [
294+
(f"{expire_node_name}.stdout", err) for err in expected_err_regexes
295+
]
294296

295297
with logfiles.expect_errors(expected_errors, worker_id=worker_id):
296298
LOGGER.info(

cardano_node_tests/tests/test_reconnect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def node_query_utxo(
6565
try:
6666
os.environ["CARDANO_NODE_SOCKET_PATH"] = str(new_socket)
6767
utxos = cluster_obj.g_query.get_utxo(address=address, tx_raw_output=tx_raw_output)
68-
return utxos
6968
finally:
7069
os.environ["CARDANO_NODE_SOCKET_PATH"] = orig_socket
70+
return utxos
7171

7272
def node_get_tip(
7373
self,
@@ -82,9 +82,9 @@ def node_get_tip(
8282
try:
8383
os.environ["CARDANO_NODE_SOCKET_PATH"] = str(new_socket)
8484
tip = cluster_obj.g_query.get_tip()
85-
return tip
8685
finally:
8786
os.environ["CARDANO_NODE_SOCKET_PATH"] = orig_socket
87+
return tip
8888

8989
def node_submit_tx(
9090
self,
@@ -112,9 +112,9 @@ def node_submit_tx(
112112
tx_files=tx_files,
113113
verify_tx=False,
114114
)
115-
return tx_raw_output
116115
finally:
117116
os.environ["CARDANO_NODE_SOCKET_PATH"] = orig_socket
117+
return tx_raw_output
118118

119119
def get_prometheus_metrics(self, port: int) -> requests.Response:
120120
response = http_client.get_session().get(f"http://localhost:{port}/metrics", timeout=10)

cardano_node_tests/tests/test_rollback.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ def node_query_utxo(
128128
try:
129129
os.environ["CARDANO_NODE_SOCKET_PATH"] = str(new_socket)
130130
utxos = cluster_obj.g_query.get_utxo(address=address, tx_raw_output=tx_raw_output)
131-
return utxos
132131
finally:
133132
os.environ["CARDANO_NODE_SOCKET_PATH"] = orig_socket
133+
return utxos
134134

135135
def node_submit_tx(
136136
self,
@@ -157,9 +157,9 @@ def node_submit_tx(
157157
txouts=txouts,
158158
tx_files=tx_files,
159159
)
160-
return tx_raw_output
161160
finally:
162161
os.environ["CARDANO_NODE_SOCKET_PATH"] = orig_socket
162+
return tx_raw_output
163163

164164
def node_wait_for_block(
165165
self,
@@ -174,9 +174,10 @@ def node_wait_for_block(
174174

175175
try:
176176
os.environ["CARDANO_NODE_SOCKET_PATH"] = str(new_socket)
177-
return cluster_obj.wait_for_block(block=block_no)
177+
new_block = cluster_obj.wait_for_block(block=block_no)
178178
finally:
179179
os.environ["CARDANO_NODE_SOCKET_PATH"] = orig_socket
180+
return new_block
180181

181182
@allure.link(helpers.get_vcs_link())
182183
# There's a submission delay of 60 sec. Therefore on testnet with low `securityParam`,

cardano_node_tests/tests/test_scripts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,7 @@ def test_incremental_signing(
21442144
tx_name=f"{temp_template}_from{idx}_r{r}",
21452145
)
21462146

2147+
assert tx_signed is not None # for pyrefly
21472148
submit_utils.submit_tx(
21482149
submit_method=submit_method,
21492150
cluster_obj=cluster,

cardano_node_tests/tests/test_tx_basic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,7 @@ def test_incremental_signing(
17011701
)
17021702

17031703
# It is not possible to submit Tx with missing required skey
1704+
assert tx_signed is not None # for pyrefly
17041705
with pytest.raises((clusterlib.CLIError, submit_api.SubmitApiError)) as excinfo:
17051706
submit_utils.submit_tx(
17061707
submit_method=submit_method,

cardano_node_tests/tests/tests_conway/test_drep.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ def test_register_and_retire_drep(
438438
if use_build_cmd and submit_method == "cli":
439439

440440
def _query_func():
441+
if not drep_data:
442+
return
441443
dbsync_utils.check_off_chain_drep_registration(
442444
drep_data=drep_data, metadata=drep_metadata_content
443445
)
@@ -587,9 +589,10 @@ def _retire_drep() -> None:
587589
assert drep_data and drep_data.voting_anchor_id
588590

589591
def _query_func():
590-
dbsync_utils.check_off_chain_vote_fetch_error(
591-
voting_anchor_id=drep_data.voting_anchor_id
592-
)
592+
if drep_data and drep_data.voting_anchor_id is not None:
593+
dbsync_utils.check_off_chain_vote_fetch_error(
594+
voting_anchor_id=drep_data.voting_anchor_id
595+
)
593596

594597
reqc.db021.start(url=helpers.get_vcs_link())
595598
dbsync_utils.retry_query(query_func=_query_func, timeout=360)

0 commit comments

Comments
 (0)