Skip to content

Commit 3f2832b

Browse files
committed
💄 style(typing): add explicit type annotations
1 parent fba0eff commit 3f2832b

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

tgit/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def set_global_settings(key: str, value: Any) -> None: # noqa: ANN401
4444
global_settings_path = Path.home() / ".tgit" / "settings.json"
4545
global_settings_path.parent.mkdir(parents=True, exist_ok=True)
4646

47-
file_settings = json.loads(global_settings_path.read_text()) or {} if global_settings_path.exists() else {}
47+
file_settings = json.loads(global_settings_path.read_text()) or {} if global_settings_path.exists() else {} # type: ignore
4848

4949
file_settings[key] = value
5050
global_settings_path.write_text(json.dumps(file_settings, indent=2))
@@ -68,7 +68,7 @@ def _merge_settings(base: dict[str, Any], override: dict[str, Any]) -> dict[str,
6868
result = base.copy()
6969
for key, value in override.items():
7070
if key in result and isinstance(result[key], dict) and isinstance(value, dict):
71-
result[key] = _merge_settings(result[key], value)
71+
result[key] = _merge_settings(result[key], value) # type: ignore
7272
else:
7373
result[key] = value
7474
return result

tgit/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CommitType:
2323
@dataclass
2424
class CommitSettings:
2525
emoji: bool = False
26-
types: list[CommitType] = field(default_factory=list)
26+
types: list[CommitType] = field(default_factory=list[CommitType])
2727

2828

2929
@dataclass

tgit/version.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def get_version_from_cargo_toml(directory_path: Path) -> Version | None:
232232
return None
233233

234234
# 5. Safely access the version string
235-
version_str = package_data.get("version")
235+
version_str = package_data.get("version") # type: ignore
236236
if not isinstance(version_str, str) or not version_str: # Check if it's a non-empty string
237237
console.print(f"Missing, empty, or invalid 'version' string in [package] table of {cargo_toml_path}")
238238
return None
@@ -458,7 +458,7 @@ def get_pre_release_identifier() -> str | None:
458458
return questionary.text(
459459
"Enter the pre-release identifier",
460460
default="alpha",
461-
validate=lambda x: bool((match := re.match(r"[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*", x)) and match.group() == x),
461+
validate=lambda x: bool((match := re.match(r"[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*", x)) and match.group() == x), # type: ignore
462462
).ask()
463463

464464

@@ -557,10 +557,10 @@ def update_file(filename: str, search_pattern: str | None, replace_text: str, ve
557557
def show_file_diff(old_content: str, new_content: str, filename: str) -> None:
558558
old_lines = old_content.splitlines()
559559
new_lines = new_content.splitlines()
560-
diff = list(Differ().compare(old_lines, new_lines))
560+
diff = list[str](Differ().compare(old_lines, new_lines))
561561
print_lines = extract_context_lines(diff)
562562

563-
diffs = []
563+
diffs: list[str] = []
564564
format_diff_lines(diff, print_lines, diffs)
565565
if diffs:
566566
console.print()
@@ -572,7 +572,7 @@ def show_file_diff(old_content: str, new_content: str, filename: str) -> None:
572572

573573

574574
def extract_context_lines(diff: list[str]) -> dict[int, str]:
575-
print_lines = {}
575+
print_lines: dict[int, str] = {}
576576
for i, line in enumerate(diff):
577577
if line.startswith(("+", "-")):
578578
for j in range(i - 3, i + 3):
@@ -600,7 +600,7 @@ def format_diff_lines(diff: list[str], print_lines: dict[int, str], diffs: list[
600600
def execute_git_commands(args: VersionArgs, next_version: Version, verbose: int) -> None:
601601
git_tag = f"v{next_version}"
602602

603-
commands = []
603+
commands: list[str] = []
604604
if args.no_commit:
605605
if verbose > 0:
606606
console.print("Skipping commit")
@@ -641,7 +641,7 @@ def version( # noqa: PLR0913
641641
custom: bool = typer.Option(False, "--custom", help="custom version to bump to"),
642642
) -> None:
643643
# Check for mutually exclusive options
644-
exclusive_options = [patch, minor, major, prepatch, preminor, premajor, custom]
644+
exclusive_options: list[bool | str] = [patch, minor, major, prepatch, preminor, premajor, custom]
645645
if sum(bool(opt) for opt in exclusive_options) > 1:
646646
typer.echo("Error: Only one version bump option can be specified at a time.")
647647
raise typer.Exit(1)

0 commit comments

Comments
 (0)