diff --git a/python/ruff-ecosystem/ruff_ecosystem/check.py b/python/ruff-ecosystem/ruff_ecosystem/check.py index 2e996ff006..fe5ea0c246 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/check.py +++ b/python/ruff-ecosystem/ruff_ecosystem/check.py @@ -63,7 +63,7 @@ def markdown_check_result(result: Result) -> str: project_rule_changes[project] = changes = RuleChanges.from_diff(diff) all_rule_changes.update(changes) - lines = [] + lines: list[str] = [] total_removed = all_rule_changes.total_removed_violations() total_added = all_rule_changes.total_added_violations() total_added_fixes = all_rule_changes.total_added_fixes() diff --git a/python/ruff-ecosystem/ruff_ecosystem/format.py b/python/ruff-ecosystem/ruff_ecosystem/format.py index f639150a86..2a15e62920 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/format.py +++ b/python/ruff-ecosystem/ruff_ecosystem/format.py @@ -25,11 +25,11 @@ def markdown_format_result(result: Result) -> str: """ Render a `ruff format` ecosystem check result as markdown. """ - lines = [] + lines: list[str] = [] total_lines_removed = total_lines_added = 0 total_files_modified = 0 error_count = len(result.errored) - patch_sets = [] + patch_sets: list[PatchSet] = [] for project, comparison in result.completed: total_lines_added += comparison.diff.lines_added @@ -97,7 +97,7 @@ def format_patchset(patch_set: PatchSet, repo: ClonedRepository) -> str: """ Convert a patchset to markdown, adding permalinks to the start of each hunk. """ - lines = [] + lines: list[str] = [] for file_patch in patch_set: for hunk in file_patch: # Note: When used for `format` checks, the line number is not exact because diff --git a/python/ruff-ecosystem/ruff_ecosystem/main.py b/python/ruff-ecosystem/ruff_ecosystem/main.py index e7f50093b9..ca0e3037c7 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/main.py +++ b/python/ruff-ecosystem/ruff_ecosystem/main.py @@ -53,7 +53,7 @@ async def main( async with semaphore: return await coroutine - comparisons: list[Exception | Comparison] = await asyncio.gather( + comparisons: list[BaseException | Comparison] = await asyncio.gather( *[ limited_parallelism( clone_and_compare( @@ -72,9 +72,10 @@ async def main( comparisons_by_target = dict(zip(targets, comparisons, strict=True)) # Split comparisons into errored / completed - errored, completed = [], [] + errored: list[tuple[Project, BaseException]] = [] + completed: list[tuple[Project, Comparison]] = [] for target, comparison in comparisons_by_target.items(): - if isinstance(comparison, Exception): + if isinstance(comparison, BaseException): errored.append((target, comparison)) else: completed.append((target, comparison)) @@ -138,7 +139,7 @@ async def clone_and_compare( class JSONEncoder(json.JSONEncoder): - def default(self, o): + def default(self, o: object): if isinstance(o, Serializable): return o.jsonable() if dataclasses.is_dataclass(o): diff --git a/python/ruff-ecosystem/ruff_ecosystem/markdown.py b/python/ruff-ecosystem/ruff_ecosystem/markdown.py index e6f6060695..0af3b20367 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/markdown.py +++ b/python/ruff-ecosystem/ruff_ecosystem/markdown.py @@ -3,11 +3,11 @@ from __future__ import annotations from typing import TYPE_CHECKING if TYPE_CHECKING: - from ruff_ecosystem.projects import Project + from ruff_ecosystem.projects import CommandOptions, Project def markdown_project_section( - title: str, content: str | list[str], options: object, project: Project + title: str, content: str | list[str], options: CommandOptions, project: Project ) -> list[str]: return markdown_details( summary=f'{project.repo.fullname} ({title})', @@ -28,8 +28,10 @@ def markdown_plus_minus(added: int, removed: int) -> str: return f"+{added} -{removed}" -def markdown_details(summary: str, content: str | list[str], preface: str): - lines = [] +def markdown_details( + summary: str, content: str | list[str], preface: str | None +) -> list[str]: + lines: list[str] = [] lines.append(f"
{summary}") if preface: lines.append("

") diff --git a/python/ruff-ecosystem/ruff_ecosystem/projects.py b/python/ruff-ecosystem/ruff_ecosystem/projects.py index d4fb64e804..fa5f8224a8 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/projects.py +++ b/python/ruff-ecosystem/ruff_ecosystem/projects.py @@ -104,7 +104,7 @@ class FormatOptions(CommandOptions): return args def to_black_args(self) -> list[str]: - args = [] + args: list[str] = [] if self.exclude: args.extend(["--exclude", self.exclude]) if self.preview: diff --git a/python/ruff-ecosystem/ruff_ecosystem/types.py b/python/ruff-ecosystem/ruff_ecosystem/types.py index 41a9b02aab..687ab31ce8 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/types.py +++ b/python/ruff-ecosystem/ruff_ecosystem/types.py @@ -75,7 +75,7 @@ class Result(Serializable): The result of an ecosystem check for a collection of projects. """ - errored: list[tuple[Project, Exception]] + errored: list[tuple[Project, BaseException]] completed: list[tuple[Project, Comparison]]