Skip to content

Commit 3ee1ec7

Browse files
authored
Fix up some types in the ecosystem code (astral-sh#8898)
## Summary Fixes up the type annotations to make type analyzers a little happier 😄 ## Test Plan N/A
1 parent ee5d95f commit 3ee1ec7

6 files changed

Lines changed: 17 additions & 14 deletions

File tree

‎python/ruff-ecosystem/ruff_ecosystem/check.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def markdown_check_result(result: Result) -> str:
6363
project_rule_changes[project] = changes = RuleChanges.from_diff(diff)
6464
all_rule_changes.update(changes)
6565

66-
lines = []
66+
lines: list[str] = []
6767
total_removed = all_rule_changes.total_removed_violations()
6868
total_added = all_rule_changes.total_added_violations()
6969
total_added_fixes = all_rule_changes.total_added_fixes()

‎python/ruff-ecosystem/ruff_ecosystem/format.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def markdown_format_result(result: Result) -> str:
2525
"""
2626
Render a `ruff format` ecosystem check result as markdown.
2727
"""
28-
lines = []
28+
lines: list[str] = []
2929
total_lines_removed = total_lines_added = 0
3030
total_files_modified = 0
3131
error_count = len(result.errored)
32-
patch_sets = []
32+
patch_sets: list[PatchSet] = []
3333

3434
for project, comparison in result.completed:
3535
total_lines_added += comparison.diff.lines_added
@@ -97,7 +97,7 @@ def format_patchset(patch_set: PatchSet, repo: ClonedRepository) -> str:
9797
"""
9898
Convert a patchset to markdown, adding permalinks to the start of each hunk.
9999
"""
100-
lines = []
100+
lines: list[str] = []
101101
for file_patch in patch_set:
102102
for hunk in file_patch:
103103
# Note: When used for `format` checks, the line number is not exact because

‎python/ruff-ecosystem/ruff_ecosystem/main.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def limited_parallelism(coroutine: Awaitable[T]) -> T:
5353
async with semaphore:
5454
return await coroutine
5555

56-
comparisons: list[Exception | Comparison] = await asyncio.gather(
56+
comparisons: list[BaseException | Comparison] = await asyncio.gather(
5757
*[
5858
limited_parallelism(
5959
clone_and_compare(
@@ -72,9 +72,10 @@ async def limited_parallelism(coroutine: Awaitable[T]) -> T:
7272
comparisons_by_target = dict(zip(targets, comparisons, strict=True))
7373

7474
# Split comparisons into errored / completed
75-
errored, completed = [], []
75+
errored: list[tuple[Project, BaseException]] = []
76+
completed: list[tuple[Project, Comparison]] = []
7677
for target, comparison in comparisons_by_target.items():
77-
if isinstance(comparison, Exception):
78+
if isinstance(comparison, BaseException):
7879
errored.append((target, comparison))
7980
else:
8081
completed.append((target, comparison))
@@ -138,7 +139,7 @@ async def clone_and_compare(
138139

139140

140141
class JSONEncoder(json.JSONEncoder):
141-
def default(self, o):
142+
def default(self, o: object):
142143
if isinstance(o, Serializable):
143144
return o.jsonable()
144145
if dataclasses.is_dataclass(o):

‎python/ruff-ecosystem/ruff_ecosystem/markdown.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from typing import TYPE_CHECKING
44

55
if TYPE_CHECKING:
6-
from ruff_ecosystem.projects import Project
6+
from ruff_ecosystem.projects import CommandOptions, Project
77

88

99
def markdown_project_section(
10-
title: str, content: str | list[str], options: object, project: Project
10+
title: str, content: str | list[str], options: CommandOptions, project: Project
1111
) -> list[str]:
1212
return markdown_details(
1313
summary=f'<a href="{project.repo.url}">{project.repo.fullname}</a> ({title})',
@@ -28,8 +28,10 @@ def markdown_plus_minus(added: int, removed: int) -> str:
2828
return f"+{added} -{removed}"
2929

3030

31-
def markdown_details(summary: str, content: str | list[str], preface: str):
32-
lines = []
31+
def markdown_details(
32+
summary: str, content: str | list[str], preface: str | None
33+
) -> list[str]:
34+
lines: list[str] = []
3335
lines.append(f"<details><summary>{summary}</summary>")
3436
if preface:
3537
lines.append("<p>")

‎python/ruff-ecosystem/ruff_ecosystem/projects.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def to_ruff_args(self) -> list[str]:
104104
return args
105105

106106
def to_black_args(self) -> list[str]:
107-
args = []
107+
args: list[str] = []
108108
if self.exclude:
109109
args.extend(["--exclude", self.exclude])
110110
if self.preview:

‎python/ruff-ecosystem/ruff_ecosystem/types.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Result(Serializable):
7575
The result of an ecosystem check for a collection of projects.
7676
"""
7777

78-
errored: list[tuple[Project, Exception]]
78+
errored: list[tuple[Project, BaseException]]
7979
completed: list[tuple[Project, Comparison]]
8080

8181

0 commit comments

Comments
 (0)