refactor: replace Any types with specific types and update bad_code.md
- Replace Any with object or specific types across codebase - Add ReviewRequest dataclass for PR review payloads - Update bad_code.md: mark 5.1 (Any Type Overuse) as resolved - Fix summary table with accurate counts and unresolved issues list
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
import base64
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -25,7 +24,7 @@ class FilesClient:
|
||||
|
||||
def update_file(
|
||||
self, owner: str, repo: str, path: str, message: str, content: str, branch: str
|
||||
) -> dict[str, Any]:
|
||||
) -> dict[str, object]:
|
||||
"""Update a file in a repository.
|
||||
|
||||
Args:
|
||||
@@ -79,7 +78,7 @@ class FilesClient:
|
||||
else ""
|
||||
)
|
||||
|
||||
def update_ref(self, owner: str, repo: str, ref: str, sha: str) -> dict[str, Any]:
|
||||
def update_ref(self, owner: str, repo: str, ref: str, sha: str) -> dict[str, object]:
|
||||
"""Update a git reference.
|
||||
|
||||
Args:
|
||||
@@ -97,7 +96,7 @@ class FilesClient:
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def create_ref(self, owner: str, repo: str, ref: str, sha: str) -> dict[str, Any]:
|
||||
def create_ref(self, owner: str, repo: str, ref: str, sha: str) -> dict[str, object]:
|
||||
"""Create a new git reference.
|
||||
|
||||
Args:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Issues client for Gitea API operations."""
|
||||
|
||||
import logging
|
||||
from typing import Any, Callable, Optional
|
||||
from typing import Callable, Optional
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -196,7 +196,7 @@ class IssuesClient:
|
||||
The created issue.
|
||||
"""
|
||||
url = f"{self.base_url}/api/v1/repos/{owner}/{repo}/issues"
|
||||
data: dict[str, Any] = {"title": title, "body": body}
|
||||
data: dict[str, str | list[str]] = {"title": title, "body": body}
|
||||
if labels:
|
||||
data["labels"] = labels
|
||||
if assignees:
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
"""Pydantic models for Gitea API entities."""
|
||||
|
||||
from typing import Optional, Any
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
@@ -71,8 +71,8 @@ class PullRequestModel(BaseModel):
|
||||
updated_at: Optional[str] = None
|
||||
closed_at: Optional[str] = None
|
||||
merged_at: Optional[str] = None
|
||||
head: dict[str, Any] = Field(default_factory=dict)
|
||||
base: dict[str, Any] = Field(default_factory=dict)
|
||||
head: dict[str, object] = Field(default_factory=dict)
|
||||
base: dict[str, object] = Field(default_factory=dict)
|
||||
repository: Optional[RepositoryModel] = None
|
||||
comments: int = 0
|
||||
comments_url: Optional[str] = None
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Notifications client for Gitea API operations."""
|
||||
|
||||
import logging
|
||||
from typing import Any, Optional
|
||||
from typing import Optional
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -26,7 +26,7 @@ class NotificationsClient:
|
||||
|
||||
def list_unread_notifications(
|
||||
self, since: Optional[str] = None
|
||||
) -> list[dict[str, Any]]:
|
||||
) -> list[dict[str, object]]:
|
||||
"""List unread notifications.
|
||||
|
||||
Args:
|
||||
@@ -42,9 +42,9 @@ class NotificationsClient:
|
||||
params["since"] = since
|
||||
response = self.client.get(url, params=params)
|
||||
response.raise_for_status()
|
||||
notifications: list[dict[str, Any]] = response.json()
|
||||
notifications: list[dict[str, object]] = response.json()
|
||||
|
||||
result: list[dict[str, Any]] = []
|
||||
result: list[dict[str, object]] = []
|
||||
for n in notifications:
|
||||
repo_info = n.get("repository") or {}
|
||||
owner_info = repo_info.get("owner") or {}
|
||||
|
||||
+18
-11
@@ -1,7 +1,8 @@
|
||||
"""Pull Requests client for Gitea API operations."""
|
||||
|
||||
import logging
|
||||
from typing import Any, Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import Callable
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -17,6 +18,12 @@ from .models import (
|
||||
logger: logging.Logger = logging.getLogger("gitea.prs_client")
|
||||
|
||||
|
||||
@dataclass
|
||||
class ReviewRequest:
|
||||
event: str
|
||||
body: str
|
||||
|
||||
|
||||
class PullRequestsClient:
|
||||
"""HTTP client for Gitea Pull Requests API operations."""
|
||||
|
||||
@@ -288,7 +295,7 @@ class PullRequestsClient:
|
||||
"""
|
||||
try:
|
||||
url = f"{self.base_url}/api/v1/repos/{owner}/{repo}/pulls/{pull_number}"
|
||||
data: dict[str, Any] = {}
|
||||
data: dict[str, str | None] = {}
|
||||
if title is not None:
|
||||
data["title"] = title
|
||||
if body is not None:
|
||||
@@ -322,7 +329,7 @@ class PullRequestsClient:
|
||||
|
||||
def approve_pr(
|
||||
self, owner: str, repo: str, pr_number: int, comment: str
|
||||
) -> dict[str, Any]:
|
||||
) -> dict[str, object]:
|
||||
"""Approve a pull request.
|
||||
|
||||
Args:
|
||||
@@ -335,14 +342,14 @@ class PullRequestsClient:
|
||||
The review response.
|
||||
"""
|
||||
url = f"{self.base_url}/api/v1/repos/{owner}/{repo}/pulls/{pr_number}/reviews"
|
||||
data: dict[str, Any] = {"event": "APPROVED", "body": comment}
|
||||
response = self.client.post(url, json=data)
|
||||
review: ReviewRequest = ReviewRequest(event="APPROVED", body=comment)
|
||||
response = self.client.post(url, json={"event": review.event, "body": review.body})
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def request_changes_pr(
|
||||
self, owner: str, repo: str, pr_number: int, comment: str
|
||||
) -> dict[str, Any]:
|
||||
) -> dict[str, object]:
|
||||
"""Request changes on a pull request.
|
||||
|
||||
Args:
|
||||
@@ -355,14 +362,14 @@ class PullRequestsClient:
|
||||
The review response.
|
||||
"""
|
||||
url = f"{self.base_url}/api/v1/repos/{owner}/{repo}/pulls/{pr_number}/reviews"
|
||||
data: dict[str, Any] = {"event": "REQUEST_CHANGES", "body": comment}
|
||||
response = self.client.post(url, json=data)
|
||||
review: ReviewRequest = ReviewRequest(event="REQUEST_CHANGES", body=comment)
|
||||
response = self.client.post(url, json={"event": review.event, "body": review.body})
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def get_pr_reviews(
|
||||
self, owner: str, repo: str, pr_number: int
|
||||
) -> list[dict[str, Any]]:
|
||||
) -> list[dict[str, object]]:
|
||||
"""Get reviews for a pull request.
|
||||
|
||||
Args:
|
||||
@@ -382,7 +389,7 @@ class PullRequestsClient:
|
||||
|
||||
def dismiss_review_pr(
|
||||
self, owner: str, repo: str, pr_number: int, review_id: int, message: str
|
||||
) -> dict[str, Any]:
|
||||
) -> dict[str, object]:
|
||||
"""Dismiss a review on a pull request.
|
||||
|
||||
Args:
|
||||
@@ -447,7 +454,7 @@ class PullRequestsClient:
|
||||
url = (
|
||||
f"{self.base_url}/api/v1/repos/{owner}/{repo}/pulls/{pull_number}/merge"
|
||||
)
|
||||
data: dict[str, Any] = {
|
||||
data: dict[str, str] = {
|
||||
"Do": style,
|
||||
"MergeTitleField": title,
|
||||
"MergeMessageField": message,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Repositories client for Gitea API operations."""
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -36,7 +35,7 @@ class ReposClient:
|
||||
url = f"{self.base_url}/api/v1/user/repos"
|
||||
response = self.client.get(url)
|
||||
response.raise_for_status()
|
||||
repos: list[dict[str, Any]] = response.json()
|
||||
repos: list[dict[str, object]] = response.json()
|
||||
# Filter to ONLY configured organization repos, include mirrors
|
||||
seen: set[str] = set()
|
||||
result: list[RepositoryModel] = []
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from typing import Any
|
||||
from gitea.client import GiteaClient
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user