1818import time
1919from unittest import SkipTest
2020from urllib .parse import urlsplit , urlunsplit
21+ import warnings
2122
2223# typing ---------------------------------------------------------
2324
@@ -1013,15 +1014,52 @@ def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> Any:
10131014 list .__delitem__ (self , delindex )
10141015
10151016
1017+ class IterableClassWatcher (type ):
1018+ def __init__ (cls , name , bases , clsdict ):
1019+ for base in bases :
1020+ if type (base ) == cls :
1021+ warnings .warn ("GitPython Iterable is deprecated due to naming clash. Use IterableObj instead" ,
1022+ DeprecationWarning )
1023+ super (IterableClassWatcher , cls ).__init__ (name , bases , clsdict )
1024+
1025+
10161026class Iterable (object ):
10171027
10181028 """Defines an interface for iterable items which is to assure a uniform
10191029 way to retrieve and iterate items within the git repository"""
10201030 __slots__ = ()
10211031 _id_attribute_ = "attribute that most suitably identifies your instance"
1032+ __metaclass__ = IterableClassWatcher
10221033
10231034 @classmethod
1024- def list_items (cls , repo : 'Repo' , * args : Any , ** kwargs : Any ) -> IterableList ['IterableObj' ]:
1035+ def list_items (cls , repo , * args , ** kwargs ):
1036+ """
1037+ Find all items of this type - subclasses can specify args and kwargs differently.
1038+ If no args are given, subclasses are obliged to return all items if no additional
1039+ arguments arg given.
1040+
1041+ :note: Favor the iter_items method as it will
1042+ :return:list(Item,...) list of item instances"""
1043+ out_list = IterableList (cls ._id_attribute_ )
1044+ out_list .extend (cls .iter_items (repo , * args , ** kwargs ))
1045+ return out_list
1046+
1047+ @classmethod
1048+ def iter_items (cls , repo : 'Repo' , * args : Any , ** kwargs : Any ):
1049+ # return typed to be compatible with subtypes e.g. Remote
1050+ """For more information about the arguments, see list_items
1051+ :return: iterator yielding Items"""
1052+ raise NotImplementedError ("To be implemented by Subclass" )
1053+
1054+
1055+ class IterableObj ():
1056+ """Defines an interface for iterable items which is to assure a uniform
1057+ way to retrieve and iterate items within the git repository"""
1058+ __slots__ = ()
1059+ _id_attribute_ = "attribute that most suitably identifies your instance"
1060+
1061+ @classmethod
1062+ def list_items (cls , repo : 'Repo' , * args : Any , ** kwargs : Any ) -> IterableList [T ]:
10251063 """
10261064 Find all items of this type - subclasses can specify args and kwargs differently.
10271065 If no args are given, subclasses are obliged to return all items if no additional
@@ -1044,10 +1082,6 @@ def iter_items(cls, repo: 'Repo', *args: Any, **kwargs: Any) -> Iterator:
10441082#} END classes
10451083
10461084
1047- class IterableObj (Iterable ):
1048- pass
1049-
1050-
10511085class NullHandler (logging .Handler ):
10521086 def emit (self , record : object ) -> None :
10531087 pass
0 commit comments