Skip to content

Commit b99a45b

Browse files
committed
Linting: Fix type errors in git module
* always explicitly cast path strings into Path object so function calls are always valid
1 parent b0f7ceb commit b99a45b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/gardenlinux/git/repository.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*- coding: utf-8 -*-
22

3-
import sys
43
from os import PathLike
54
from pathlib import Path
5+
from typing import Union
66

77
from pygit2 import Oid
88
from pygit2 import Repository as _Repository
@@ -25,7 +25,9 @@ class Repository(_Repository):
2525
Apache License, Version 2.0
2626
"""
2727

28-
def __init__(self, git_directory=".", logger=None, **kwargs):
28+
def __init__(
29+
self, git_directory: Union[str, PathLike[str]] = ".", logger=None, **kwargs
30+
):
2931
"""
3032
Constructor __init__(Repository)
3133
@@ -38,8 +40,7 @@ def __init__(self, git_directory=".", logger=None, **kwargs):
3840
if logger is None or not logger.hasHandlers():
3941
logger = LoggerSetup.get_logger("gardenlinux.git")
4042

41-
if not isinstance(git_directory, PathLike):
42-
git_directory = Path(git_directory)
43+
git_directory = Path(git_directory)
4344

4445
if not git_directory.exists():
4546
raise RuntimeError(f"Git directory given is invalid: {git_directory}")
@@ -107,11 +108,11 @@ def root_repo(self):
107108

108109
@staticmethod
109110
def checkout_repo(
110-
git_directory,
111+
git_directory: Union[str, PathLike[str]],
111112
repo_url=GL_REPOSITORY_URL,
112-
branch="main",
113-
commit=None,
114-
pathspecs=None,
113+
branch: str = "main",
114+
commit: str | None = None,
115+
pathspecs: list[str] | None = None,
115116
logger=None,
116117
**kwargs,
117118
):
@@ -122,8 +123,7 @@ def checkout_repo(
122123
:since: 0.10.0
123124
"""
124125

125-
if not isinstance(git_directory, PathLike):
126-
git_directory = Path(git_directory)
126+
git_directory = Path(git_directory)
127127

128128
if not git_directory.is_dir() or git_directory.match("/*"):
129129
raise RuntimeError(

0 commit comments

Comments
 (0)