Skip to content

Commit e43a010

Browse files
committed
feat(async): fullfill RESTObjectList with sync and async methods
1 parent c4117e1 commit e43a010

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

gitlab/base.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import importlib
1919

2020

21-
class RESTObject(object):
21+
class RESTObject:
2222
"""Represents an object built from server data.
2323
2424
It holds the attributes know from the server, and the updated attributes in
@@ -144,7 +144,7 @@ def attributes(self):
144144
return d
145145

146146

147-
class RESTObjectList(object):
147+
class RESTObjectList:
148148
"""Generator object representing a list of RESTObject's.
149149
150150
This generator uses the Gitlab pagination system to fetch new data when
@@ -174,16 +174,26 @@ def __init__(self, manager, obj_cls, _list):
174174
self._obj_cls = obj_cls
175175
self._list = _list
176176

177-
def __aiter__(self):
178-
return self
179-
180177
def __len__(self):
181178
return len(self._list)
182179

180+
def __iter__(self):
181+
return self
182+
183+
def __next__(self):
184+
return self.next()
185+
186+
def next(self):
187+
data = self._list.next()
188+
return self._obj_cls(self.manager, data)
189+
190+
def __aiter__(self):
191+
return self
192+
183193
async def __anext__(self):
184-
return await self.next()
194+
return await self.anext()
185195

186-
async def next(self):
196+
async def anext(self):
187197
data = await self._list.next()
188198
return self._obj_cls(self.manager, data)
189199

0 commit comments

Comments
 (0)