mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-02 18:02:23 +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)
|
project_rule_changes[project] = changes = RuleChanges.from_diff(diff)
|
||||||
all_rule_changes.update(changes)
|
all_rule_changes.update(changes)
|
||||||
|
|
||||||
lines = []
|
lines: list[str] = []
|
||||||
total_removed = all_rule_changes.total_removed_violations()
|
total_removed = all_rule_changes.total_removed_violations()
|
||||||
total_added = all_rule_changes.total_added_violations()
|
total_added = all_rule_changes.total_added_violations()
|
||||||
total_added_fixes = all_rule_changes.total_added_fixes()
|
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.
|
Render a `ruff format` ecosystem check result as markdown.
|
||||||
"""
|
"""
|
||||||
lines = []
|
lines: list[str] = []
|
||||||
total_lines_removed = total_lines_added = 0
|
total_lines_removed = total_lines_added = 0
|
||||||
total_files_modified = 0
|
total_files_modified = 0
|
||||||
error_count = len(result.errored)
|
error_count = len(result.errored)
|
||||||
patch_sets = []
|
patch_sets: list[PatchSet] = []
|
||||||
|
|
||||||
for project, comparison in result.completed:
|
for project, comparison in result.completed:
|
||||||
total_lines_added += comparison.diff.lines_added
|
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.
|
Convert a patchset to markdown, adding permalinks to the start of each hunk.
|
||||||
"""
|
"""
|
||||||
lines = []
|
lines: list[str] = []
|
||||||
for file_patch in patch_set:
|
for file_patch in patch_set:
|
||||||
for hunk in file_patch:
|
for hunk in file_patch:
|
||||||
# Note: When used for `format` checks, the line number is not exact because
|
# Note: When used for `format` checks, the line number is not exact because
|
||||||
|
|
|
@ -53,7 +53,7 @@ async def main(
|
||||||
async with semaphore:
|
async with semaphore:
|
||||||
return await coroutine
|
return await coroutine
|
||||||
|
|
||||||
comparisons: list[Exception | Comparison] = await asyncio.gather(
|
comparisons: list[BaseException | Comparison] = await asyncio.gather(
|
||||||
*[
|
*[
|
||||||
limited_parallelism(
|
limited_parallelism(
|
||||||
clone_and_compare(
|
clone_and_compare(
|
||||||
|
@ -72,9 +72,10 @@ async def main(
|
||||||
comparisons_by_target = dict(zip(targets, comparisons, strict=True))
|
comparisons_by_target = dict(zip(targets, comparisons, strict=True))
|
||||||
|
|
||||||
# Split comparisons into errored / completed
|
# 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():
|
for target, comparison in comparisons_by_target.items():
|
||||||
if isinstance(comparison, Exception):
|
if isinstance(comparison, BaseException):
|
||||||
errored.append((target, comparison))
|
errored.append((target, comparison))
|
||||||
else:
|
else:
|
||||||
completed.append((target, comparison))
|
completed.append((target, comparison))
|
||||||
|
@ -138,7 +139,7 @@ async def clone_and_compare(
|
||||||
|
|
||||||
|
|
||||||
class JSONEncoder(json.JSONEncoder):
|
class JSONEncoder(json.JSONEncoder):
|
||||||
def default(self, o):
|
def default(self, o: object):
|
||||||
if isinstance(o, Serializable):
|
if isinstance(o, Serializable):
|
||||||
return o.jsonable()
|
return o.jsonable()
|
||||||
if dataclasses.is_dataclass(o):
|
if dataclasses.is_dataclass(o):
|
||||||
|
|
|
@ -3,11 +3,11 @@ from __future__ import annotations
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ruff_ecosystem.projects import Project
|
from ruff_ecosystem.projects import CommandOptions, Project
|
||||||
|
|
||||||
|
|
||||||
def markdown_project_section(
|
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]:
|
) -> list[str]:
|
||||||
return markdown_details(
|
return markdown_details(
|
||||||
summary=f'<a href="{project.repo.url}">{project.repo.fullname}</a> ({title})',
|
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}"
|
return f"+{added} -{removed}"
|
||||||
|
|
||||||
|
|
||||||
def markdown_details(summary: str, content: str | list[str], preface: str):
|
def markdown_details(
|
||||||
lines = []
|
summary: str, content: str | list[str], preface: str | None
|
||||||
|
) -> list[str]:
|
||||||
|
lines: list[str] = []
|
||||||
lines.append(f"<details><summary>{summary}</summary>")
|
lines.append(f"<details><summary>{summary}</summary>")
|
||||||
if preface:
|
if preface:
|
||||||
lines.append("<p>")
|
lines.append("<p>")
|
||||||
|
|
|
@ -104,7 +104,7 @@ class FormatOptions(CommandOptions):
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def to_black_args(self) -> list[str]:
|
def to_black_args(self) -> list[str]:
|
||||||
args = []
|
args: list[str] = []
|
||||||
if self.exclude:
|
if self.exclude:
|
||||||
args.extend(["--exclude", self.exclude])
|
args.extend(["--exclude", self.exclude])
|
||||||
if self.preview:
|
if self.preview:
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Result(Serializable):
|
||||||
The result of an ecosystem check for a collection of projects.
|
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]]
|
completed: list[tuple[Project, Comparison]]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue