Skip to content

Commit 424e277

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

17 files changed

+77
-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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
from __future__ import annotations
22

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

56
from commitizen.defaults import DEFAULT_SETTINGS, Settings
67

8+
if TYPE_CHECKING:
9+
import sys
10+
11+
# Self is Python 3.11+ but backported in typing-extensions
12+
if sys.version_info < (3, 11):
13+
from typing_extensions import Self
14+
else:
15+
from typing import Self
16+
717

818
class BaseConfig:
919
def __init__(self) -> None:
@@ -28,7 +38,7 @@ def path(self, path: str | Path) -> None:
2838
"""
2939
self._path = Path(path)
3040

31-
def set_key(self, key, value):
41+
def set_key(self, key: str, value: Any) -> Self:
3242
"""Set or update a key in the conf.
3343
3444
For now only strings are supported.

commitizen/config/json_config.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,35 @@
22

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

67
from commitizen.exceptions import InvalidConfigurationError
78
from commitizen.git import smart_open
89

910
from .base_config import BaseConfig
1011

12+
if TYPE_CHECKING:
13+
import sys
14+
15+
# Self is Python 3.11+ but backported in typing-extensions
16+
if sys.version_info < (3, 11):
17+
from typing_extensions import Self
18+
else:
19+
from typing import Self
20+
1121

1222
class JsonConfig(BaseConfig):
1323
def __init__(self, *, data: bytes | str, path: Path | str):
1424
super().__init__()
1525
self.is_empty_config = False
16-
self.path = path # type: ignore
26+
self.path: Path = path # type: ignore
1727
self._parse_setting(data)
1828

19-
def init_empty_config_content(self):
29+
def init_empty_config_content(self) -> None:
2030
with smart_open(self.path, "a", encoding=self.encoding) as json_file:
2131
json.dump({"commitizen": {}}, json_file)
2232

23-
def set_key(self, key, value):
33+
def set_key(self, key: str, value: Any) -> Self:
2434
"""Set or update a key in the conf.
2535
2636
For now only strings are supported.

commitizen/config/toml_config.py

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

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

67
from tomlkit import exceptions, parse, table
78

89
from commitizen.exceptions import InvalidConfigurationError
910

1011
from .base_config import BaseConfig
1112

13+
if TYPE_CHECKING:
14+
import sys
15+
16+
# Self is Python 3.11+ but backported in typing-extensions
17+
if sys.version_info < (3, 11):
18+
from typing_extensions import Self
19+
else:
20+
from typing import Self
21+
1222

1323
class TomlConfig(BaseConfig):
1424
def __init__(self, *, data: bytes | str, path: Path | str):
1525
super().__init__()
1626
self.is_empty_config = False
17-
self.path = path # type: ignore
27+
self.path: Path = path # type: ignore
1828
self._parse_setting(data)
1929

20-
def init_empty_config_content(self):
30+
def init_empty_config_content(self) -> None:
2131
if os.path.isfile(self.path):
2232
with open(self.path, "rb") as input_toml_file:
2333
parser = parse(input_toml_file.read())
@@ -27,10 +37,10 @@ def init_empty_config_content(self):
2737
with open(self.path, "wb") as output_toml_file:
2838
if parser.get("tool") is None:
2939
parser["tool"] = table()
30-
parser["tool"]["commitizen"] = table()
40+
parser["tool"]["commitizen"] = table() # type: ignore
3141
output_toml_file.write(parser.as_string().encode(self.encoding))
3242

33-
def set_key(self, key, value):
43+
def set_key(self, key: str, value: Any) -> Self:
3444
"""Set or update a key in the conf.
3545
3646
For now only strings are supported.
@@ -39,7 +49,7 @@ def set_key(self, key, value):
3949
with open(self.path, "rb") as f:
4050
parser = parse(f.read())
4151

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

commitizen/config/yaml_config.py

Lines changed: 13 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 TYPE_CHECKING, Any
45

56
import yaml
67

@@ -9,15 +10,24 @@
910

1011
from .base_config import BaseConfig
1112

13+
if TYPE_CHECKING:
14+
import sys
15+
16+
# Self is Python 3.11+ but backported in typing-extensions
17+
if sys.version_info < (3, 11):
18+
from typing_extensions import Self
19+
else:
20+
from typing import Self
21+
1222

1323
class YAMLConfig(BaseConfig):
1424
def __init__(self, *, data: bytes | str, path: Path | str):
1525
super().__init__()
1626
self.is_empty_config = False
17-
self.path = path # type: ignore
27+
self.path: Path = path # type: ignore
1828
self._parse_setting(data)
1929

20-
def init_empty_config_content(self):
30+
def init_empty_config_content(self) -> None:
2131
with smart_open(self.path, "a", encoding=self.encoding) as json_file:
2232
yaml.dump({"commitizen": {}}, json_file, explicit_start=True)
2333

@@ -41,7 +51,7 @@ def _parse_setting(self, data: bytes | str) -> None:
4151
except (KeyError, TypeError):
4252
self.is_empty_config = True
4353

44-
def set_key(self, key, value):
54+
def set_key(self, key: str, value: Any) -> Self:
4555
"""Set or update a key in the conf.
4656
4757
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)