Skip to content

Commit f8e56ab

Browse files
committed
style: type untyped methods
1 parent 4892945 commit f8e56ab

17 files changed

+41
-36
lines changed

commitizen/changelog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Metadata:
6363
latest_version_position: int | None = None
6464
latest_version_tag: str | None = None
6565

66-
def __post_init__(self):
66+
def __post_init__(self) -> None:
6767
if self.latest_version and not self.latest_version_tag:
6868
# Test syntactic sugar
6969
# latest version tag is optional if same as latest version
@@ -169,8 +169,8 @@ def process_commit_message(
169169
commit: GitCommit,
170170
changes: dict[str | None, list],
171171
change_type_map: dict[str, str] | None = None,
172-
):
173-
message: dict = {
172+
) -> None:
173+
message: dict[str, Any] = {
174174
"sha1": commit.rev,
175175
"parents": commit.parents,
176176
"author": commit.author,

commitizen/commands/changelog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _find_incremental_rev(self, latest_version: str, tags: Iterable[GitTag]) ->
138138

139139
def _write_changelog(
140140
self, changelog_out: str, lines: list[str], changelog_meta: changelog.Metadata
141-
):
141+
) -> None:
142142
with smart_open(self.file_name, "w", encoding=self.encoding) as changelog_file:
143143
partial_changelog: str | None = None
144144
if self.incremental:

commitizen/commands/example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
class Example:
66
"""Show an example so people understands the rules."""
77

8-
def __init__(self, config: BaseConfig, *args):
8+
def __init__(self, config: BaseConfig, *args: object):
99
self.config: BaseConfig = config
1010
self.cz = factory.committer_factory(self.config)
1111

12-
def __call__(self):
12+
def __call__(self) -> None:
1313
out.write(self.cz.example())

commitizen/commands/init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def is_pre_commit_installed(self) -> bool:
7979

8080

8181
class Init:
82-
def __init__(self, config: BaseConfig, *args):
82+
def __init__(self, config: BaseConfig, *args: object):
8383
self.config: BaseConfig = config
8484
self.encoding = config.settings["encoding"]
8585
self.cz = factory.committer_factory(self.config)

commitizen/commands/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
class Schema:
66
"""Show structure of the rule."""
77

8-
def __init__(self, config: BaseConfig, *args):
8+
def __init__(self, config: BaseConfig, *args: object):
99
self.config: BaseConfig = config
1010
self.cz = factory.committer_factory(self.config)
1111

12-
def __call__(self):
12+
def __call__(self) -> None:
1313
out.write(self.cz.schema())

commitizen/config/base_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4+
from typing import Any, Self
45

56
from commitizen.defaults import DEFAULT_SETTINGS, Settings
67

@@ -28,7 +29,7 @@ def path(self, path: str | Path) -> None:
2829
"""
2930
self._path = Path(path)
3031

31-
def set_key(self, key, value):
32+
def set_key(self, key: str, value: Any) -> Self:
3233
"""Set or update a key in the conf.
3334
3435
For now only strings are supported.

commitizen/config/json_config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
from pathlib import Path
5+
from typing import Any, Self
56

67
from commitizen.exceptions import InvalidConfigurationError
78
from commitizen.git import smart_open
@@ -13,14 +14,14 @@ class JsonConfig(BaseConfig):
1314
def __init__(self, *, data: bytes | str, path: Path | str):
1415
super().__init__()
1516
self.is_empty_config = False
16-
self.path = path # type: ignore
17+
self.path: Path = path # type: ignore
1718
self._parse_setting(data)
1819

19-
def init_empty_config_content(self):
20+
def init_empty_config_content(self) -> None:
2021
with smart_open(self.path, "a", encoding=self.encoding) as json_file:
2122
json.dump({"commitizen": {}}, json_file)
2223

23-
def set_key(self, key, value):
24+
def set_key(self, key: str, value: Any) -> Self:
2425
"""Set or update a key in the conf.
2526
2627
For now only strings are supported.

commitizen/config/toml_config.py

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

33
import os
44
from pathlib import Path
5+
from typing import Any, Self
56

67
from tomlkit import exceptions, parse, table
78

@@ -14,10 +15,10 @@ class TomlConfig(BaseConfig):
1415
def __init__(self, *, data: bytes | str, path: Path | str):
1516
super().__init__()
1617
self.is_empty_config = False
17-
self.path = path # type: ignore
18+
self.path: Path = path # type: ignore
1819
self._parse_setting(data)
1920

20-
def init_empty_config_content(self):
21+
def init_empty_config_content(self) -> None:
2122
if os.path.isfile(self.path):
2223
with open(self.path, "rb") as input_toml_file:
2324
parser = parse(input_toml_file.read())
@@ -27,10 +28,10 @@ def init_empty_config_content(self):
2728
with open(self.path, "wb") as output_toml_file:
2829
if parser.get("tool") is None:
2930
parser["tool"] = table()
30-
parser["tool"]["commitizen"] = table()
31+
parser["tool"]["commitizen"] = table() # type: ignore
3132
output_toml_file.write(parser.as_string().encode(self.encoding))
3233

33-
def set_key(self, key, value):
34+
def set_key(self, key: str, value: Any) -> Self:
3435
"""Set or update a key in the conf.
3536
3637
For now only strings are supported.
@@ -39,7 +40,7 @@ def set_key(self, key, value):
3940
with open(self.path, "rb") as f:
4041
parser = parse(f.read())
4142

42-
parser["tool"]["commitizen"][key] = value
43+
parser["tool"]["commitizen"][key] = value # type: ignore
4344
with open(self.path, "wb") as f:
4445
f.write(parser.as_string().encode(self.encoding))
4546
return self

commitizen/config/yaml_config.py

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

33
from pathlib import Path
4+
from typing import Any, Self
45

56
import yaml
67

@@ -14,10 +15,10 @@ class YAMLConfig(BaseConfig):
1415
def __init__(self, *, data: bytes | str, path: Path | str):
1516
super().__init__()
1617
self.is_empty_config = False
17-
self.path = path # type: ignore
18+
self.path: Path = path # type: ignore
1819
self._parse_setting(data)
1920

20-
def init_empty_config_content(self):
21+
def init_empty_config_content(self) -> None:
2122
with smart_open(self.path, "a", encoding=self.encoding) as json_file:
2223
yaml.dump({"commitizen": {}}, json_file, explicit_start=True)
2324

@@ -41,7 +42,7 @@ def _parse_setting(self, data: bytes | str) -> None:
4142
except (KeyError, TypeError):
4243
self.is_empty_config = True
4344

44-
def set_key(self, key, value):
45+
def set_key(self, key: str, value: Any) -> Self:
4546
"""Set or update a key in the conf.
4647
4748
For now only strings are supported.

commitizen/cz/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ def message(self, answers: dict) -> str:
7676
"""Format your git message."""
7777

7878
@property
79-
def style(self):
79+
def style(self) -> Style:
8080
return merge_styles(
8181
[
8282
Style(BaseCommitizen.default_style_config),
8383
Style(self.config.settings["style"]),
8484
]
85-
)
85+
) # type: ignore[return-value]
8686

8787
def example(self) -> str:
8888
"""Example of the commit message."""

0 commit comments

Comments
 (0)