Skip to content

Commit 8bd5d71

Browse files
committed
style(mypy): add return type to all functions
1 parent 59ce084 commit 8bd5d71

File tree

8 files changed

+32
-17
lines changed

8 files changed

+32
-17
lines changed

commitizen/bump.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def generate_version(
132132

133133
def update_version_in_files(
134134
current_version: str, new_version: str, files: List[str], *, check_consistency=False
135-
):
135+
) -> None:
136136
"""Change old version to the new one in every file given.
137137
138138
Note that this version is not the tag formatted one.
@@ -196,7 +196,7 @@ def _version_to_regex(version: str):
196196
return re.compile(f"{clean_regex}")
197197

198198

199-
def create_tag(version: Union[Version, str], tag_format: Optional[str] = None):
199+
def create_tag(version: Union[Version, str], tag_format: Optional[str] = None) -> str:
200200
"""The tag and the software version might be different.
201201
202202
That's why this function exists.

commitizen/config/base_config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def set_key(self, key, value):
2525
"""
2626
raise NotImplementedError()
2727

28-
def update(self, data: dict):
28+
def update(self, data: dict) -> None:
2929
self._settings.update(data)
3030

31-
def add_path(self, path: Union[str, Path]):
31+
def add_path(self, path: Union[str, Path]) -> None:
3232
self._path = Path(path)
3333

34-
def _parse_setting(self, data: Union[bytes, str]) -> dict:
34+
def _parse_setting(self, data: Union[bytes, str]) -> None:
3535
raise NotImplementedError()

commitizen/config/json_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def set_key(self, key, value):
3030
json.dump(parser, f, indent=2)
3131
return self
3232

33-
def _parse_setting(self, data: Union[bytes, str]):
33+
def _parse_setting(self, data: Union[bytes, str]) -> None:
3434
"""We expect to have a section in .cz.json looking like
3535
3636
```

commitizen/config/toml_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def set_key(self, key, value):
4141
f.write(parser.as_string().encode("utf-8"))
4242
return self
4343

44-
def _parse_setting(self, data: Union[bytes, str]):
44+
def _parse_setting(self, data: Union[bytes, str]) -> None:
4545
"""We expect to have a section in pyproject looking like
4646
4747
```

commitizen/config/yaml_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def init_empty_config_content(self):
1717
with open(self.path, "a") as json_file:
1818
yaml.dump({"commitizen": {}}, json_file)
1919

20-
def _parse_setting(self, data: Union[bytes, str]):
20+
def _parse_setting(self, data: Union[bytes, str]) -> None:
2121
"""We expect to have a section in cz.yaml looking like
2222
2323
```

commitizen/defaults.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
from collections import OrderedDict
2-
from typing import Any, Dict, List
2+
from typing import List, Optional, TypedDict
3+
4+
5+
# Type
6+
class Settings(TypedDict):
7+
name: str
8+
version: Optional[str]
9+
version_files: List[str]
10+
tag_format: Optional[str]
11+
bump_message: Optional[str]
12+
changelog_file: str
13+
changelog_incremental: bool
14+
changelog_start_rev: Optional[str]
15+
update_changelog_on_bump: bool
16+
use_shortcuts: bool
17+
318

419
name: str = "cz_conventional_commits"
520
config_files: List[str] = [
@@ -11,7 +26,7 @@
1126
"cz.yaml",
1227
]
1328

14-
DEFAULT_SETTINGS: Dict[str, Any] = {
29+
DEFAULT_SETTINGS: Settings = {
1530
"name": "cz_conventional_commits",
1631
"version": None,
1732
"version_files": [],

commitizen/git.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ def from_line(cls, line: str, inner_delimiter: str) -> "GitTag":
5454
return cls(name=name, rev=obj, date=date)
5555

5656

57-
def tag(tag: str, annotated: bool = False):
57+
def tag(tag: str, annotated: bool = False) -> cmd.Command:
5858
c = cmd.run(f"git tag -a {tag} -m {tag}" if annotated else f"git tag {tag}")
5959
return c
6060

6161

62-
def commit(message: str, args: str = ""):
62+
def commit(message: str, args: str = "") -> cmd.Command:
6363
f = NamedTemporaryFile("wb", delete=False)
6464
f.write(message.encode("utf-8"))
6565
f.close()

commitizen/out.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
from termcolor import colored
44

55

6-
def write(value: str, *args):
6+
def write(value: str, *args) -> None:
77
"""Intended to be used when value is multiline."""
88
print(value, *args)
99

1010

11-
def line(value: str, *args, **kwargs):
11+
def line(value: str, *args, **kwargs) -> None:
1212
"""Wrapper in case I want to do something different later."""
1313
print(value, *args, **kwargs)
1414

1515

16-
def error(value: str):
16+
def error(value: str) -> None:
1717
message = colored(value, "red")
1818
line(message, file=sys.stderr)
1919

2020

21-
def success(value: str):
21+
def success(value: str) -> None:
2222
message = colored(value, "green")
2323
line(message)
2424

2525

26-
def info(value: str):
26+
def info(value: str) -> None:
2727
message = colored(value, "blue")
2828
line(message)
2929

0 commit comments

Comments
 (0)