mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Fix up some types in the ecosystem code (#8898)
## Summary
Fixes up the type annotations to make type analyzers a little happier 😄
## Test Plan
N/A
This commit is contained in:
parent
ee5d95f751
commit
3ee1ec70cc
6 changed files with 17 additions and 14 deletions
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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'<a href="{project.repo.url}">{project.repo.fullname}</a> ({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"<details><summary>{summary}</summary>")
|
||||
if preface:
|
||||
lines.append("<p>")
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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]]
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue