From bef33f72a4e86f9ec99eb4f6d5f10c737e365e4b Mon Sep 17 00:00:00 2001 From: Tim Hsiung Date: Fri, 8 May 2026 16:18:38 +0800 Subject: [PATCH] fix(types): correct nullability of config fields in command TypedDicts Several command TypedDicts declared fields as non-nullable (int, str, dict, list) while argparse produces None when CLI flags are omitted. Runtime code already handles None correctly, but the type annotations were misleading. Changes: - CommitArgs: message_length_limit int -> int | None - CheckArgs: message_length_limit int -> int | None, allowed_prefixes list[str] -> list[str] | None - BumpArgs: file_name str -> str | None - ChangelogArgs: file_name, start_rev, tag_format, version_scheme, export_template, template str -> str | None; extras dict[str, Any] -> dict[str, Any] | None Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- commitizen/commands/bump.py | 2 +- commitizen/commands/changelog.py | 14 +++++++------- commitizen/commands/check.py | 4 ++-- commitizen/commands/commit.py | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 0b6e0ffa3..d3ae0f1b7 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -47,7 +47,7 @@ class BumpArgs(Settings, total=False): check_consistency: bool devrelease: int | None dry_run: bool - file_name: str + file_name: str | None files_only: bool | None version_files_only: bool | None get_next: bool # TODO: maybe rename to `next_version_to_stdout` diff --git a/commitizen/commands/changelog.py b/commitizen/commands/changelog.py index 5521da373..78fc7bea8 100644 --- a/commitizen/commands/changelog.py +++ b/commitizen/commands/changelog.py @@ -31,17 +31,17 @@ class ChangelogArgs(TypedDict, total=False): change_type_order: list[str] current_version: str dry_run: bool - file_name: str + file_name: str | None incremental: bool merge_prerelease: bool rev_range: str - start_rev: str - tag_format: str + start_rev: str | None + tag_format: str | None unreleased_version: str | None - version_scheme: str - template: str - extras: dict[str, Any] - export_template: str + version_scheme: str | None + template: str | None + extras: dict[str, Any] | None + export_template: str | None during_version_bump: bool | None allow_no_commit: bool | None # Internal-only when invoked by bump. diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index ab5e671d6..84ac4f9ee 100644 --- a/commitizen/commands/check.py +++ b/commitizen/commands/check.py @@ -21,8 +21,8 @@ class CheckArgs(TypedDict, total=False): commit_msg: str rev_range: str allow_abort: bool - message_length_limit: int - allowed_prefixes: list[str] + message_length_limit: int | None + allowed_prefixes: list[str] | None message: str use_default_range: bool diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index 178df2c82..67ac782f6 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -35,7 +35,7 @@ class CommitArgs(TypedDict, total=False): dry_run: bool edit: bool extra_cli_args: list[str] - message_length_limit: int + message_length_limit: int | None no_retry: bool signoff: bool write_message_to_file: Path | None