Skip to content

Commit 1f8c4bc

Browse files
committed
refactor(commit): type commit args
1 parent e67ba23 commit 1f8c4bc

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

commitizen/commands/commit.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import subprocess
77
import tempfile
88
from pathlib import Path
9-
from typing import Union, cast
9+
from typing import TypedDict
1010

1111
import questionary
1212

@@ -28,10 +28,22 @@
2828
from commitizen.git import smart_open
2929

3030

31+
class CommitArgs(TypedDict, total=False):
32+
all: bool
33+
dry_run: bool
34+
edit: bool
35+
extra_cli_args: str
36+
message_length_limit: int
37+
no_retry: bool
38+
signoff: bool
39+
write_message_to_file: Path | None
40+
retry: bool
41+
42+
3143
class Commit:
3244
"""Show prompt for the user to create a guided commit."""
3345

34-
def __init__(self, config: BaseConfig, arguments: dict) -> None:
46+
def __init__(self, config: BaseConfig, arguments: CommitArgs) -> None:
3547
if not git.is_git_project():
3648
raise NotAGitProjectError()
3749

@@ -69,7 +81,7 @@ def _prompt_commit_questions(self) -> str:
6981

7082
message = cz.message(answers)
7183
message_len = len(message.partition("\n")[0].strip())
72-
message_length_limit: int = self.arguments.get("message_length_limit", 0)
84+
message_length_limit = self.arguments.get("message_length_limit", 0)
7385
if 0 < message_length_limit < message_len:
7486
raise CommitMessageLengthExceededError(
7587
f"Length of commit message exceeds limit ({message_len}/{message_length_limit})"
@@ -108,12 +120,10 @@ def _get_message(self) -> str:
108120
return self._prompt_commit_questions()
109121

110122
def __call__(self) -> None:
111-
extra_args = cast(str, self.arguments.get("extra_cli_args", ""))
112-
dry_run = cast(bool, self.arguments.get("dry_run"))
113-
write_message_to_file = cast(
114-
Union[Path, None], self.arguments.get("write_message_to_file")
115-
)
116-
signoff = cast(bool, self.arguments.get("signoff"))
123+
extra_args = self.arguments.get("extra_cli_args", "")
124+
dry_run = bool(self.arguments.get("dry_run"))
125+
write_message_to_file = self.arguments.get("write_message_to_file")
126+
signoff = bool(self.arguments.get("signoff"))
117127

118128
if self.arguments.get("all"):
119129
git.add("-u")

0 commit comments

Comments
 (0)