@@ -1183,7 +1183,8 @@ def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None:
1183
1183
1184
1184
1185
1185
class IterableClassWatcher (type ):
1186
- """Metaclass that watches."""
1186
+ """Metaclass that issues :class:`DeprecationWarning` when :class:`git.util.Iterable`
1187
+ is subclassed."""
1187
1188
1188
1189
def __init__ (cls , name : str , bases : Tuple , clsdict : Dict ) -> None :
1189
1190
for base in bases :
@@ -1199,39 +1200,49 @@ def __init__(cls, name: str, bases: Tuple, clsdict: Dict) -> None:
1199
1200
1200
1201
1201
1202
class Iterable (metaclass = IterableClassWatcher ):
1202
- """Defines an interface for iterable items, so there is a uniform way to retrieve
1203
- and iterate items within the git repository."""
1203
+ """Deprecated, use :class:`IterableObj` instead.
1204
+
1205
+ Defines an interface for iterable items, so there is a uniform way to retrieve
1206
+ and iterate items within the git repository.
1207
+ """
1204
1208
1205
1209
__slots__ = ()
1206
1210
1207
1211
_id_attribute_ = "attribute that most suitably identifies your instance"
1208
1212
1209
1213
@classmethod
1210
- def list_items (cls , repo : "Repo" , * args : Any , ** kwargs : Any ) -> Any :
1214
+ def iter_items (cls , repo : "Repo" , * args : Any , ** kwargs : Any ) -> Any :
1215
+ # return typed to be compatible with subtypes e.g. Remote
1216
+ """Deprecated, use :class:`IterableObj` instead.
1217
+
1218
+ Find (all) items of this type.
1219
+
1220
+ Subclasses can specify ``args`` and ``kwargs`` differently, and may use them for
1221
+ filtering. However, when the method is called with no additional positional or
1222
+ keyword arguments, subclasses are obliged to to yield all items.
1223
+
1224
+ :return: Iterator yielding Items
1211
1225
"""
1212
- Deprecated, use IterableObj instead.
1226
+ raise NotImplementedError ("To be implemented by Subclass" )
1227
+
1228
+ @classmethod
1229
+ def list_items (cls , repo : "Repo" , * args : Any , ** kwargs : Any ) -> Any :
1230
+ """Deprecated, use :class:`IterableObj` instead.
1231
+
1232
+ Find (all) items of this type and collect them into a list.
1213
1233
1214
- Find all items of this type - subclasses can specify args and kwargs differently.
1215
- If no args are given, subclasses are obliged to return all items if no additional
1216
- arguments arg given.
1234
+ For more information about the arguments, see :meth:`list_items`.
1217
1235
1218
- :note: Favor the iter_items method as it will
1236
+ :note: Favor the :meth:`iter_items` method as it will avoid eagerly collecting
1237
+ all items. When there are many items, that can slow performance and increase
1238
+ memory usage.
1219
1239
1220
1240
:return: list(Item,...) list of item instances
1221
1241
"""
1222
1242
out_list : Any = IterableList (cls ._id_attribute_ )
1223
1243
out_list .extend (cls .iter_items (repo , * args , ** kwargs ))
1224
1244
return out_list
1225
1245
1226
- @classmethod
1227
- def iter_items (cls , repo : "Repo" , * args : Any , ** kwargs : Any ) -> Any :
1228
- # return typed to be compatible with subtypes e.g. Remote
1229
- """For more information about the arguments, see list_items.
1230
-
1231
- :return: Iterator yielding Items
1232
- """
1233
- raise NotImplementedError ("To be implemented by Subclass" )
1234
-
1235
1246
1236
1247
@runtime_checkable
1237
1248
class IterableObj (Protocol ):
@@ -1246,30 +1257,37 @@ class IterableObj(Protocol):
1246
1257
_id_attribute_ : str
1247
1258
1248
1259
@classmethod
1249
- def list_items (cls , repo : "Repo" , * args : Any , ** kwargs : Any ) -> IterableList [T_IterableObj ]:
1260
+ @abstractmethod
1261
+ def iter_items (cls , repo : "Repo" , * args : Any , ** kwargs : Any ) -> Iterator [T_IterableObj ]:
1262
+ # Return-typed to be compatible with subtypes e.g. Remote.
1263
+ """Find (all) items of this type.
1264
+
1265
+ Subclasses can specify ``args`` and ``kwargs`` differently, and may use them for
1266
+ filtering. However, when the method is called with no additional positional or
1267
+ keyword arguments, subclasses are obliged to to yield all items.
1268
+
1269
+ For more information about the arguments, see list_items.
1270
+
1271
+ :return: Iterator yielding Items
1250
1272
"""
1251
- Find all items of this type - subclasses can specify args and kwargs differently.
1252
- If no args are given, subclasses are obliged to return all items if no additional
1253
- arguments arg given.
1273
+ raise NotImplementedError ("To be implemented by Subclass" )
1274
+
1275
+ @classmethod
1276
+ def list_items (cls , repo : "Repo" , * args : Any , ** kwargs : Any ) -> IterableList [T_IterableObj ]:
1277
+ """Find (all) items of this type and collect them into a list.
1278
+
1279
+ For more information about the arguments, see :meth:`list_items`.
1254
1280
1255
- :note: Favor the iter_items method as it will
1281
+ :note: Favor the :meth:`iter_items` method as it will avoid eagerly collecting
1282
+ all items. When there are many items, that can slow performance and increase
1283
+ memory usage.
1256
1284
1257
1285
:return: list(Item,...) list of item instances
1258
1286
"""
1259
1287
out_list : IterableList = IterableList (cls ._id_attribute_ )
1260
1288
out_list .extend (cls .iter_items (repo , * args , ** kwargs ))
1261
1289
return out_list
1262
1290
1263
- @classmethod
1264
- @abstractmethod
1265
- def iter_items (cls , repo : "Repo" , * args : Any , ** kwargs : Any ) -> Iterator [T_IterableObj ]: # Iterator[T_IterableObj]:
1266
- # Return-typed to be compatible with subtypes e.g. Remote.
1267
- """For more information about the arguments, see list_items.
1268
-
1269
- :return: Iterator yielding Items
1270
- """
1271
- raise NotImplementedError ("To be implemented by Subclass" )
1272
-
1273
1291
1274
1292
# } END classes
1275
1293
0 commit comments