| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f5e1b10 commit 2b768c7
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1182,54 +1182,37 @@ def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None: | |||
| 1182 | 1182 | list.__delitem__(self, delindex) | |
| 1183 | 1183 | ||
| 1184 | 1184 | ||
| 1185 | - class IterableClassWatcher(type): | ||
| 1186 | - """Metaclass that issues :class:`DeprecationWarning` when :class:`git.util.Iterable` | ||
| 1187 | - is subclassed.""" | ||
| 1188 | - | ||
| 1189 | - def __init__(cls, name: str, bases: Tuple, clsdict: Dict) -> None: | ||
| 1190 | - for base in bases: | ||
| 1191 | - if type(base) is IterableClassWatcher: | ||
| 1192 | - warnings.warn( | ||
| 1193 | - f"GitPython Iterable subclassed by {name}. " | ||
| 1194 | - "Iterable is deprecated due to naming clash since v3.1.18" | ||
| 1195 | - " and will be removed in 3.1.20, " | ||
| 1196 | - "Use IterableObj instead \n", | ||
| 1197 | - DeprecationWarning, | ||
| 1198 | - stacklevel=2, | ||
| 1199 | - ) | ||
| 1200 | - | ||
| 1201 | - | ||
| 1202 | - class Iterable(metaclass=IterableClassWatcher): | ||
| 1203 | - """Deprecated, use :class:`IterableObj` instead. | ||
| 1204 | - | ||
| 1205 | - Defines an interface for iterable items, so there is a uniform way to retrieve | ||
| 1185 | + @runtime_checkable | ||
| 1186 | + class IterableObj(Protocol): | ||
| 1187 | + """Defines an interface for iterable items, so there is a uniform way to retrieve | ||
| 1206 | 1188 | and iterate items within the git repository. | |
| 1189 | + | ||
| 1190 | + Subclasses = [Submodule, Commit, Reference, PushInfo, FetchInfo, Remote] | ||
| 1207 | 1191 | """ | |
| 1208 | 1192 | ||
| 1209 | 1193 | __slots__ = () | |
| 1210 | 1194 | ||
| 1211 | - _id_attribute_ = "attribute that most suitably identifies your instance" | ||
| 1195 | + _id_attribute_: str | ||
| 1212 | 1196 | ||
| 1213 | 1197 | @classmethod | |
| 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. | ||
| 1198 | + @abstractmethod | ||
| 1199 | + def iter_items(cls, repo: "Repo", *args: Any, **kwargs: Any) -> Iterator[T_IterableObj]: | ||
| 1200 | + # Return-typed to be compatible with subtypes e.g. Remote. | ||
| 1201 | + """Find (all) items of this type. | ||
| 1219 | 1202 | ||
| 1220 | 1203 | Subclasses can specify ``args`` and ``kwargs`` differently, and may use them for | |
| 1221 | 1204 | filtering. However, when the method is called with no additional positional or | |
| 1222 | 1205 | keyword arguments, subclasses are obliged to to yield all items. | |
| 1223 | 1206 | ||
| 1207 | + For more information about the arguments, see list_items. | ||
| 1208 | + | ||
| 1224 | 1209 | :return: Iterator yielding Items | |
| 1225 | 1210 | """ | |
| 1226 | 1211 | raise NotImplementedError("To be implemented by Subclass") | |
| 1227 | 1212 | ||
| 1228 | 1213 | @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. | ||
| 1214 | + def list_items(cls, repo: "Repo", *args: Any, **kwargs: Any) -> IterableList[T_IterableObj]: | ||
| 1215 | + """Find (all) items of this type and collect them into a list. | ||
| 1233 | 1216 | ||
| 1234 | 1217 | For more information about the arguments, see :meth:`list_items`. | |
| 1235 | 1218 | ||
@@ -1239,52 +1222,62 @@ def list_items(cls, repo: "Repo", *args: Any, **kwargs: Any) -> Any: | |||
| 1239 | 1222 | ||
| 1240 | 1223 | :return: list(Item,...) list of item instances | |
| 1241 | 1224 | """ | |
| 1242 | - out_list: Any = IterableList(cls._id_attribute_) | ||
| 1225 | + out_list: IterableList = IterableList(cls._id_attribute_) | ||
| 1243 | 1226 | out_list.extend(cls.iter_items(repo, *args, **kwargs)) | |
| 1244 | 1227 | return out_list | |
| 1245 | 1228 | ||
| 1246 | 1229 | ||
| 1247 | - @runtime_checkable | ||
| 1248 | - class IterableObj(Protocol): | ||
| 1249 | - """Defines an interface for iterable items, so there is a uniform way to retrieve | ||
| 1250 | - and iterate items within the git repository. | ||
| 1230 | + class IterableClassWatcher(type): | ||
| 1231 | + """Metaclass that issues :class:`DeprecationWarning` when :class:`git.util.Iterable` | ||
| 1232 | + is subclassed.""" | ||
| 1251 | 1233 | ||
| 1252 | - Subclasses = [Submodule, Commit, Reference, PushInfo, FetchInfo, Remote] | ||
| 1234 | + def __init__(cls, name: str, bases: Tuple, clsdict: Dict) -> None: | ||
| 1235 | + for base in bases: | ||
| 1236 | + if type(base) is IterableClassWatcher: | ||
| 1237 | + warnings.warn( | ||
| 1238 | + f"GitPython Iterable subclassed by {name}. " | ||
| 1239 | + "Iterable is deprecated due to naming clash since v3.1.18" | ||
| 1240 | + " and will be removed in 3.1.20, " | ||
| 1241 | + "Use IterableObj instead \n", | ||
| 1242 | + DeprecationWarning, | ||
| 1243 | + stacklevel=2, | ||
| 1244 | + ) | ||
| 1245 | + | ||
| 1246 | + | ||
| 1247 | + class Iterable(metaclass=IterableClassWatcher): | ||
| 1248 | + """Deprecated, use :class:`IterableObj` instead. | ||
| 1249 | + | ||
| 1250 | + Defines an interface for iterable items, so there is a uniform way to retrieve | ||
| 1251 | + and iterate items within the git repository. | ||
| 1253 | 1252 | """ | |
| 1254 | 1253 | ||
| 1255 | 1254 | __slots__ = () | |
| 1256 | 1255 | ||
| 1257 | - _id_attribute_: str | ||
| 1256 | + _id_attribute_ = "attribute that most suitably identifies your instance" | ||
| 1258 | 1257 | ||
| 1259 | 1258 | @classmethod | |
| 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. | ||
| 1259 | + def iter_items(cls, repo: "Repo", *args: Any, **kwargs: Any) -> Any: | ||
| 1260 | + """Deprecated, use :class:`IterableObj` instead. | ||
| 1264 | 1261 | ||
| 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. | ||
| 1262 | + Find (all) items of this type. | ||
| 1268 | 1263 | ||
| 1269 | - For more information about the arguments, see list_items. | ||
| 1264 | + See :meth:`IterableObj.list_items` for details on usage. | ||
| 1270 | 1265 | ||
| 1271 | 1266 | :return: Iterator yielding Items | |
| 1272 | 1267 | """ | |
| 1273 | 1268 | raise NotImplementedError("To be implemented by Subclass") | |
| 1274 | 1269 | ||
| 1275 | 1270 | @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. | ||
| 1271 | + def list_items(cls, repo: "Repo", *args: Any, **kwargs: Any) -> Any: | ||
| 1272 | + """Deprecated, use :class:`IterableObj` instead. | ||
| 1278 | 1273 | ||
| 1279 | - For more information about the arguments, see :meth:`list_items`. | ||
| 1274 | + Find (all) items of this type and collect them into a list. | ||
| 1280 | 1275 | ||
| 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. | ||
| 1276 | + See :meth:`IterableObj.list_items` for details on usage. | ||
| 1284 | 1277 | ||
| 1285 | 1278 | :return: list(Item,...) list of item instances | |
| 1286 | 1279 | """ | |
| 1287 | - out_list: IterableList = IterableList(cls._id_attribute_) | ||
| 1280 | + out_list: Any = IterableList(cls._id_attribute_) | ||
| 1288 | 1281 | out_list.extend(cls.iter_items(repo, *args, **kwargs)) | |
| 1289 | 1282 | return out_list | |
| 1290 | 1283 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments