Skip to content

Commit 13cd81d

Browse files
committed
fix(types): allow documented None bump_map values
1 parent 6585f2c commit 13cd81d

5 files changed

Lines changed: 36 additions & 10 deletions

File tree

‎commitizen/cz/base.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class ValidationResult(NamedTuple):
3737

3838
class BaseCommitizen(metaclass=ABCMeta):
3939
bump_pattern: str | None = None
40-
bump_map: dict[str, str] | None = None
41-
bump_map_major_version_zero: dict[str, str] | None = None
40+
bump_map: Mapping[str, str | None] | None = None
41+
bump_map_major_version_zero: Mapping[str, str | None] | None = None
4242
default_style_config: list[tuple[str, str]] = [
4343
("qmark", "fg:#ff9d00 bold"),
4444
("question", "bold"),

‎commitizen/cz/conventional_commits/conventional_commits.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from commitizen.cz.utils import multiple_line_breaker, required_validator
99

1010
if TYPE_CHECKING:
11+
from collections.abc import Mapping
12+
1113
from commitizen.question import CzQuestion
1214

1315
__all__ = ["ConventionalCommitsCz"]
@@ -32,8 +34,10 @@ class ConventionalCommitsAnswers(TypedDict):
3234

3335
class ConventionalCommitsCz(BaseCommitizen):
3436
bump_pattern = defaults.BUMP_PATTERN
35-
bump_map = defaults.BUMP_MAP
36-
bump_map_major_version_zero = defaults.BUMP_MAP_MAJOR_VERSION_ZERO
37+
bump_map: Mapping[str, str | None] = defaults.BUMP_MAP
38+
bump_map_major_version_zero: Mapping[str, str | None] = (
39+
defaults.BUMP_MAP_MAJOR_VERSION_ZERO
40+
)
3741
commit_parser = r"^((?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?|\w+!):\s(?P<message>.*)?"
3842
change_type_map = {
3943
"feat": "Feat",

‎commitizen/cz/customize/customize.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828

2929
def _derive_major_version_zero(
30-
bump_map: Mapping[str, str],
31-
) -> OrderedDict[str, str]:
30+
bump_map: Mapping[str, str | None],
31+
) -> OrderedDict[str, str | None]:
3232
"""Derive a ``bump_map_major_version_zero`` from a user-supplied
3333
``bump_map`` by demoting any ``MAJOR`` rule to ``MINOR``.
3434
@@ -45,8 +45,10 @@ def _derive_major_version_zero(
4545

4646
class CustomizeCommitsCz(BaseCommitizen):
4747
bump_pattern = defaults.BUMP_PATTERN
48-
bump_map = defaults.BUMP_MAP
49-
bump_map_major_version_zero = defaults.BUMP_MAP_MAJOR_VERSION_ZERO
48+
bump_map: Mapping[str, str | None] = defaults.BUMP_MAP
49+
bump_map_major_version_zero: Mapping[str, str | None] = (
50+
defaults.BUMP_MAP_MAJOR_VERSION_ZERO
51+
)
5052
change_type_order = defaults.CHANGE_TYPE_ORDER
5153

5254
def __init__(self, config: BaseConfig) -> None:

‎commitizen/defaults.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
class CzSettings(TypedDict, total=False):
1515
bump_pattern: str
16-
bump_map: OrderedDict[str, str]
17-
bump_map_major_version_zero: OrderedDict[str, str]
16+
bump_map: OrderedDict[str, str | None]
17+
bump_map_major_version_zero: OrderedDict[str, str | None]
1818
change_type_order: list[str]
1919

2020
questions: Iterable[CzQuestion]

‎tests/commands/test_bump_command.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,26 @@ def test_bump_allow_no_commit_with_string_none_bump_map_raises(
14061406
assert git.tag_exist("0.1.2") is False
14071407

14081408

1409+
@pytest.mark.usefixtures("tmp_commitizen_project")
1410+
def test_bump_python_plugin_none_bump_map_is_a_supported_no_bump_value(
1411+
util: UtilFixture, mock_plugin: BaseCommitizen
1412+
) -> None:
1413+
"""A Python plugin may use ``None`` to match without bumping."""
1414+
mock_plugin.bump_pattern = r"^(docs|fix)"
1415+
mock_plugin.bump_map = {"docs": None, "fix": "PATCH"}
1416+
mock_plugin.bump_map_major_version_zero = {"docs": None, "fix": "PATCH"}
1417+
1418+
util.create_file_and_commit("fix: seed release")
1419+
util.run_cli("bump", "--yes")
1420+
util.create_file_and_commit("docs: update guide")
1421+
1422+
with pytest.raises(NoneIncrementExit):
1423+
util.run_cli("bump", "--yes")
1424+
1425+
util.run_cli("bump", "--yes", "--allow-no-commit")
1426+
assert git.tag_exist("0.1.2") is True
1427+
1428+
14091429
def test_bump_allow_no_commit_with_increment(
14101430
tmp_commitizen_project, monkeypatch, util: UtilFixture, capsys
14111431
):

0 commit comments

Comments
 (0)