Skip to content

Commit 2c3d5d0

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

17 files changed

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

3+
import sys
34
from pathlib import Path
5+
from typing import TYPE_CHECKING, Any
46

57
from commitizen.defaults import DEFAULT_SETTINGS, Settings
68

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

819
class BaseConfig:
920
def __init__(self) -> None:
@@ -28,7 +39,7 @@ def path(self, path: str | Path) -> None:
2839
"""
2940
self._path = Path(path)
3041

31-
def set_key(self, key, value):
42+
def set_key(self, key: str, value: Any) -> Self:
3243
"""Set or update a key in the conf.
3344
3445
For now only strings are supported.

commitizen/config/json_config.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
from __future__ import annotations
22

33
import json
4+
import sys
45
from pathlib import Path
6+
from typing import TYPE_CHECKING, Any
57

68
from commitizen.exceptions import InvalidConfigurationError
79
from commitizen.git import smart_open
810

911
from .base_config import BaseConfig
1012

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+
1122

1223
class JsonConfig(BaseConfig):
1324
def __init__(self, *, data: bytes | str, path: Path | str):
1425
super().__init__()
1526
self.is_empty_config = False
16-
self.path = path # type: ignore
27+
self.path: Path = path # type: ignore
1728
self._parse_setting(data)
1829

19-
def init_empty_config_content(self):
30+
def init_empty_config_content(self) -> None:
2031
with smart_open(self.path, "a", encoding=self.encoding) as json_file:
2132
json.dump({"commitizen": {}}, json_file)
2233

23-
def set_key(self, key, value):
34+
def set_key(self, key: str, value: Any) -> Self:
2435
"""Set or update a key in the conf.
2536
2637
For now only strings are supported.

commitizen/config/toml_config.py

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

33
import os
4+
import sys
45
from pathlib import Path
6+
from typing import TYPE_CHECKING, Any
57

68
from tomlkit import exceptions, parse, table
79

810
from commitizen.exceptions import InvalidConfigurationError
911

1012
from .base_config import BaseConfig
1113

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

1324
class TomlConfig(BaseConfig):
1425
def __init__(self, *, data: bytes | str, path: Path | str):
1526
super().__init__()
1627
self.is_empty_config = False
17-
self.path = path # type: ignore
28+
self.path: Path = path # type: ignore
1829
self._parse_setting(data)
1930

20-
def init_empty_config_content(self):
31+
def init_empty_config_content(self) -> None:
2132
if os.path.isfile(self.path):
2233
with open(self.path, "rb") as input_toml_file:
2334
parser = parse(input_toml_file.read())
@@ -27,10 +38,10 @@ def init_empty_config_content(self):
2738
with open(self.path, "wb") as output_toml_file:
2839
if parser.get("tool") is None:
2940
parser["tool"] = table()
30-
parser["tool"]["commitizen"] = table()
41+
parser["tool"]["commitizen"] = table() # type: ignore
3142
output_toml_file.write(parser.as_string().encode(self.encoding))
3243

33-
def set_key(self, key, value):
44+
def set_key(self, key: str, value: Any) -> Self:
3445
"""Set or update a key in the conf.
3546
3647
For now only strings are supported.
@@ -39,7 +50,7 @@ def set_key(self, key, value):
3950
with open(self.path, "rb") as f:
4051
parser = parse(f.read())
4152

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

commitizen/config/yaml_config.py

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

3+
import sys
34
from pathlib import Path
5+
from typing import TYPE_CHECKING, Any
46

57
import yaml
68

@@ -9,15 +11,24 @@
911

1012
from .base_config import BaseConfig
1113

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

1324
class YAMLConfig(BaseConfig):
1425
def __init__(self, *, data: bytes | str, path: Path | str):
1526
super().__init__()
1627
self.is_empty_config = False
17-
self.path = path # type: ignore
28+
self.path: Path = path # type: ignore
1829
self._parse_setting(data)
1930

20-
def init_empty_config_content(self):
31+
def init_empty_config_content(self) -> None:
2132
with smart_open(self.path, "a", encoding=self.encoding) as json_file:
2233
yaml.dump({"commitizen": {}}, json_file, explicit_start=True)
2334

@@ -41,7 +52,7 @@ def _parse_setting(self, data: bytes | str) -> None:
4152
except (KeyError, TypeError):
4253
self.is_empty_config = True
4354

44-
def set_key(self, key, value):
55+
def set_key(self, key: str, value: Any) -> Self:
4556
"""Set or update a key in the conf.
4657
4758
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)