Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4fd84b2

Browse files
committed
style(commands/check): improve type checking
1 parent caaa696 commit 4fd84b2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

commitizen/commands/check.py

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

33
import re
44
import sys
5+
from collections.abc import Generator
56
from typing import Any
67

78
from commitizen import factory, git, out
@@ -32,7 +33,6 @@ def __init__(self, config: BaseConfig, arguments: dict[str, Any]) -> None:
3233
self.max_msg_length: int = arguments.get("message_length_limit", 0)
3334

3435
# we need to distinguish between None and [], which is a valid value
35-
3636
allowed_prefixes = arguments.get("allowed_prefixes")
3737
self.allowed_prefixes: list[str] = (
3838
allowed_prefixes
@@ -46,7 +46,7 @@ def __init__(self, config: BaseConfig, arguments: dict[str, Any]) -> None:
4646
self.encoding = config.settings["encoding"]
4747
self.cz = factory.commiter_factory(self.config)
4848

49-
def _valid_command_argument(self):
49+
def _valid_command_argument(self) -> None:
5050
num_exclusive_args_provided = sum(
5151
arg is not None
5252
for arg in (self.commit_msg_file, self.commit_msg, self.rev_range)
@@ -59,7 +59,7 @@ def _valid_command_argument(self):
5959
"See 'cz check -h' for more information"
6060
)
6161

62-
def __call__(self):
62+
def __call__(self) -> None:
6363
"""Validate if commit messages follows the conventional pattern.
6464
6565
Raises:
@@ -70,12 +70,12 @@ def __call__(self):
7070
raise NoCommitsFoundError(f"No commit found with range: '{self.rev_range}'")
7171

7272
pattern = self.cz.schema_pattern()
73-
ill_formated_commits = [
73+
ill_formated_commits: Generator[git.GitCommit] = (
7474
commit
7575
for commit in commits
7676
if not self.validate_commit_message(commit.message, pattern)
77-
]
78-
displayed_msgs_content = "\n".join(
77+
)
78+
displayed_msgs_content: str = "\n".join(
7979
[
8080
f'commit "{commit.rev}": "{commit.message}"'
8181
for commit in ill_formated_commits
@@ -90,7 +90,8 @@ def __call__(self):
9090
)
9191
out.success("Commit validation: successful!")
9292

93-
def _get_commits(self):
93+
def _get_commits(self) -> list[git.GitCommit]:
94+
# TODO: this method seems to do a few different things. probably would be better if we could split it to smaller functions
9495
msg = None
9596
# Get commit message from file (--commit-msg-file)
9697
if self.commit_msg_file is not None:

0 commit comments

Comments
 (0)