Skip to content

refactor(BaseConfig): update function name, upgrade mypy version #1444

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

Merged
merged 2 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
refactor(BaseConfig): use setter
  • Loading branch information
bearomorphism committed May 22, 2025
commit 6a54286e1479aeea9ca6b34098389f545c6568aa
12 changes: 9 additions & 3 deletions commitizen/config/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ def settings(self) -> Settings:
def path(self) -> Path | None:
return self._path

@path.setter
def path(self, path: str | Path) -> None:
"""
mypy does not like this until 1.16
See https://github.com/python/mypy/pull/18510
TODO: remove "type: ignore" from the call sites when 1.16 is available
"""
self._path = Path(path)

def set_key(self, key, value):
"""Set or update a key in the conf.

Expand All @@ -30,8 +39,5 @@ def set_key(self, key, value):
def update(self, data: Settings) -> None:
self._settings.update(data)

def add_path(self, path: str | Path) -> None:
self._path = Path(path)

def _parse_setting(self, data: bytes | str) -> None:
raise NotImplementedError()
2 changes: 1 addition & 1 deletion commitizen/config/json_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class JsonConfig(BaseConfig):
def __init__(self, *, data: bytes | str, path: Path | str):
super().__init__()
self.is_empty_config = False
self.add_path(path)
self.path = path # type: ignore
self._parse_setting(data)

def init_empty_config_content(self):
Expand Down
2 changes: 1 addition & 1 deletion commitizen/config/toml_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TomlConfig(BaseConfig):
def __init__(self, *, data: bytes | str, path: Path | str):
super().__init__()
self.is_empty_config = False
self.add_path(path)
self.path = path # type: ignore
self._parse_setting(data)

def init_empty_config_content(self):
Expand Down
2 changes: 1 addition & 1 deletion commitizen/config/yaml_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class YAMLConfig(BaseConfig):
def __init__(self, *, data: bytes | str, path: Path | str):
super().__init__()
self.is_empty_config = False
self.add_path(path)
self.path = path # type: ignore
self._parse_setting(data)

def init_empty_config_content(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/test_init_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_init_without_setup_pre_commit_hook(tmpdir, mocker: MockFixture, config)
def test_init_when_config_already_exists(config, capsys):
# Set config path
path = os.sep.join(["tests", "pyproject.toml"])
config.add_path(path)
config.path = path

commands.Init(config)()
captured = capsys.readouterr()
Expand Down
4 changes: 3 additions & 1 deletion tests/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,9 @@ def test_tags_rules_get_version_tags(capsys: pytest.CaptureFixture):

def test_changelog_file_name_from_args_and_config():
mock_config = Mock(spec=BaseConfig)
mock_config.path.parent = "/my/project"
mock_path = Mock(spec=Path)
mock_path.parent = Path("/my/project")
mock_config.path = mock_path
mock_config.settings = {
"name": "cz_conventional_commits",
"changelog_file": "CHANGELOG.md",
Expand Down