Skip to content

Commit fd89bf7

Browse files
committed
style(BaseConfig): update set_key comments and type annotation, remove duplicated docstring
1 parent 14c924e commit fd89bf7

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: str | 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
@@ -30,18 +30,13 @@ def init_empty_config_content(self) -> None:
3030
with smart_open(self.path, "a", encoding=self.encoding) as json_file:
3131
json.dump({"commitizen": {}}, json_file)
3232

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

42-
parser["commitizen"][key] = value
37+
config_doc["commitizen"][key] = value
4338
with smart_open(self.path, "w", encoding=self.encoding) as f:
44-
json.dump(parser, f, indent=2)
39+
json.dump(config_doc, f, indent=2)
4540
return self
4641

4742
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
@@ -41,11 +41,6 @@ def init_empty_config_content(self) -> None:
4141
output_toml_file.write(config_doc.as_string().encode(self.encoding))
4242

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

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

@@ -51,17 +51,12 @@ def _parse_setting(self, data: bytes | str) -> None:
5151
except (KeyError, TypeError):
5252
self.is_empty_config = True
5353

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

63-
parser["commitizen"][key] = value
58+
config_doc["commitizen"][key] = value
6459
with smart_open(self.path, "w", encoding=self.encoding) as yaml_file:
65-
yaml.dump(parser, yaml_file, explicit_start=True)
60+
yaml.dump(config_doc, yaml_file, explicit_start=True)
6661

6762
return self

0 commit comments

Comments
 (0)