Skip to content

Commit 9e5574c

Browse files
committed
Add final types to submodule.py
1 parent 2fc8a46 commit 9e5574c

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

git/objects/submodule/base.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
if TYPE_CHECKING:
5858
from git.index import IndexFile
5959
from git.repo import Repo
60+
from git.refs import Head
6061

6162

6263
# -----------------------------------------------------------------------------
@@ -265,7 +266,7 @@ def _module_abspath(cls, parent_repo: 'Repo', path: PathLike, name: str) -> Path
265266
# end
266267

267268
@classmethod
268-
def _clone_repo(cls, repo, url, path, name, **kwargs):
269+
def _clone_repo(cls, repo: 'Repo', url: str, path: PathLike, name: str, **kwargs: Any) -> 'Repo':
269270
""":return: Repo instance of newly cloned repository
270271
:param repo: our parent repository
271272
:param url: url to clone from
@@ -279,7 +280,7 @@ def _clone_repo(cls, repo, url, path, name, **kwargs):
279280
module_abspath_dir = osp.dirname(module_abspath)
280281
if not osp.isdir(module_abspath_dir):
281282
os.makedirs(module_abspath_dir)
282-
module_checkout_path = osp.join(repo.working_tree_dir, path)
283+
module_checkout_path = osp.join(str(repo.working_tree_dir), path)
283284
# end
284285

285286
clone = git.Repo.clone_from(url, module_checkout_path, **kwargs)
@@ -484,7 +485,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
484485
def update(self, recursive: bool = False, init: bool = True, to_latest_revision: bool = False,
485486
progress: Union['UpdateProgress', None] = None, dry_run: bool = False,
486487
force: bool = False, keep_going: bool = False, env: Union[Mapping[str, str], None] = None,
487-
clone_multi_options: Union[Sequence[TBD], None] = None):
488+
clone_multi_options: Union[Sequence[TBD], None] = None) -> 'Submodule':
488489
"""Update the repository of this submodule to point to the checkout
489490
we point at with the binsha of this instance.
490491
@@ -712,7 +713,7 @@ def update(self, recursive: bool = False, init: bool = True, to_latest_revision:
712713
return self
713714

714715
@unbare_repo
715-
def move(self, module_path, configuration=True, module=True):
716+
def move(self, module_path: PathLike, configuration: bool = True, module: bool = True) -> 'Submodule':
716717
"""Move the submodule to a another module path. This involves physically moving
717718
the repository at our current path, changing the configuration, as well as
718719
adjusting our index entry accordingly.
@@ -742,7 +743,7 @@ def move(self, module_path, configuration=True, module=True):
742743
return self
743744
# END handle no change
744745

745-
module_checkout_abspath = join_path_native(self.repo.working_tree_dir, module_checkout_path)
746+
module_checkout_abspath = join_path_native(str(self.repo.working_tree_dir), module_checkout_path)
746747
if osp.isfile(module_checkout_abspath):
747748
raise ValueError("Cannot move repository onto a file: %s" % module_checkout_abspath)
748749
# END handle target files
@@ -1160,7 +1161,7 @@ def exists(self) -> bool:
11601161
# END handle object state consistency
11611162

11621163
@property
1163-
def branch(self):
1164+
def branch(self) -> 'Head':
11641165
""":return: The branch instance that we are to checkout
11651166
:raise InvalidGitRepositoryError: if our module is not yet checked out"""
11661167
return mkhead(self.module(), self._branch_path)

git/objects/util.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,20 @@ def __init__(self, secs_west_of_utc: float, name: Union[None, str] = None) -> No
144144
def __reduce__(self) -> Tuple[Type['tzoffset'], Tuple[float, str]]:
145145
return tzoffset, (-self._offset.total_seconds(), self._name)
146146

147-
def utcoffset(self, dt) -> timedelta:
147+
def utcoffset(self, dt: Union[datetime, None]) -> timedelta:
148148
return self._offset
149149

150-
def tzname(self, dt) -> str:
150+
def tzname(self, dt: Union[datetime, None]) -> str:
151151
return self._name
152152

153-
def dst(self, dt) -> timedelta:
153+
def dst(self, dt: Union[datetime, None]) -> timedelta:
154154
return ZERO
155155

156156

157157
utc = tzoffset(0, 'UTC')
158158

159159

160-
def from_timestamp(timestamp, tz_offset: float) -> datetime:
160+
def from_timestamp(timestamp: float, tz_offset: float) -> datetime:
161161
"""Converts a timestamp + tz_offset into an aware datetime instance."""
162162
utc_dt = datetime.fromtimestamp(timestamp, utc)
163163
try:
@@ -305,7 +305,7 @@ class Traversable(Protocol):
305305

306306
@classmethod
307307
@abstractmethod
308-
def _get_intermediate_items(cls, item) -> Sequence['Traversable']:
308+
def _get_intermediate_items(cls, item: Any) -> Sequence['Traversable']:
309309
"""
310310
Returns:
311311
Tuple of items connected to the given item.
@@ -327,7 +327,7 @@ def list_traverse(self, *args: Any, **kwargs: Any) -> Any:
327327
stacklevel=2)
328328
return self._list_traverse(*args, **kwargs)
329329

330-
def _list_traverse(self, as_edge=False, *args: Any, **kwargs: Any
330+
def _list_traverse(self, as_edge: bool = False, *args: Any, **kwargs: Any
331331
) -> IterableList[Union['Commit', 'Submodule', 'Tree', 'Blob']]:
332332
"""
333333
:return: IterableList with the results of the traversal as produced by

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ filterwarnings = 'ignore::DeprecationWarning'
1919
# filterwarnings ignore::WarningType # ignores those warnings
2020

2121
[tool.mypy]
22-
# disallow_untyped_defs = true
22+
disallow_untyped_defs = true
2323
no_implicit_optional = true
2424
warn_redundant_casts = true
2525
# warn_unused_ignores = True

0 commit comments

Comments
 (0)