Skip to content

feat(lint): add pyrefly and update linting configs #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ repos:
- id: markdownlint
- repo: local
hooks:
- id: pyrefly
name: pyrefly
entry: pyrefly
args: [ check, --remove-unused-ignores ]
pass_filenames: false
language: system
types: [python]
- id: mypy
name: mypy
entry: mypy
Expand Down
6 changes: 5 additions & 1 deletion cardano_clusterlib/clusterlib_klass.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(
slots_offset: int | None = None,
socket_path: itp.FileType = "",
command_era: str = consts.CommandEras.LATEST,
):
) -> None:
try:
self.command_era = getattr(consts.CommandEras, command_era.upper())
except AttributeError as excp:
Expand All @@ -59,6 +59,7 @@ def __init__(
self.confirm_blocks = consts.CONFIRM_BLOCKS_NUM
self._rand_str = helpers.get_rand_str(4)
self._cli_log = ""
# pyrefly: ignore # missing-attribute
self.era_in_use = (
consts.Eras.__members__.get(command_era.upper()) or consts.Eras["DEFAULT"]
).name.lower()
Expand Down Expand Up @@ -100,6 +101,7 @@ def __init__(
# Conway+ era
self.conway_genesis_json: pl.Path | None = None
self.conway_genesis: dict = {}
# pyrefly: ignore # bad-specialization, bad-argument-type, not-a-type
if consts.Eras[self.era_in_use.upper()].value >= consts.Eras.CONWAY.value:
# Conway genesis
self.conway_genesis_json = clusterlib_helpers._find_conway_genesis_json(
Expand Down Expand Up @@ -276,6 +278,7 @@ def cli(
if retcode == 0:
break

# pyrefly: ignore # missing-attribute
stderr_dec = stderr.decode()
err_msg = (
f"An error occurred running a CLI command `{cmd_str}` on path "
Expand All @@ -289,6 +292,7 @@ def cli(
else:
raise exceptions.CLIError(err_msg)

# pyrefly: ignore # bad-argument-type
return structs.CLIOut(stdout or b"", stderr or b"")

def refresh_pparams_file(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions cardano_clusterlib/txtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ def get_proposal_file_argname(era_in_use: str = "") -> str:
"""Return the name of the proposal file argument."""
proposal_file_argname = (
"--proposal-file"
# pyrefly: ignore # bad-specialization, bad-argument-type, not-a-type
if (consts.Eras[era_in_use.upper()].value >= consts.Eras.CONWAY.value)
else "--update-proposal-file"
)
Expand Down
19 changes: 17 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ force_single_line = true
line-length = 100

[tool.ruff.lint]
select = ["ARG", "B", "C4", "C90", "D", "DTZ", "E", "EM", "F", "FURB", "I001", "ISC", "N", "PERF", "PIE", "PL", "PLE", "PLR", "PLW", "PT", "PTH", "Q", "RET", "RSE", "RUF", "SIM", "TRY", "UP", "W", "YTT"]
select = ["ANN", "ARG", "B", "C4", "C90", "D", "DTZ", "E", "EM", "F", "FURB", "I001", "ISC", "N", "PERF", "PIE", "PL", "PLE", "PLR", "PLW", "PT", "PTH", "Q", "RET", "RSE", "RUF", "SIM", "TRY", "UP", "W", "YTT"]
ignore = ["D10", "D203", "D212", "D213", "D214", "D215", "D404", "D405", "D406", "D407", "D408", "D409", "D410", "D411", "D413", "ISC001", "PLR0912", "PLR0913", "PLR0915", "PT001", "PT007", "PT012", "PT018", "PT023", "PTH123", "RET504", "TRY002", "TRY301", "UP006", "UP007", "UP035"]

[tool.ruff.lint.per-file-ignores]
"docs/**.py" = ["ANN"]

[tool.ruff.lint.isort]
force-single-line = true

Expand All @@ -56,6 +59,18 @@ ignore_missing_imports = true
follow_imports = "normal"
no_implicit_optional = true
allow_untyped_globals = false
allow_untyped_defs = false
warn_unused_configs = true
warn_return_any = true

[tool.pyrefly]
project_includes = ["cardano_clusterlib"]
ignore_errors_in_generated_code = true
use_untyped_imports = true
ignore_missing_source = true

[[tool.pyrefly.sub_config]]
matches = "cardano_clusterlib/clusterlib_klass.py"

# Ignore the bad-argument-type errors for Self@ClusterLib, that are reported only for LSP
[tool.pyrefly.sub_config.errors]
bad-argument-type = false
5 changes: 3 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
-e . --config-settings editable_mode=compat

# linting
mypy
pre-commit
mypy~=1.15.0
pyrefly~=0.17.0
pre-commit~=4.2.0

build
virtualenv
Loading