Skip to content

Commit ac6c44a

Browse files
authored
lint: update pre-commit and refomat (#11)
# Motivation - Testing github CI
1 parent 9a829f0 commit ac6c44a

File tree

30 files changed

+88
-101
lines changed

30 files changed

+88
-101
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repos:
77
hooks:
88
- id: taplo-format
99
- repo: https://github.com/astral-sh/ruff-pre-commit
10-
rev: v0.9.6
10+
rev: v0.11.7
1111
hooks:
1212
# Run the linter.
1313
- id: ruff
@@ -19,7 +19,7 @@ repos:
1919
types_or: [python, jupyter, pyi]
2020

2121
- repo: https://github.com/biomejs/pre-commit
22-
rev: "v0.6.1"
22+
rev: "v2.0.0-beta.1"
2323
hooks:
2424
- id: biome-check
2525
language: node
@@ -48,7 +48,7 @@ repos:
4848
- id: check-merge-conflict
4949

5050
- repo: https://github.com/python-jsonschema/check-jsonschema
51-
rev: 0.31.1
51+
rev: 0.33.0
5252
hooks:
5353
- id: check-github-workflows
5454
- id: check-github-actions
@@ -77,12 +77,12 @@ repos:
7777
entry: bash -c "uv run --frozen --all-extras --dev deptry src --ignore DEP001 --extend-exclude 'codegen-examples/.*'"
7878

7979
- repo: https://github.com/renovatebot/pre-commit-hooks
80-
rev: 39.169.3
80+
rev: 39.263.1
8181
hooks:
8282
- id: renovate-config-validator
8383

8484
- repo: https://github.com/astral-sh/uv-pre-commit
85-
rev: "0.5.31"
85+
rev: "0.6.17"
8686
hooks:
8787
- id: uv-sync
8888
args: ["--frozen", "--all-packages", "--all-extras"]

src/codegen/agents/agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from typing import Any, Optional
2+
from typing import Any
33

44
from codegen_api_client.api.agents_api import AgentsApi
55
from codegen_api_client.api_client import ApiClient
@@ -45,7 +45,7 @@ def refresh(self) -> None:
4545
class Agent:
4646
"""API client for interacting with Codegen AI agents."""
4747

48-
def __init__(self, token: str, org_id: Optional[int] = None, base_url: Optional[str] = CODEGEN_BASE_API_URL):
48+
def __init__(self, token: str, org_id: int | None = None, base_url: str | None = CODEGEN_BASE_API_URL):
4949
"""Initialize a new Agent client.
5050
5151
Args:
@@ -82,7 +82,7 @@ def run(self, prompt: str) -> AgentTask:
8282
self.current_job = job
8383
return job
8484

85-
def get_status(self) -> Optional[dict[str, Any]]:
85+
def get_status(self) -> dict[str, Any] | None:
8686
"""Get the status of the current job.
8787
8888
Returns:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import subprocess
55
import sys
66
from pathlib import Path
7-
from typing import Optional
87

98
import rich
109
import rich_click as click
@@ -89,7 +88,7 @@ def create_app_module(file_path: Path) -> str:
8988
return f"{module_name}:app"
9089

9190

92-
def start_ngrok(port: int) -> Optional[str]:
91+
def start_ngrok(port: int) -> str | None:
9392
"""Start ngrok and return the public URL"""
9493
try:
9594
import requests

src/codegen/extensions/attribution/git_history.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import time
22
from collections import defaultdict, deque
33
from datetime import datetime
4-
from typing import Optional
54

65
import pygit2
76
from intervaltree import IntervalTree
@@ -16,7 +15,7 @@
1615
class GitAttributionTracker:
1716
"""Tracks attribution information for code symbols based on git history."""
1817

19-
def __init__(self, codebase: Codebase, ai_authors: Optional[list[str]] = None):
18+
def __init__(self, codebase: Codebase, ai_authors: list[str] | None = None):
2019
"""Initialize the attribution tracker.
2120
2221
Args:
@@ -43,7 +42,7 @@ def __init__(self, codebase: Codebase, ai_authors: Optional[list[str]] = None):
4342

4443
self._commits: deque[Commit]
4544

46-
def build_history(self, max_commits: Optional[int] = None) -> None:
45+
def build_history(self, max_commits: int | None = None) -> None:
4746
"""Build the git history for the codebase.
4847
4948
Args:
@@ -206,7 +205,7 @@ def map_symbols_to_history(self, force=False) -> None:
206205
start_time = time.time()
207206

208207
print("Stashing any working directory changes...")
209-
stash_msg = f"Codegen Attribution Stash @ {datetime.now().timestamp()}"
208+
stash_msg = f"Codegen Attribution Stash @ {datetime.now().timestamp()}" # noqa: DTZ005
210209
stash_id = None
211210
try:
212211
stash_id = self.repo.stash(self.repo.default_signature, stash_msg, include_untracked=True)
@@ -325,7 +324,7 @@ def get_symbol_history(self, symbol: Symbol) -> list[dict]:
325324
symbol_id = f"{symbol.filepath}:{symbol.name}"
326325
return self._symbol_history.get(symbol_id, [])
327326

328-
def get_symbol_last_editor(self, symbol: Symbol) -> Optional[str]:
327+
def get_symbol_last_editor(self, symbol: Symbol) -> str | None:
329328
"""Get the last person who edited a symbol.
330329
331330
Args:
@@ -423,12 +422,12 @@ def get_ai_contribution_timeline(self) -> list[tuple[datetime, int]]:
423422
if any(name in author for name in self.ai_authors):
424423
for commit in commits:
425424
# Convert timestamp to year-month
426-
dt = datetime.fromtimestamp(commit["timestamp"])
425+
dt = datetime.fromtimestamp(commit["timestamp"]) # noqa: DTZ006
427426
month_key = f"{dt.year}-{dt.month:02d}"
428427
monthly_counts[month_key] += 1
429428

430429
# Sort by date
431430
timeline = sorted(monthly_counts.items())
432431

433432
# Convert to datetime objects
434-
return [(datetime.strptime(month, "%Y-%m"), count) for month, count in timeline]
433+
return [(datetime.strptime(month, "%Y-%m"), count) for month, count in timeline] # noqa: DTZ007

src/codegen/extensions/attribution/main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
from typing import Optional
2-
31
from codegen.extensions.attribution.git_history import GitAttributionTracker
42
from codegen.sdk.core.codebase import Codebase
53

64

7-
def analyze_ai_impact(codebase: Codebase, ai_authors: Optional[list[str]] = None, max_commits: Optional[int] = None) -> dict:
5+
def analyze_ai_impact(codebase: Codebase, ai_authors: list[str] | None = None, max_commits: int | None = None) -> dict:
86
"""Analyze the impact of AI on a codebase.
97
108
Args:
@@ -57,7 +55,7 @@ def analyze_ai_impact(codebase: Codebase, ai_authors: Optional[list[str]] = None
5755
}
5856

5957

60-
def add_attribution_to_symbols(codebase: Codebase, ai_authors: Optional[list[str]] = None) -> None:
58+
def add_attribution_to_symbols(codebase: Codebase, ai_authors: list[str] | None = None) -> None:
6159
"""Add attribution information to symbols in the codebase.
6260
6361
This adds the following attributes to each symbol:

src/codegen/extensions/events/codegen_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from typing import Any, Optional
2+
from typing import Any
33

44
from fastapi import FastAPI, Request
55
from fastapi.responses import HTMLResponse
@@ -23,7 +23,7 @@ class CodegenApp:
2323
linear: Linear
2424
slack: Slack
2525

26-
def __init__(self, name: str, repo: Optional[str] = None, tmp_dir: str = "/tmp/codegen", commit: str | None = "latest"):
26+
def __init__(self, name: str, repo: str | None = None, tmp_dir: str = "/tmp/codegen", commit: str | None = "latest"):
2727
self.name = name
2828
self.tmp_dir = tmp_dir
2929

src/codegen/extensions/events/github.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
3-
from typing import Any, Callable, TypeVar
3+
from collections.abc import Callable
4+
from typing import Any, TypeVar
45

56
from fastapi import Request
67
from github import Github

src/codegen/extensions/events/github_types.py

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

43

54
class GitHubRepository:
@@ -37,11 +36,11 @@ class GitHubInstallation:
3736
events: list[str]
3837
created_at: datetime
3938
updated_at: datetime
40-
single_file_name: Optional[str]
39+
single_file_name: str | None
4140
has_multiple_single_files: bool
4241
single_file_paths: list[str]
43-
suspended_by: Optional[str]
44-
suspended_at: Optional[datetime]
42+
suspended_by: str | None
43+
suspended_at: datetime | None
4544

4645

4746
class GitHubUser:
@@ -58,5 +57,5 @@ class GitHubInstallationEvent:
5857
action: str
5958
installation: GitHubInstallation
6059
repositories: list[GitHubRepository]
61-
requester: Optional[dict]
60+
requester: dict | None
6261
sender: GitHubUser

src/codegen/extensions/events/linear.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
2-
from typing import Any, Callable, TypeVar
2+
from collections.abc import Callable
3+
from typing import Any, TypeVar
34

45
from pydantic import BaseModel
56

src/codegen/extensions/github/types/pull_request.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal, Optional
1+
from typing import Literal
22

33
from pydantic import BaseModel
44

@@ -47,30 +47,30 @@ class PullRequest(BaseModel):
4747
locked: bool
4848
title: str
4949
user: GitHubUser
50-
body: Optional[str]
50+
body: str | None
5151
created_at: str
5252
updated_at: str
53-
closed_at: Optional[str]
54-
merged_at: Optional[str]
55-
merge_commit_sha: Optional[str]
56-
assignee: Optional[GitHubUser]
53+
closed_at: str | None
54+
merged_at: str | None
55+
merge_commit_sha: str | None
56+
assignee: GitHubUser | None
5757
assignees: list[GitHubUser]
5858
requested_reviewers: list[GitHubUser]
5959
requested_teams: list[dict]
6060
labels: list[Label]
61-
milestone: Optional[dict]
61+
milestone: dict | None
6262
draft: bool
6363
head: PullRequestRef
6464
base: PullRequestRef
6565
_links: PullRequestLinks
6666
author_association: str
67-
auto_merge: Optional[dict]
68-
active_lock_reason: Optional[str]
67+
auto_merge: dict | None
68+
active_lock_reason: str | None
6969
merged: bool
70-
mergeable: Optional[bool]
71-
rebaseable: Optional[bool]
70+
mergeable: bool | None
71+
rebaseable: bool | None
7272
mergeable_state: str
73-
merged_by: Optional[GitHubUser]
73+
merged_by: GitHubUser | None
7474
comments: int
7575
review_comments: int
7676
maintainer_can_modify: bool

src/codegen/extensions/github/types/push.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
from pydantic import BaseModel
42

53
from .base import GitHubRepository, GitHubUser
@@ -23,7 +21,7 @@ class PushEvent(BaseModel):
2321
created: bool
2422
deleted: bool
2523
forced: bool
26-
base_ref: Optional[str]
24+
base_ref: str | None
2725
compare: str
2826
commits: list[GitHubCommit]
2927
head_commit: GitHubCommit

src/codegen/extensions/graph/create_graph.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
from codegen.extensions.graph.utils import Node, NodeLabel, Relation, RelationLabel, SimpleGraph
42
from codegen.sdk.code_generation.doc_utils.utils import safe_get_class
53
from codegen.sdk.core.class_definition import Class
@@ -16,7 +14,7 @@ def create_codebase_graph(codebase):
1614
# Track existing nodes by name to prevent duplicates
1715
node_registry = {} # name -> node_id mapping
1816

19-
def get_or_create_node(name: str, label: NodeLabel, parent_name: Optional[str] = None, properties: dict | None = None):
17+
def get_or_create_node(name: str, label: NodeLabel, parent_name: str | None = None, properties: dict | None = None):
2018
"""Get existing node or create new one if it doesn't exist."""
2119
full_name = f"{parent_name}.{name}" if parent_name and parent_name != "Class" else name
2220
if full_name in node_registry:

src/codegen/extensions/graph/neo4j_exporter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def export_graph(self, graph: SimpleGraph):
2626
with self.driver.session() as session:
2727
# Create nodes
2828
for node in graph.nodes.values():
29-
properties = {"name": node.name, "full_name": node.full_name, **{k: str(v) if isinstance(v, (dict, list)) else v for k, v in node.properties.items()}}
29+
properties = {"name": node.name, "full_name": node.full_name, **{k: str(v) if isinstance(v, dict | list) else v for k, v in node.properties.items()}}
3030

3131
query = f"CREATE (n:{node.label} {{{', '.join(f'{k}: ${k}' for k in properties.keys())}}})"
3232
session.run(query, properties)
@@ -36,7 +36,7 @@ def export_graph(self, graph: SimpleGraph):
3636
source_node = graph.nodes[relation.source_id]
3737
target_node = graph.nodes[relation.target_id]
3838

39-
properties = {**{k: str(v) if isinstance(v, (dict, list)) else v for k, v in relation.properties.items()}}
39+
properties = {**{k: str(v) if isinstance(v, dict | list) else v for k, v in relation.properties.items()}}
4040

4141
query = (
4242
f"MATCH (source:{source_node.label} {{full_name: $source_name}}), "

src/codegen/extensions/index/code_index.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from abc import ABC, abstractmethod
44
from pathlib import Path
5-
from typing import Optional, TypeVar
5+
from typing import TypeVar
66

77
import numpy as np
88

@@ -34,9 +34,9 @@ def __init__(self, codebase: Codebase):
3434
codebase: The codebase to index
3535
"""
3636
self.codebase = codebase
37-
self.E: Optional[np.ndarray] = None
38-
self.items: Optional[np.ndarray] = None
39-
self.commit_hash: Optional[str] = None
37+
self.E: np.ndarray | None = None
38+
self.items: np.ndarray | None = None
39+
self.commit_hash: str | None = None
4040

4141
@property
4242
@abstractmethod
@@ -151,7 +151,7 @@ def update(self) -> None:
151151
# Update commit hash
152152
self.commit_hash = self._get_current_commit()
153153

154-
def save(self, save_path: Optional[str] = None) -> None:
154+
def save(self, save_path: str | None = None) -> None:
155155
"""Save the index to disk."""
156156
if self.E is None or self.items is None:
157157
msg = "No embeddings to save. Call create() first."
@@ -162,7 +162,7 @@ def save(self, save_path: Optional[str] = None) -> None:
162162

163163
self._save_index(save_path)
164164

165-
def load(self, load_path: Optional[str] = None) -> None:
165+
def load(self, load_path: str | None = None) -> None:
166166
"""Load the index from disk."""
167167
load_path = Path(load_path) if load_path else self._get_default_save_path()
168168

src/codegen/extensions/index/file_index.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import pickle
44
from pathlib import Path
5-
from typing import Optional
65

76
import modal
87
import numpy as np
@@ -87,7 +86,7 @@ def delete_modal_dict(self) -> bool:
8786
logger.exception(f"Failed to delete Modal Dict: {e}")
8887
return False
8988

90-
def modal_dict_exists(self, commit_hash: Optional[str] = None) -> bool:
89+
def modal_dict_exists(self, commit_hash: str | None = None) -> bool:
9190
"""Check if a Modal Dict exists for a specific commit.
9291
9392
Args:

src/codegen/extensions/linear/linear_client.py

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

43
import requests
54
from requests.adapters import HTTPAdapter
@@ -15,7 +14,7 @@ class LinearClient:
1514
api_headers: dict
1615
api_endpoint = "https://api.linear.app/graphql"
1716

18-
def __init__(self, access_token: Optional[str] = None, team_id: Optional[str] = None, max_retries: int = 3, backoff_factor: float = 0.5):
17+
def __init__(self, access_token: str | None = None, team_id: str | None = None, max_retries: int = 3, backoff_factor: float = 0.5):
1918
if not access_token:
2019
access_token = os.getenv("LINEAR_ACCESS_TOKEN")
2120
if not access_token:

0 commit comments

Comments
 (0)