Skip to content

Commit 88f4c79

Browse files
committed
🔄 Refactor CommitMessage model for Python 3.10+ compatibility
- Replace Optional[str] with str | None for type hinting - Reorder fields for better results - Remove unnecessary comment and noqa directive
1 parent d7795a5 commit 88f4c79

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

aicodebot/commands/commit.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
from pathlib import Path
77
from pydantic import BaseModel, Field
88
from rich.panel import Panel
9-
from typing import Optional
109
import click, os, shutil, subprocess, sys, tempfile
1110

1211

1312
class CommitMessage(BaseModel):
14-
# Use Optional[str] instead of str | None for Python 3.9 compatibility
15-
git_message_detail: Optional[str] = Field( # noqa: UP007
13+
# Note we get better results if the message_detail is first.
14+
git_message_detail: str | None = Field(
1615
default="",
1716
description="An optional detailed explanation of the changes made in this commit,"
1817
" if the summary doesn't provide enough context",
@@ -103,9 +102,9 @@ def commit(response_token_size, yes, skip_pre_commit, files): # noqa: PLR0915
103102
chain = prompt | structured_llm
104103
response = chain.invoke({"diff_context": diff_context, "languages": languages})
105104

106-
commit_message = response["git_message_summary"]
107-
if response.get("git_message_detail"):
108-
commit_message += f"\n\n{response['git_message_detail']}"
105+
commit_message = response.git_message_summary
106+
if response.git_message_detail:
107+
commit_message += f"\n\n{response.git_message_detail}"
109108

110109
console.print(Panel(OurMarkdown(commit_message)))
111110

0 commit comments

Comments
 (0)