Skip to content

Commit 019822b

Browse files
Fix ruff linting errors
- Fix type annotations to use X | Y syntax instead of Optional[X] - Fix f-string usage in exception messages - Fix datetime.min timezone issue by using datetime.UTC
1 parent 9f18d6b commit 019822b

7 files changed

Lines changed: 17 additions & 21 deletions

File tree

src/codegen/cli/commands/init/main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from pathlib import Path
2-
from typing import Optional
32

43
import rich
54
import typer
@@ -10,9 +9,9 @@
109

1110

1211
def init(
13-
path: Optional[str] = typer.Option(None, help="Path within a git repository. Defaults to the current directory."),
14-
token: Optional[str] = typer.Option(None, help="Access token for the git repository. Required for full functionality."),
15-
language: Optional[str] = typer.Option(None, help="Override automatic language detection (python or typescript)"),
12+
path: str | None = typer.Option(None, help="Path within a git repository. Defaults to the current directory."),
13+
token: str | None = typer.Option(None, help="Access token for the git repository. Required for full functionality."),
14+
language: str | None = typer.Option(None, help="Override automatic language detection (python or typescript)"),
1615
fetch_docs: bool = typer.Option(False, "--fetch-docs", help="Fetch docs and examples (requires auth)"),
1716
):
1817
"""Initialize or update the Codegen folder."""

src/codegen/cli/commands/login/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import Optional
21

32
import rich
43
import typer
@@ -7,7 +6,7 @@
76
from codegen.cli.auth.token_manager import get_current_token
87

98

10-
def login(token: Optional[str] = typer.Option(None, help="API token for authentication")):
9+
def login(token: str | None = typer.Option(None, help="API token for authentication")):
1110
"""Store authentication token."""
1211
# Check if already authenticated
1312
if get_current_token():

src/codegen/cli/commands/mcp/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""MCP server command for the Codegen CLI."""
22

3-
from typing import Optional
43

54
import typer
65
from rich.console import Console
@@ -10,7 +9,7 @@
109

1110
def mcp(
1211
host: str = typer.Option("localhost", help="Host to bind the MCP server to"),
13-
port: Optional[int] = typer.Option(None, help="Port to bind the MCP server to (default: stdio transport)"),
12+
port: int | None = typer.Option(None, help="Port to bind the MCP server to (default: stdio transport)"),
1413
transport: str = typer.Option("stdio", help="Transport protocol to use (stdio or http)"),
1514
):
1615
"""Start the Codegen MCP server."""

src/codegen/cli/commands/update/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import subprocess
22
import sys
33
from importlib.metadata import distribution
4-
from typing import Optional
54

65
import requests
76
import rich
@@ -33,7 +32,7 @@ def install_package(package: str, *args: str) -> None:
3332

3433
def update(
3534
list_: bool = typer.Option(False, "--list", "-l", help="List all supported versions of the codegen"),
36-
version: Optional[str] = typer.Option(None, "--version", "-v", help="Update to a specific version of the codegen"),
35+
version: str | None = typer.Option(None, "--version", "-v", help="Update to a specific version of the codegen"),
3736
):
3837
"""Update Codegen to the latest or specified version
3938

src/codegen/cli/mcp/server.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import os
3-
from typing import Annotated, Any, Optional
3+
from typing import Annotated, Any
44

55
from fastmcp import Context, FastMCP
66

@@ -79,9 +79,9 @@ def get_service_config() -> dict[str, Any]:
7979
def create_agent_run(
8080
org_id: Annotated[int, "Organization ID"],
8181
prompt: Annotated[str, "The prompt/task for the agent to execute"],
82-
repo_name: Annotated[Optional[str], "Repository name (optional)"] = None,
83-
branch_name: Annotated[Optional[str], "Branch name (optional)"] = None,
84-
ctx: Optional[Context] = None,
82+
repo_name: Annotated[str | None, "Repository name (optional)"] = None,
83+
branch_name: Annotated[str | None, "Branch name (optional)"] = None,
84+
ctx: Context | None = None,
8585
) -> str:
8686
"""Create a new agent run in the specified organization."""
8787
try:
@@ -112,7 +112,7 @@ def create_agent_run(
112112
def get_agent_run(
113113
org_id: Annotated[int, "Organization ID"],
114114
agent_run_id: Annotated[int, "Agent run ID"],
115-
ctx: Optional[Context] = None,
115+
ctx: Context | None = None,
116116
) -> str:
117117
"""Get details of a specific agent run."""
118118
try:
@@ -142,7 +142,7 @@ def get_agent_run(
142142
def get_organizations(
143143
page: Annotated[int, "Page number (default: 1)"] = 1,
144144
limit: Annotated[int, "Number of organizations per page (default: 10)"] = 10,
145-
ctx: Optional[Context] = None,
145+
ctx: Context | None = None,
146146
) -> str:
147147
"""Get list of organizations the user has access to."""
148148
try:
@@ -166,7 +166,7 @@ def get_users(
166166
org_id: Annotated[int, "Organization ID"],
167167
page: Annotated[int, "Page number (default: 1)"] = 1,
168168
limit: Annotated[int, "Number of users per page (default: 10)"] = 10,
169-
ctx: Optional[Context] = None,
169+
ctx: Context | None = None,
170170
) -> str:
171171
"""Get list of users in an organization."""
172172
try:
@@ -189,7 +189,7 @@ def get_users(
189189
def get_user(
190190
org_id: Annotated[int, "Organization ID"],
191191
user_id: Annotated[int, "User ID"],
192-
ctx: Optional[Context] = None,
192+
ctx: Context | None = None,
193193
) -> str:
194194
"""Get details of a specific user in an organization."""
195195
try:

src/codegen/git/clients/git_repo_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import time
2-
from datetime import datetime
2+
from datetime import UTC, datetime
33

44
from github.Branch import Branch
55
from github.CheckRun import CheckRun
@@ -98,7 +98,7 @@ def get_last_modified_date_of_path(self, path: str) -> datetime:
9898
return last_modified_date
9999
else:
100100
print("Directory has not been modified or does not exist.")
101-
return datetime.min
101+
return datetime.min.replace(tzinfo=UTC)
102102

103103
####################################################################################################################
104104
# COMMENTS

src/codegen/shared/performance/stopwatch_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ def subprocess_with_stopwatch(command, command_desc: str | None = None, *args, *
4949
end_time = time.time()
5050
logger.info(f"Command '{command_desc or command}' took {end_time - start_time} seconds to execute.")
5151
# Cast to the correct type since we set text=True
52-
return cast(subprocess.CompletedProcess[str], result)
52+
return cast("subprocess.CompletedProcess[str]", result)

0 commit comments

Comments
 (0)