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

Shorten Iterable docstrings and put IterableObj first#1785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Byron merged 1 commit intogitpython-developers:mainfromEliahKagan:iteritems-next
Dec 23, 2023
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 46 additions & 53 deletionsgit/util.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1182,54 +1182,37 @@ def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None:
list.__delitem__(self,delindex)


classIterableClassWatcher(type):
"""Metaclass that issues :class:`DeprecationWarning` when :class:`git.util.Iterable`
is subclassed."""

def__init__(cls,name:str,bases:Tuple,clsdict:Dict)->None:
forbaseinbases:
iftype(base)isIterableClassWatcher:
warnings.warn(
f"GitPython Iterable subclassed by{name}. "
"Iterable is deprecated due to naming clash since v3.1.18"
" and will be removed in 3.1.20, "
"Use IterableObj instead\n",
DeprecationWarning,
stacklevel=2,
)


classIterable(metaclass=IterableClassWatcher):
"""Deprecated, use :class:`IterableObj` instead.
Defines an interface for iterable items, so there is a uniform way to retrieve
@runtime_checkable
classIterableObj(Protocol):
"""Defines an interface for iterable items, so there is a uniform way to retrieve
and iterate items within the git repository.
Subclasses = [Submodule, Commit, Reference, PushInfo, FetchInfo, Remote]
"""

__slots__= ()

_id_attribute_="attribute that most suitably identifies your instance"
_id_attribute_:str

@classmethod
defiter_items(cls,repo:"Repo",*args:Any,**kwargs:Any)->Any:
# return typed to be compatible with subtypes e.g. Remote
"""Deprecated, use :class:`IterableObj` instead.
Find (all) items of this type.
@abstractmethod
defiter_items(cls,repo:"Repo",*args:Any,**kwargs:Any)->Iterator[T_IterableObj]:
# Return-typed to be compatible with subtypes e.g. Remote.
"""Find (all) items of this type.
Subclasses can specify ``args`` and ``kwargs`` differently, and may use them for
filtering. However, when the method is called with no additional positional or
keyword arguments, subclasses are obliged to to yield all items.
For more information about the arguments, see list_items.
:return: Iterator yielding Items
"""
raiseNotImplementedError("To be implemented by Subclass")

@classmethod
deflist_items(cls,repo:"Repo",*args:Any,**kwargs:Any)->Any:
"""Deprecated, use :class:`IterableObj` instead.
Find (all) items of this type and collect them into a list.
deflist_items(cls,repo:"Repo",*args:Any,**kwargs:Any)->IterableList[T_IterableObj]:
"""Find (all) items of this type and collect them into a list.
For more information about the arguments, see :meth:`list_items`.
Expand All@@ -1239,52 +1222,62 @@ def list_items(cls, repo: "Repo", *args: Any, **kwargs: Any) -> Any:
:return: list(Item,...) list of item instances
"""
out_list:Any=IterableList(cls._id_attribute_)
out_list:IterableList=IterableList(cls._id_attribute_)
out_list.extend(cls.iter_items(repo,*args,**kwargs))
returnout_list


@runtime_checkable
classIterableObj(Protocol):
"""Defines an interface for iterable items, so there is a uniform way to retrieve
and iterate items within the git repository.
classIterableClassWatcher(type):
"""Metaclass that issues :class:`DeprecationWarning` when :class:`git.util.Iterable`
is subclassed."""

Subclasses = [Submodule, Commit, Reference, PushInfo, FetchInfo, Remote]
def__init__(cls,name:str,bases:Tuple,clsdict:Dict)->None:
forbaseinbases:
iftype(base)isIterableClassWatcher:
warnings.warn(
f"GitPython Iterable subclassed by{name}. "
"Iterable is deprecated due to naming clash since v3.1.18"
" and will be removed in 3.1.20, "
"Use IterableObj instead\n",
DeprecationWarning,
stacklevel=2,
)


classIterable(metaclass=IterableClassWatcher):
"""Deprecated, use :class:`IterableObj` instead.
Defines an interface for iterable items, so there is a uniform way to retrieve
and iterate items within the git repository.
"""

__slots__= ()

_id_attribute_:str
_id_attribute_="attribute that most suitably identifies your instance"

@classmethod
@abstractmethod
defiter_items(cls,repo:"Repo",*args:Any,**kwargs:Any)->Iterator[T_IterableObj]:
# Return-typed to be compatible with subtypes e.g. Remote.
"""Find (all) items of this type.
defiter_items(cls,repo:"Repo",*args:Any,**kwargs:Any)->Any:
"""Deprecated, use :class:`IterableObj` instead.
Subclasses can specify ``args`` and ``kwargs`` differently, and may use them for
filtering. However, when the method is called with no additional positional or
keyword arguments, subclasses are obliged to to yield all items.
Find (all) items of this type.
For more information about the arguments, see list_items.
See :meth:`IterableObj.list_items` for details on usage.
:return: Iterator yielding Items
"""
raiseNotImplementedError("To be implemented by Subclass")

@classmethod
deflist_items(cls,repo:"Repo",*args:Any,**kwargs:Any)->IterableList[T_IterableObj]:
"""Find (all) items of this type and collect them into a list.
deflist_items(cls,repo:"Repo",*args:Any,**kwargs:Any)->Any:
"""Deprecated, use :class:`IterableObj` instead.
For more information about the arguments, see :meth:`list_items`.
Find (all) items of this type and collect them into a list.
:note: Favor the :meth:`iter_items` method as it will avoid eagerly collecting
all items. When there are many items, that can slow performance and increase
memory usage.
See :meth:`IterableObj.list_items` for details on usage.
:return: list(Item,...) list of item instances
"""
out_list:IterableList=IterableList(cls._id_attribute_)
out_list:Any=IterableList(cls._id_attribute_)
out_list.extend(cls.iter_items(repo,*args,**kwargs))
returnout_list

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp