Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit619304c

Browse files
authored
Merge pull request#1785 from EliahKagan/iteritems-next
Shorten Iterable docstrings and put IterableObj first
2 parentscf94a26 +2b768c7 commit619304c

File tree

1 file changed

+46
-53
lines changed

1 file changed

+46
-53
lines changed

‎git/util.py

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,54 +1182,37 @@ def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None:
11821182
list.__delitem__(self,delindex)
11831183

11841184

1185-
classIterableClassWatcher(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-
forbaseinbases:
1191-
iftype(base)isIterableClassWatcher:
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-
classIterable(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+
classIterableObj(Protocol):
1187+
"""Defines an interface for iterable items, so there is a uniform way to retrieve
12061188
and iterate items within the git repository.
1189+
1190+
Subclasses = [Submodule, Commit, Reference, PushInfo, FetchInfo, Remote]
12071191
"""
12081192

12091193
__slots__= ()
12101194

1211-
_id_attribute_="attribute that most suitably identifies your instance"
1195+
_id_attribute_:str
12121196

12131197
@classmethod
1214-
defiter_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+
defiter_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.
12191202
12201203
Subclasses can specify ``args`` and ``kwargs`` differently, and may use them for
12211204
filtering. However, when the method is called with no additional positional or
12221205
keyword arguments, subclasses are obliged to to yield all items.
12231206
1207+
For more information about the arguments, see list_items.
1208+
12241209
:return: Iterator yielding Items
12251210
"""
12261211
raiseNotImplementedError("To be implemented by Subclass")
12271212

12281213
@classmethod
1229-
deflist_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+
deflist_items(cls,repo:"Repo",*args:Any,**kwargs:Any)->IterableList[T_IterableObj]:
1215+
"""Find (all) items of this type and collect them into a list.
12331216
12341217
For more information about the arguments, see :meth:`list_items`.
12351218
@@ -1239,52 +1222,62 @@ def list_items(cls, repo: "Repo", *args: Any, **kwargs: Any) -> Any:
12391222
12401223
:return: list(Item,...) list of item instances
12411224
"""
1242-
out_list:Any=IterableList(cls._id_attribute_)
1225+
out_list:IterableList=IterableList(cls._id_attribute_)
12431226
out_list.extend(cls.iter_items(repo,*args,**kwargs))
12441227
returnout_list
12451228

12461229

1247-
@runtime_checkable
1248-
classIterableObj(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+
classIterableClassWatcher(type):
1231+
"""Metaclass that issues :class:`DeprecationWarning` when :class:`git.util.Iterable`
1232+
is subclassed."""
12511233

1252-
Subclasses = [Submodule, Commit, Reference, PushInfo, FetchInfo, Remote]
1234+
def__init__(cls,name:str,bases:Tuple,clsdict:Dict)->None:
1235+
forbaseinbases:
1236+
iftype(base)isIterableClassWatcher:
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+
classIterable(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.
12531252
"""
12541253

12551254
__slots__= ()
12561255

1257-
_id_attribute_:str
1256+
_id_attribute_="attribute that most suitably identifies your instance"
12581257

12591258
@classmethod
1260-
@abstractmethod
1261-
defiter_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+
defiter_items(cls,repo:"Repo",*args:Any,**kwargs:Any)->Any:
1260+
"""Deprecated, use :class:`IterableObj` instead.
12641261
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.
12681263
1269-
For more information about the arguments, see list_items.
1264+
See :meth:`IterableObj.list_items` for details on usage.
12701265
12711266
:return: Iterator yielding Items
12721267
"""
12731268
raiseNotImplementedError("To be implemented by Subclass")
12741269

12751270
@classmethod
1276-
deflist_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+
deflist_items(cls,repo:"Repo",*args:Any,**kwargs:Any)->Any:
1272+
"""Deprecated, use :class:`IterableObj` instead.
12781273
1279-
For more information about the arguments, see :meth:`list_items`.
1274+
Find (all) items of this type and collect them into a list.
12801275
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.
12841277
12851278
:return: list(Item,...) list of item instances
12861279
"""
1287-
out_list:IterableList=IterableList(cls._id_attribute_)
1280+
out_list:Any=IterableList(cls._id_attribute_)
12881281
out_list.extend(cls.iter_items(repo,*args,**kwargs))
12891282
returnout_list
12901283

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp