| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,13 +93,13 @@ Examples: | |||
| 93 | 93 | .. code-block:: python | |
| 94 | 94 | ||
| 95 | 95 | # list all the projects | |
| 96 | - projects = gl.projects.list(as_list=False) | ||
| 96 | + projects = gl.projects.list(iterator=True) | ||
| 97 | 97 | for project in projects: | |
| 98 | 98 | print(project) | |
| 99 | 99 | ||
| 100 | 100 | # get the group with id == 2 | |
| 101 | 101 | group = gl.groups.get(2) | |
| 102 | - for project in group.projects.list(as_list=False): | ||
| 102 | + for project in group.projects.list(iterator=True): | ||
| 103 | 103 | print(project) | |
| 104 | 104 | ||
| 105 | 105 | # create a new user | |
@@ -109,7 +109,7 @@ Examples: | |||
| 109 | 109 | ||
| 110 | 110 | .. warning:: | |
| 111 | 111 | Calling ``list()`` without any arguments will by default not return the complete list | |
| 112 | - of items. Use either the ``all=True`` or ``as_list=False`` parameters to get all the | ||
| 112 | + of items. Use either the ``all=True`` or ``iterator=True`` parameters to get all the | ||
| 113 | 113 | items when using listing methods. See the :ref:`pagination` section for more | |
| 114 | 114 | information. | |
| 115 | 115 | ||
@@ -156,9 +156,9 @@ conflict with python or python-gitlab when using them as kwargs: | |||
| 156 | 156 | ||
| 157 | 157 | .. code-block:: python | |
| 158 | 158 | ||
| 159 | - gl.user_activities.list(from='2019-01-01', as_list=False) ## invalid | ||
| 159 | + gl.user_activities.list(from='2019-01-01', iterator=True) ## invalid | ||
| 160 | 160 | ||
| 161 | - gl.user_activities.list(query_parameters={'from': '2019-01-01'}, as_list=False) # OK | ||
| 161 | + gl.user_activities.list(query_parameters={'from': '2019-01-01'}, iterator=True) # OK | ||
| 162 | 162 | ||
| 163 | 163 | Gitlab Objects | |
| 164 | 164 | ============== | |
@@ -282,13 +282,13 @@ order options. At the time of writing, only ``order_by="id"`` works. | |||
| 282 | 282 | Reference: | |
| 283 | 283 | https://docs.gitlab.com/ce/api/README.html#keyset-based-pagination | |
| 284 | 284 | ||
| 285 | - ``list()`` methods can also return a generator object which will handle the | ||
| 286 | - next calls to the API when required. This is the recommended way to iterate | ||
| 287 | - through a large number of items: | ||
| 285 | + ``list()`` methods can also return a generator object, by passing the argument | ||
| 286 | + ``iterator=True``, which will handle the next calls to the API when required. This | ||
| 287 | + is the recommended way to iterate through a large number of items: | ||
| 288 | 288 | ||
| 289 | 289 | .. code-block:: python | |
| 290 | 290 | ||
| 291 | - items = gl.groups.list(as_list=False) | ||
| 291 | + items = gl.groups.list(iterator=True) | ||
| 292 | 292 | for item in items: | |
| 293 | 293 | print(item.attributes) | |
| 294 | 294 | ||
@@ -310,6 +310,10 @@ The generator exposes extra listing information as received from the server: | |||
| 310 | 310 | For more information see: | |
| 311 | 311 | https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headers | |
| 312 | 312 | ||
| 313 | + .. note:: | ||
| 314 | + Prior to python-gitlab 3.6.0 the argument ``as_list`` was used instead of | ||
| 315 | + ``iterator``. ``as_list=False`` is the equivalent of ``iterator=True``. | ||
| 316 | + | ||
| 313 | 317 | Sudo | |
| 314 | 318 | ==== | |
| 315 | 319 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,13 +63,13 @@ The ``search()`` methods implement the pagination support:: | |||
| 63 | 63 | ||
| 64 | 64 | # get a generator that will automatically make required API calls for | |
| 65 | 65 | # pagination | |
| 66 | - for item in gl.search(gitlab.const.SEARCH_SCOPE_ISSUES, search_str, as_list=False): | ||
| 66 | + for item in gl.search(gitlab.const.SEARCH_SCOPE_ISSUES, search_str, iterator=True): | ||
| 67 | 67 | do_something(item) | |
| 68 | 68 | ||
| 69 | 69 | The search API doesn't return objects, but dicts. If you need to act on | |
| 70 | 70 | objects, you need to create them explicitly:: | |
| 71 | 71 | ||
| 72 | - for item in gl.search(gitlab.const.SEARCH_SCOPE_ISSUES, search_str, as_list=False): | ||
| 72 | + for item in gl.search(gitlab.const.SEARCH_SCOPE_ISSUES, search_str, iterator=True): | ||
| 73 | 73 | issue_project = gl.projects.get(item['project_id'], lazy=True) | |
| 74 | 74 | issue = issue_project.issues.get(item['iid']) | |
| 75 | 75 | issue.state = 'closed' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -413,4 +413,4 @@ Get the users activities:: | |||
| 413 | 413 | ||
| 414 | 414 | activities = gl.user_activities.list( | |
| 415 | 415 | query_parameters={'from': '2018-07-01'}, | |
| 416 | - all=True, as_list=False) | ||
| 416 | + all=True, iterator=True) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -807,7 +807,9 @@ def http_list( | |||
| 807 | 807 | self, | |
| 808 | 808 | path: str, | |
| 809 | 809 | query_data: Optional[Dict[str, Any]] = None, | |
| 810 | - as_list: Optional[bool] = None, | ||
| 810 | + *, | ||
| 811 | + as_list: Optional[bool] = None, # Deprecated in favor of `iterator` | ||
| 812 | + iterator: Optional[bool] = None, | ||
| 811 | 813 | **kwargs: Any, | |
| 812 | 814 | ) -> Union["GitlabList", List[Dict[str, Any]]]: | |
| 813 | 815 | """Make a GET request to the Gitlab server for list-oriented queries. | |
@@ -816,12 +818,13 @@ def http_list( | |||
| 816 | 818 | path: Path or full URL to query ('/projects' or | |
| 817 | 819 | 'http://whatever/v4/api/projects') | |
| 818 | 820 | query_data: Data to send as query parameters | |
| 821 | + iterator: Indicate if should return a generator (True) | ||
| 819 | 822 | **kwargs: Extra options to send to the server (e.g. sudo, page, | |
| 820 | 823 | per_page) | |
| 821 | 824 | ||
| 822 | 825 | Returns: | |
| 823 | - A list of the objects returned by the server. If `as_list` is | ||
| 824 | - False and no pagination-related arguments (`page`, `per_page`, | ||
| 826 | + A list of the objects returned by the server. If `iterator` is | ||
| 827 | + True and no pagination-related arguments (`page`, `per_page`, | ||
| 825 | 828 | `all`) are defined then a GitlabList object (generator) is returned | |
| 826 | 829 | instead. This object will make API calls when needed to fetch the | |
| 827 | 830 | next items from the server. | |
@@ -832,15 +835,29 @@ def http_list( | |||
| 832 | 835 | """ | |
| 833 | 836 | query_data = query_data or {} | |
| 834 | 837 | ||
| 835 | - # In case we want to change the default behavior at some point | ||
| 836 | - as_list = True if as_list is None else as_list | ||
| 838 | + # Don't allow both `as_list` and `iterator` to be set. | ||
| 839 | + if as_list is not None and iterator is not None: | ||
| 840 | + raise ValueError( | ||
| 841 | + "Only one of `as_list` or `iterator` can be used. " | ||
| 842 | + "Use `iterator` instead of `as_list`. `as_list` is deprecated." | ||
| 843 | + ) | ||
| 844 | + | ||
| 845 | + if as_list is not None: | ||
| 846 | + iterator = not as_list | ||
| 847 | + utils.warn( | ||
| 848 | + message=( | ||
| 849 | + f"`as_list={as_list}` is deprecated and will be removed in a " | ||
| 850 | + f"future version. Use `iterator={iterator}` instead." | ||
| 851 | + ), | ||
| 852 | + category=DeprecationWarning, | ||
| 853 | + ) | ||
| 837 | 854 | ||
| 838 | 855 | get_all = kwargs.pop("all", None) | |
| 839 | 856 | url = self._build_url(path) | |
| 840 | 857 | ||
| 841 | 858 | page = kwargs.get("page") | |
| 842 | 859 | ||
| 843 | - if as_list is False: | ||
| 860 | + if iterator: | ||
| 844 | 861 | # Generator requested | |
| 845 | 862 | return GitlabList(self, url, query_data, **kwargs) | |
| 846 | 863 | ||
@@ -879,7 +896,7 @@ def should_emit_warning() -> bool: | |||
| 879 | 896 | utils.warn( | |
| 880 | 897 | message=( | |
| 881 | 898 | f"Calling a `list()` method without specifying `all=True` or " | |
| 882 | - f"`as_list=False` will return a maximum of {gl_list.per_page} items. " | ||
| 899 | + f"`iterator=True` will return a maximum of {gl_list.per_page} items. " | ||
| 883 | 900 | f"Your query returned {len(items)} of {total_items} items. See " | |
| 884 | 901 | f"{_PAGINATION_URL} for more details. If this was done intentionally, " | |
| 885 | 902 | f"then this warning can be supressed by adding the argument " | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,12 +201,12 @@ def list(self, **kwargs: Any) -> Union[base.RESTObjectList, List[base.RESTObject | |||
| 201 | 201 | all: If True, return all the items, without pagination | |
| 202 | 202 | per_page: Number of items to retrieve per request | |
| 203 | 203 | page: ID of the page to return (starts with page 1) | |
| 204 | - as_list: If set to False and no pagination option is | ||
| 204 | + iterator: If set to True and no pagination option is | ||
| 205 | 205 | defined, return a generator instead of a list | |
| 206 | 206 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 207 | 207 | ||
| 208 | 208 | Returns: | |
| 209 | - The list of objects, or a generator if `as_list` is False | ||
| 209 | + The list of objects, or a generator if `iterator` is True | ||
| 210 | 210 | ||
| 211 | 211 | Raises: | |
| 212 | 212 | GitlabAuthenticationError: If authentication is not correct | |
@@ -846,8 +846,6 @@ def participants(self, **kwargs: Any) -> Dict[str, Any]: | |||
| 846 | 846 | all: If True, return all the items, without pagination | |
| 847 | 847 | per_page: Number of items to retrieve per request | |
| 848 | 848 | page: ID of the page to return (starts with page 1) | |
| 849 | - as_list: If set to False and no pagination option is | ||
| 850 | - defined, return a generator instead of a list | ||
| 851 | 849 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 852 | 850 | ||
| 853 | 851 | Raises: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,12 +26,12 @@ def list(self, **kwargs: Any) -> Union[List[LDAPGroup], RESTObjectList]: | |||
| 26 | 26 | all: If True, return all the items, without pagination | |
| 27 | 27 | per_page: Number of items to retrieve per request | |
| 28 | 28 | page: ID of the page to return (starts with page 1) | |
| 29 | - as_list: If set to False and no pagination option is | ||
| 29 | + iterator: If set to True and no pagination option is | ||
| 30 | 30 | defined, return a generator instead of a list | |
| 31 | 31 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 32 | 32 | ||
| 33 | 33 | Returns: | |
| 34 | - The list of objects, or a generator if `as_list` is False | ||
| 34 | + The list of objects, or a generator if `iterator` is True | ||
| 35 | 35 | ||
| 36 | 36 | Raises: | |
| 37 | 37 | GitlabAuthenticationError: If authentication is not correct | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -199,8 +199,6 @@ def closes_issues(self, **kwargs: Any) -> RESTObjectList: | |||
| 199 | 199 | all: If True, return all the items, without pagination | |
| 200 | 200 | per_page: Number of items to retrieve per request | |
| 201 | 201 | page: ID of the page to return (starts with page 1) | |
| 202 | - as_list: If set to False and no pagination option is | ||
| 203 | - defined, return a generator instead of a list | ||
| 204 | 202 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 205 | 203 | ||
| 206 | 204 | Raises: | |
@@ -211,7 +209,7 @@ def closes_issues(self, **kwargs: Any) -> RESTObjectList: | |||
| 211 | 209 | List of issues | |
| 212 | 210 | """ | |
| 213 | 211 | path = f"{self.manager.path}/{self.encoded_id}/closes_issues" | |
| 214 | - data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs) | ||
| 212 | + data_list = self.manager.gitlab.http_list(path, iterator=True, **kwargs) | ||
| 215 | 213 | if TYPE_CHECKING: | |
| 216 | 214 | assert isinstance(data_list, gitlab.GitlabList) | |
| 217 | 215 | manager = ProjectIssueManager(self.manager.gitlab, parent=self.manager._parent) | |
@@ -226,8 +224,6 @@ def commits(self, **kwargs: Any) -> RESTObjectList: | |||
| 226 | 224 | all: If True, return all the items, without pagination | |
| 227 | 225 | per_page: Number of items to retrieve per request | |
| 228 | 226 | page: ID of the page to return (starts with page 1) | |
| 229 | - as_list: If set to False and no pagination option is | ||
| 230 | - defined, return a generator instead of a list | ||
| 231 | 227 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 232 | 228 | ||
| 233 | 229 | Raises: | |
@@ -239,7 +235,7 @@ def commits(self, **kwargs: Any) -> RESTObjectList: | |||
| 239 | 235 | """ | |
| 240 | 236 | ||
| 241 | 237 | path = f"{self.manager.path}/{self.encoded_id}/commits" | |
| 242 | - data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs) | ||
| 238 | + data_list = self.manager.gitlab.http_list(path, iterator=True, **kwargs) | ||
| 243 | 239 | if TYPE_CHECKING: | |
| 244 | 240 | assert isinstance(data_list, gitlab.GitlabList) | |
| 245 | 241 | manager = ProjectCommitManager(self.manager.gitlab, parent=self.manager._parent) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,8 +33,6 @@ def issues(self, **kwargs: Any) -> RESTObjectList: | |||
| 33 | 33 | all: If True, return all the items, without pagination | |
| 34 | 34 | per_page: Number of items to retrieve per request | |
| 35 | 35 | page: ID of the page to return (starts with page 1) | |
| 36 | - as_list: If set to False and no pagination option is | ||
| 37 | - defined, return a generator instead of a list | ||
| 38 | 36 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 39 | 37 | ||
| 40 | 38 | Raises: | |
@@ -46,7 +44,7 @@ def issues(self, **kwargs: Any) -> RESTObjectList: | |||
| 46 | 44 | """ | |
| 47 | 45 | ||
| 48 | 46 | path = f"{self.manager.path}/{self.encoded_id}/issues" | |
| 49 | - data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs) | ||
| 47 | + data_list = self.manager.gitlab.http_list(path, iterator=True, **kwargs) | ||
| 50 | 48 | if TYPE_CHECKING: | |
| 51 | 49 | assert isinstance(data_list, RESTObjectList) | |
| 52 | 50 | manager = GroupIssueManager(self.manager.gitlab, parent=self.manager._parent) | |
@@ -62,8 +60,6 @@ def merge_requests(self, **kwargs: Any) -> RESTObjectList: | |||
| 62 | 60 | all: If True, return all the items, without pagination | |
| 63 | 61 | per_page: Number of items to retrieve per request | |
| 64 | 62 | page: ID of the page to return (starts with page 1) | |
| 65 | - as_list: If set to False and no pagination option is | ||
| 66 | - defined, return a generator instead of a list | ||
| 67 | 63 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 68 | 64 | ||
| 69 | 65 | Raises: | |
@@ -74,7 +70,7 @@ def merge_requests(self, **kwargs: Any) -> RESTObjectList: | |||
| 74 | 70 | The list of merge requests | |
| 75 | 71 | """ | |
| 76 | 72 | path = f"{self.manager.path}/{self.encoded_id}/merge_requests" | |
| 77 | - data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs) | ||
| 73 | + data_list = self.manager.gitlab.http_list(path, iterator=True, **kwargs) | ||
| 78 | 74 | if TYPE_CHECKING: | |
| 79 | 75 | assert isinstance(data_list, RESTObjectList) | |
| 80 | 76 | manager = GroupIssueManager(self.manager.gitlab, parent=self.manager._parent) | |
@@ -114,8 +110,6 @@ def issues(self, **kwargs: Any) -> RESTObjectList: | |||
| 114 | 110 | all: If True, return all the items, without pagination | |
| 115 | 111 | per_page: Number of items to retrieve per request | |
| 116 | 112 | page: ID of the page to return (starts with page 1) | |
| 117 | - as_list: If set to False and no pagination option is | ||
| 118 | - defined, return a generator instead of a list | ||
| 119 | 113 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 120 | 114 | ||
| 121 | 115 | Raises: | |
@@ -127,7 +121,7 @@ def issues(self, **kwargs: Any) -> RESTObjectList: | |||
| 127 | 121 | """ | |
| 128 | 122 | ||
| 129 | 123 | path = f"{self.manager.path}/{self.encoded_id}/issues" | |
| 130 | - data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs) | ||
| 124 | + data_list = self.manager.gitlab.http_list(path, iterator=True, **kwargs) | ||
| 131 | 125 | if TYPE_CHECKING: | |
| 132 | 126 | assert isinstance(data_list, RESTObjectList) | |
| 133 | 127 | manager = ProjectIssueManager(self.manager.gitlab, parent=self.manager._parent) | |
@@ -143,8 +137,6 @@ def merge_requests(self, **kwargs: Any) -> RESTObjectList: | |||
| 143 | 137 | all: If True, return all the items, without pagination | |
| 144 | 138 | per_page: Number of items to retrieve per request | |
| 145 | 139 | page: ID of the page to return (starts with page 1) | |
| 146 | - as_list: If set to False and no pagination option is | ||
| 147 | - defined, return a generator instead of a list | ||
| 148 | 140 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 149 | 141 | ||
| 150 | 142 | Raises: | |
@@ -155,7 +147,7 @@ def merge_requests(self, **kwargs: Any) -> RESTObjectList: | |||
| 155 | 147 | The list of merge requests | |
| 156 | 148 | """ | |
| 157 | 149 | path = f"{self.manager.path}/{self.encoded_id}/merge_requests" | |
| 158 | - data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs) | ||
| 150 | + data_list = self.manager.gitlab.http_list(path, iterator=True, **kwargs) | ||
| 159 | 151 | if TYPE_CHECKING: | |
| 160 | 152 | assert isinstance(data_list, RESTObjectList) | |
| 161 | 153 | manager = ProjectMergeRequestManager( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,7 @@ def repository_tree( | |||
| 60 | 60 | all: If True, return all the items, without pagination | |
| 61 | 61 | per_page: Number of items to retrieve per request | |
| 62 | 62 | page: ID of the page to return (starts with page 1) | |
| 63 | - as_list: If set to False and no pagination option is | ||
| 63 | + iterator: If set to True and no pagination option is | ||
| 64 | 64 | defined, return a generator instead of a list | |
| 65 | 65 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 66 | 66 | ||
@@ -172,7 +172,7 @@ def repository_contributors( | |||
| 172 | 172 | all: If True, return all the items, without pagination | |
| 173 | 173 | per_page: Number of items to retrieve per request | |
| 174 | 174 | page: ID of the page to return (starts with page 1) | |
| 175 | - as_list: If set to False and no pagination option is | ||
| 175 | + iterator: If set to True and no pagination option is | ||
| 176 | 176 | defined, return a generator instead of a list | |
| 177 | 177 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 178 | 178 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,7 +81,7 @@ def all(self, scope: Optional[str] = None, **kwargs: Any) -> List[Runner]: | |||
| 81 | 81 | all: If True, return all the items, without pagination | |
| 82 | 82 | per_page: Number of items to retrieve per request | |
| 83 | 83 | page: ID of the page to return (starts with page 1) | |
| 84 | - as_list: If set to False and no pagination option is | ||
| 84 | + iterator: If set to True and no pagination option is | ||
| 85 | 85 | defined, return a generator instead of a list | |
| 86 | 86 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 87 | 87 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments