Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy improvement #1054

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def commitizen_excepthook(
original_excepthook(type, value, traceback)
exit_code = value.exit_code
if exit_code in no_raise:
exit_code = 0
exit_code = ExitCode.EXPECTED_EXIT
sys.exit(exit_code)
else:
original_excepthook(type, value, traceback)
Expand Down
6 changes: 4 additions & 2 deletions commitizen/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
for arg in (self.commit_msg_file, self.commit_msg, self.rev_range)
)
if num_exclusive_args_provided == 0 and not sys.stdin.isatty():
self.commit_msg: str | None = sys.stdin.read()
self.commit_msg = sys.stdin.read()
elif num_exclusive_args_provided != 1:
raise InvalidCommandArgumentError(
"Only one of --rev-range, --message, and --commit-msg-file is permitted by check command! "
Expand Down Expand Up @@ -106,7 +106,9 @@
return [git.GitCommit(rev="", title="", body=msg)]

# Get commit messages from git log (--rev-range)
return git.get_commits(end=self.rev_range)
if self.rev_range:
return git.get_commits(end=self.rev_range)
return git.get_commits()

Check warning on line 111 in commitizen/commands/check.py

View check run for this annotation

Codecov / codecov/patch

commitizen/commands/check.py#L111

Added line #L111 was not covered by tests

@staticmethod
def _filter_comments(msg: str) -> str:
Expand Down
10 changes: 5 additions & 5 deletions commitizen/cz/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class BaseCommitizen(metaclass=ABCMeta):
template_loader: BaseLoader = PackageLoader("commitizen", "templates")
template_extras: dict[str, Any] = {}

def __init__(self, config: BaseConfig):
def __init__(self, config: BaseConfig) -> None:
self.config = config
if not self.config.settings.get("style"):
self.config.settings.update({"style": BaseCommitizen.default_style_config})
Expand All @@ -83,19 +83,19 @@ def style(self):
]
)

def example(self) -> str | None:
def example(self) -> str:
"""Example of the commit message."""
raise NotImplementedError("Not Implemented yet")

def schema(self) -> str | None:
def schema(self) -> str:
"""Schema definition of the commit message."""
raise NotImplementedError("Not Implemented yet")

def schema_pattern(self) -> str | None:
def schema_pattern(self) -> str:
"""Regex matching the schema used for message validation."""
raise NotImplementedError("Not Implemented yet")

def info(self) -> str | None:
def info(self) -> str:
"""Information about the standardized commit message."""
raise NotImplementedError("Not Implemented yet")

Expand Down
16 changes: 8 additions & 8 deletions commitizen/cz/customize/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ def message(self, answers: dict) -> str:
else:
return message_template.render(**answers)

def example(self) -> str | None:
return self.custom_settings.get("example")
def example(self) -> str:
return self.custom_settings.get("example") or ""

def schema_pattern(self) -> str | None:
return self.custom_settings.get("schema_pattern")
def schema_pattern(self) -> str:
return self.custom_settings.get("schema_pattern") or ""

def schema(self) -> str | None:
return self.custom_settings.get("schema")
def schema(self) -> str:
return self.custom_settings.get("schema") or ""

def info(self) -> str | None:
def info(self) -> str:
info_path = self.custom_settings.get("info_path")
info = self.custom_settings.get("info")
if info_path:
Expand All @@ -86,4 +86,4 @@ def info(self) -> str | None:
return content
elif info:
return info
return None
return ""
2 changes: 1 addition & 1 deletion commitizen/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Settings(TypedDict, total=False):
changelog_merge_prerelease: bool
update_changelog_on_bump: bool
use_shortcuts: bool
style: list[tuple[str, str]] | None
style: list[tuple[str, str]]
customize: CzSettings
major_version_zero: bool
pre_bump_hooks: list[str] | None
Expand Down
2 changes: 1 addition & 1 deletion commitizen/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ExitCode(enum.IntEnum):
class CommitizenException(Exception):
def __init__(self, *args, **kwargs):
self.output_method = kwargs.get("output_method") or out.error
self.exit_code = self.__class__.exit_code
self.exit_code: ExitCode = self.__class__.exit_code
if args:
self.message = args[0]
elif hasattr(self.__class__, "message"):
Expand Down
10 changes: 5 additions & 5 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ commitizen:
| ------------------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `questions` | `Questions` | `None` | Questions regarding the commit message. Detailed below. The type `Questions` is an alias to `Iterable[MutableMapping[str, Any]]` which is defined in `commitizen.defaults`. It expects a list of dictionaries. |
| `message_template` | `str` | `None` | The template for generating message from the given answers. `message_template` should either follow [Jinja2][jinja2] formatting specification, and all the variables in this template should be defined in `name` in `questions` |
| `example` | `str` | `None` | (OPTIONAL) Provide an example to help understand the style. Used by `cz example`. |
| `schema` | `str` | `None` | (OPTIONAL) Show the schema used. Used by `cz schema`. |
| `schema_pattern` | `str` | `None` | (OPTIONAL) The regular expression used to do commit message validation. Used by `cz check`. |
| `info_path` | `str` | `None` | (OPTIONAL) The path to the file that contains explanation of the commit rules. Used by `cz info`. If not provided `cz info`, will load `info` instead. |
| `info` | `str` | `None` | (OPTIONAL) Explanation of the commit rules. Used by `cz info`. |
| `example` | `str` | `""` | (OPTIONAL) Provide an example to help understand the style. Used by `cz example`. |
| `schema` | `str` | `""` | (OPTIONAL) Show the schema used. Used by `cz schema`. |
| `schema_pattern` | `str` | `""` | (OPTIONAL) The regular expression used to do commit message validation. Used by `cz check`. |
| `info_path` | `str` | `""` | (OPTIONAL) The path to the file that contains explanation of the commit rules. Used by `cz info`. If not provided `cz info`, will load `info` instead. |
| `info` | `str` | `""` | (OPTIONAL) Explanation of the commit rules. Used by `cz info`. |
| `bump_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`) |
| `bump_pattern` | `str` | `None` | (OPTIONAL) Regex to extract information from commit (subject and body) |
| `change_type_order`| `str` | `None` | (OPTIONAL) List of strings used to order the Changelog. All other types will be sorted alphabetically. Default is `["BREAKING CHANGE", "Feat", "Fix", "Refactor", "Perf"]` |
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cz_customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def test_info_with_info_path(tmpdir, config_info):

def test_info_without_info(config_without_info):
cz = CustomizeCommitsCz(config_without_info)
assert cz.info() is None
assert cz.info() == ""


def test_commit_parser(config):
Expand Down