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."""

commitizen/git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def get_commits(
215215
]
216216

217217

218-
def get_filenames_in_commit(git_reference: str = ""):
218+
def get_filenames_in_commit(git_reference: str = "") -> list[str]:
219219
"""Get the list of files that were committed in the requested git reference.
220220
221221
:param git_reference: a git reference as accepted by `git show`, default: the last commit
@@ -312,7 +312,7 @@ def get_core_editor() -> str | None:
312312
return None
313313

314314

315-
def smart_open(*args, **kwargs):
315+
def smart_open(*args, **kwargs): # type: ignore[no-untyped-def,unused-ignore]
316316
"""Open a file with the EOL style determined from Git."""
317317
return open(*args, newline=EOLType.for_open(), **kwargs)
318318

commitizen/hooks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from __future__ import annotations
22

33
import os
4+
from collections.abc import Mapping
45

56
from commitizen import cmd, out
67
from commitizen.exceptions import RunHookError
78

89

9-
def run(hooks, _env_prefix="CZ_", **env):
10+
def run(hooks: str | list[str], _env_prefix: str = "CZ_", **env: object) -> None:
1011
if isinstance(hooks, str):
1112
hooks = [hooks]
1213

@@ -24,7 +25,7 @@ def run(hooks, _env_prefix="CZ_", **env):
2425
raise RunHookError(f"Running hook '{hook}' failed")
2526

2627

27-
def _format_env(prefix: str, env: dict[str, str]) -> dict[str, str]:
28+
def _format_env(prefix: str, env: Mapping[str, object]) -> dict[str, str]:
2829
"""_format_env() prefixes all given environment variables with the given
2930
prefix so it can be passed directly to cmd.run()."""
3031
penv = dict(os.environ)

commitizen/providers/base_provider.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_version(self) -> str:
2929
"""
3030

3131
@abstractmethod
32-
def set_version(self, version: str):
32+
def set_version(self, version: str) -> None:
3333
"""
3434
Set the new current version
3535
"""
@@ -58,15 +58,15 @@ def get_version(self) -> str:
5858
document = json.loads(self.file.read_text())
5959
return self.get(document)
6060

61-
def set_version(self, version: str):
61+
def set_version(self, version: str) -> None:
6262
document = json.loads(self.file.read_text())
6363
self.set(document, version)
6464
self.file.write_text(json.dumps(document, indent=self.indent) + "\n")
6565

6666
def get(self, document: dict[str, Any]) -> str:
6767
return document["version"] # type: ignore
6868

69-
def set(self, document: dict[str, Any], version: str):
69+
def set(self, document: dict[str, Any], version: str) -> None:
7070
document["version"] = version
7171

7272

@@ -79,13 +79,13 @@ def get_version(self) -> str:
7979
document = tomlkit.parse(self.file.read_text())
8080
return self.get(document)
8181

82-
def set_version(self, version: str):
82+
def set_version(self, version: str) -> None:
8383
document = tomlkit.parse(self.file.read_text())
8484
self.set(document, version)
8585
self.file.write_text(tomlkit.dumps(document))
8686

8787
def get(self, document: tomlkit.TOMLDocument) -> str:
8888
return document["project"]["version"] # type: ignore
8989

90-
def set(self, document: tomlkit.TOMLDocument, version: str):
90+
def set(self, document: tomlkit.TOMLDocument, version: str) -> None:
9191
document["project"]["version"] = version # type: ignore

commitizen/providers/cargo_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get(self, document: tomlkit.TOMLDocument) -> str:
2828
...
2929
return document["workspace"]["package"]["version"] # type: ignore
3030

31-
def set(self, document: tomlkit.TOMLDocument, version: str):
31+
def set(self, document: tomlkit.TOMLDocument, version: str) -> None:
3232
try:
3333
document["workspace"]["package"]["version"] = version # type: ignore
3434
return

commitizen/providers/commitizen_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ class CommitizenProvider(VersionProvider):
1111
def get_version(self) -> str:
1212
return self.config.settings["version"] # type: ignore
1313

14-
def set_version(self, version: str):
14+
def set_version(self, version: str) -> None:
1515
self.config.set_key("version", version)

commitizen/providers/poetry_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ class PoetryProvider(TomlProvider):
1515
def get(self, pyproject: tomlkit.TOMLDocument) -> str:
1616
return pyproject["tool"]["poetry"]["version"] # type: ignore
1717

18-
def set(self, pyproject: tomlkit.TOMLDocument, version: str):
18+
def set(self, pyproject: tomlkit.TOMLDocument, version: str) -> None:
1919
pyproject["tool"]["poetry"]["version"] = version # type: ignore

commitizen/providers/scm_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ def get_version(self) -> str:
2323
return "0.0.0"
2424
return str(versions[-1])
2525

26-
def set_version(self, version: str):
26+
def set_version(self, version: str) -> None:
2727
# Not necessary
2828
pass

0 commit comments

Comments
 (0)