Skip to content

Commit 3710e24

Browse files
committed
Rmv circular import, create Has_id_attribute Protocol instead
1 parent 030b1fd commit 3710e24

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

‎git/objects/tree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def traverse(self, # type: ignore # overrides super()
323323
super(Tree, self).traverse(predicate, prune, depth, # type: ignore
324324
branch_first, visit_once, ignore_self))
325325

326-
def list_traverse(self, *args: Any, **kwargs: Any) -> IterableList[Union['Tree', 'Submodule', 'Blob']]:
326+
def list_traverse(self, *args: Any, **kwargs: Any) -> IterableList[IndexObjUnion]:
327327
return super(Tree, self).list_traverse(* args, **kwargs)
328328

329329
# List protocol

‎git/objects/util.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
import calendar
2020
from datetime import datetime, timedelta, tzinfo
2121

22-
from git.objects.base import IndexObject # just for an isinstance check
23-
2422
# typing ------------------------------------------------------------
2523
from typing import (Any, Callable, Deque, Iterator, NamedTuple, overload, Sequence,
2624
TYPE_CHECKING, Tuple, Type, TypeVar, Union, cast)
2725

28-
from git.types import Literal
26+
from git.types import Has_id_attribute, Literal
2927

3028
if TYPE_CHECKING:
3129
from io import BytesIO, StringIO
@@ -319,7 +317,7 @@ def list_traverse(self, *args: Any, **kwargs: Any) -> IterableList[Union['Commit
319317
"""
320318
# Commit and Submodule have id.__attribute__ as IterableObj
321319
# Tree has id.__attribute__ inherited from IndexObject
322-
if isinstance(self, (TraversableIterableObj, IndexObject)):
320+
if isinstance(self, (TraversableIterableObj, Has_id_attribute)):
323321
id = self._id_attribute_
324322
else:
325323
id = "" # shouldn't reach here, unless Traversable subclass created with no _id_attribute_

‎git/types.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from git.repo import Repo
1212

1313
if sys.version_info[:2] >= (3, 8):
14-
from typing import Final, Literal, SupportsIndex, TypedDict, Protocol # noqa: F401
14+
from typing import Final, Literal, SupportsIndex, TypedDict, Protocol, runtime_checkable # noqa: F401
1515
else:
16-
from typing_extensions import Final, Literal, SupportsIndex, TypedDict, Protocol # noqa: F401
16+
from typing_extensions import Final, Literal, SupportsIndex, TypedDict, Protocol, runtime_checkable # noqa: F401
1717

1818
if sys.version_info[:2] >= (3, 10):
1919
from typing import TypeGuard # noqa: F401
@@ -73,5 +73,11 @@ class HSH_TD(TypedDict):
7373
files: Dict[PathLike, Files_TD]
7474

7575

76+
@runtime_checkable
7677
class Has_Repo(Protocol):
7778
repo: 'Repo'
79+
80+
81+
@runtime_checkable
82+
class Has_id_attribute(Protocol):
83+
_id_attribute_: str

0 commit comments

Comments
 (0)