- Notifications
You must be signed in to change notification settings - Fork673
feat(client): introduceiterator=True
and deprecateas_list=False
inlist()
#2032
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
22 changes: 13 additions & 9 deletionsdocs/api-usage.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -93,13 +93,13 @@ Examples: | ||
.. code-block:: python | ||
# list all the projects | ||
projects = gl.projects.list(iterator=True) | ||
for project in projects: | ||
print(project) | ||
# get the group with id == 2 | ||
group = gl.groups.get(2) | ||
for project in group.projects.list(iterator=True): | ||
print(project) | ||
# create a new user | ||
@@ -109,7 +109,7 @@ Examples: | ||
.. warning:: | ||
Calling ``list()`` without any arguments will by default not return the complete list | ||
of items. Use either the ``all=True`` or ``iterator=True`` parameters to get all the | ||
items when using listing methods. See the :ref:`pagination` section for more | ||
information. | ||
@@ -156,9 +156,9 @@ conflict with python or python-gitlab when using them as kwargs: | ||
.. code-block:: python | ||
gl.user_activities.list(from='2019-01-01',iterator=True) ## invalid | ||
gl.user_activities.list(query_parameters={'from': '2019-01-01'},iterator=True) # OK | ||
Gitlab Objects | ||
============== | ||
@@ -282,13 +282,13 @@ order options. At the time of writing, only ``order_by="id"`` works. | ||
Reference: | ||
https://docs.gitlab.com/ce/api/README.html#keyset-based-pagination | ||
``list()`` methods can also return a generator object, by passingthe argument | ||
``iterator=True``, which will handle thenext calls to the API when required. This | ||
is the recommended way to iteratethrough a large number of items: | ||
.. code-block:: python | ||
items = gl.groups.list(iterator=True) | ||
for item in items: | ||
print(item.attributes) | ||
@@ -310,6 +310,10 @@ The generator exposes extra listing information as received from the server: | ||
For more information see: | ||
https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headers | ||
.. note:: | ||
Prior to python-gitlab 3.6.0 the argument ``as_list`` was used instead of | ||
JohnVillalovos marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
``iterator``. ``as_list=False`` is the equivalent of ``iterator=True``. | ||
Sudo | ||
==== | ||
4 changes: 2 additions & 2 deletionsdocs/gl_objects/search.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletiondocs/gl_objects/users.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
31 changes: 24 additions & 7 deletionsgitlab/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -807,7 +807,9 @@ def http_list( | ||
self, | ||
path: str, | ||
query_data: Optional[Dict[str, Any]] = None, | ||
*, | ||
as_list: Optional[bool] = None, # Deprecated in favor of `iterator` | ||
iterator: Optional[bool] = None, | ||
nejch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
**kwargs: Any, | ||
) -> Union["GitlabList", List[Dict[str, Any]]]: | ||
"""Make a GET request to the Gitlab server for list-oriented queries. | ||
@@ -816,12 +818,13 @@ def http_list( | ||
path: Path or full URL to query ('/projects' or | ||
'http://whatever/v4/api/projects') | ||
query_data: Data to send as query parameters | ||
iterator: Indicate if should return a generator (True) | ||
**kwargs: Extra options to send to the server (e.g. sudo, page, | ||
per_page) | ||
Returns: | ||
A list of the objects returned by the server. If `iterator` is | ||
True and no pagination-related arguments (`page`, `per_page`, | ||
`all`) are defined then a GitlabList object (generator) is returned | ||
instead. This object will make API calls when needed to fetch the | ||
next items from the server. | ||
@@ -832,15 +835,29 @@ def http_list( | ||
""" | ||
query_data = query_data or {} | ||
# Don't allow both `as_list` and `iterator` to be set. | ||
if as_list is not None and iterator is not None: | ||
raise ValueError( | ||
"Only one of `as_list` or `iterator` can be used. " | ||
"Use `iterator` instead of `as_list`. `as_list` is deprecated." | ||
) | ||
if as_list is not None: | ||
iterator = not as_list | ||
utils.warn( | ||
message=( | ||
f"`as_list={as_list}` is deprecated and will be removed in a " | ||
f"future version. Use `iterator={iterator}` instead." | ||
), | ||
category=DeprecationWarning, | ||
) | ||
get_all = kwargs.pop("all", None) | ||
url = self._build_url(path) | ||
page = kwargs.get("page") | ||
ifiterator: | ||
# Generator requested | ||
return GitlabList(self, url, query_data, **kwargs) | ||
@@ -879,7 +896,7 @@ def should_emit_warning() -> bool: | ||
utils.warn( | ||
message=( | ||
f"Calling a `list()` method without specifying `all=True` or " | ||
f"`iterator=True` will return a maximum of {gl_list.per_page} items. " | ||
f"Your query returned {len(items)} of {total_items} items. See " | ||
f"{_PAGINATION_URL} for more details. If this was done intentionally, " | ||
f"then this warning can be supressed by adding the argument " | ||
6 changes: 2 additions & 4 deletionsgitlab/mixins.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionsgitlab/v4/objects/ldap.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8 changes: 2 additions & 6 deletionsgitlab/v4/objects/merge_requests.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
16 changes: 4 additions & 12 deletionsgitlab/v4/objects/milestones.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionsgitlab/v4/objects/repositories.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletiongitlab/v4/objects/runners.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionsgitlab/v4/objects/users.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
17 changes: 14 additions & 3 deletionstests/functional/api/test_gitlab.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletiontests/functional/api/test_projects.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionstests/unit/mixins/test_mixin_methods.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.