Skip to content

Commit 97dab38

Browse files
bearomorphismLee-W
authored andcommitted
style(BaseConfig): update set_key comments and type annotation, remove duplicated docstring
1 parent c085fd0 commit 97dab38

File tree

4 files changed

+14
-30
lines changed

4 files changed

+14
-30
lines changed

commitizen/config/base_config.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from typing import TYPE_CHECKING, Any
4+
from typing import TYPE_CHECKING
55

66
from commitizen.defaults import DEFAULT_SETTINGS, Settings
77

@@ -33,11 +33,10 @@ def path(self) -> Path:
3333
def path(self, path: Path) -> None:
3434
self._path = Path(path)
3535

36-
def set_key(self, key: str, value: Any) -> Self:
37-
"""Set or update a key in the conf.
36+
def set_key(self, key: str, value: object) -> Self:
37+
"""Set or update a key in the config file.
3838
39-
For now only strings are supported.
40-
We use to update the version number.
39+
Currently, only strings are supported for the parameter key.
4140
"""
4241
raise NotImplementedError()
4342

commitizen/config/json_config.py

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

33
import json
44
from pathlib import Path
5-
from typing import TYPE_CHECKING, Any
5+
from typing import TYPE_CHECKING
66

77
from commitizen.exceptions import InvalidConfigurationError
88
from commitizen.git import smart_open
@@ -31,18 +31,13 @@ def init_empty_config_content(self) -> None:
3131
) as json_file:
3232
json.dump({"commitizen": {}}, json_file)
3333

34-
def set_key(self, key: str, value: Any) -> Self:
35-
"""Set or update a key in the conf.
36-
37-
For now only strings are supported.
38-
We use to update the version number.
39-
"""
34+
def set_key(self, key: str, value: object) -> Self:
4035
with open(self.path, "rb") as f:
41-
parser = json.load(f)
36+
config_doc = json.load(f)
4237

43-
parser["commitizen"][key] = value
38+
config_doc["commitizen"][key] = value
4439
with smart_open(self.path, "w", encoding=self._settings["encoding"]) as f:
45-
json.dump(parser, f, indent=2)
40+
json.dump(config_doc, f, indent=2)
4641
return self
4742

4843
def _parse_setting(self, data: bytes | str) -> None:

commitizen/config/toml_config.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ def init_empty_config_content(self) -> None:
4242
)
4343

4444
def set_key(self, key: str, value: object) -> Self:
45-
"""Set or update a key in the conf.
46-
47-
For now only strings are supported.
48-
We use to update the version number.
49-
"""
5045
with open(self.path, "rb") as f:
5146
config_doc = parse(f.read())
5247

commitizen/config/yaml_config.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from typing import TYPE_CHECKING, Any
4+
from typing import TYPE_CHECKING
55

66
import yaml
77

@@ -52,19 +52,14 @@ def _parse_setting(self, data: bytes | str) -> None:
5252
except (KeyError, TypeError):
5353
self.is_empty_config = True
5454

55-
def set_key(self, key: str, value: Any) -> Self:
56-
"""Set or update a key in the conf.
57-
58-
For now only strings are supported.
59-
We use to update the version number.
60-
"""
55+
def set_key(self, key: str, value: object) -> Self:
6156
with open(self.path, "rb") as yaml_file:
62-
parser = yaml.load(yaml_file, Loader=yaml.FullLoader)
57+
config_doc = yaml.load(yaml_file, Loader=yaml.FullLoader)
6358

64-
parser["commitizen"][key] = value
59+
config_doc["commitizen"][key] = value
6560
with smart_open(
6661
self.path, "w", encoding=self._settings["encoding"]
6762
) as yaml_file:
68-
yaml.dump(parser, yaml_file, explicit_start=True)
63+
yaml.dump(config_doc, yaml_file, explicit_start=True)
6964

7065
return self

0 commit comments

Comments
 (0)