Skip to content

Commit 5598b7d

Browse files
committed
clean up page iterator fixes
1 parent fcc0b8d commit 5598b7d

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/msgraph_core/tasks/page_iterator.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
and models modules.
1818
"""
1919

20-
from typing import Callable, Optional, Union, Dict, List
20+
from typing import Callable, Optional, Union, Dict, Type
2121

2222
from typing import TypeVar
2323
from requests.exceptions import InvalidURL
@@ -65,7 +65,7 @@ def __init__(
6565
self.request_adapter = request_adapter
6666

6767
if isinstance(response, Parsable) and not constructor_callable:
68-
parsable_factory = type(response) # type: ignore
68+
parsable_factory: Type[Parsable] = type(response)
6969
elif constructor_callable is None:
7070
parsable_factory = PageResult
7171
else:
@@ -75,7 +75,7 @@ def __init__(
7575
self.parsable_factory = parsable_factory
7676
self.pause_index = 0
7777
self.headers: HeadersCollection = HeadersCollection()
78-
self.request_options = [] # type: ignore
78+
self.request_options: list = []
7979
self.current_page = self.convert_to_page(response)
8080
self.object_type = self.current_page.value[
8181
0].__class__.__name__ if self.current_page.value else None
@@ -148,8 +148,9 @@ async def next(self) -> Optional[PageResult]:
148148
if self.current_page is not None and not self.current_page.odata_next_link:
149149
return None
150150
response = await self.fetch_next_page()
151-
page: PageResult = PageResult(response.odata_next_link, response.value) # type: ignore
152-
return page
151+
next_link = response.odata_next_link if response and hasattr(response, 'odata_next_link') else None
152+
value = response.value if response and hasattr(response, 'value') else None
153+
return PageResult(next_link, value)
153154

154155
@staticmethod
155156
def convert_to_page(response: Union[T, list, object]) -> PageResult:
@@ -169,9 +170,9 @@ def convert_to_page(response: Union[T, list, object]) -> PageResult:
169170
raise ValueError('Response cannot be null.')
170171
value = None
171172
if isinstance(response, list):
172-
value = response.value # type: ignore
173+
value = response
173174
elif hasattr(response, 'value'):
174-
value = getattr(response, 'value')
175+
value = response.value
175176
elif isinstance(response, object):
176177
value = getattr(response, 'value', [])
177178
if value is None:
@@ -181,8 +182,7 @@ def convert_to_page(response: Union[T, list, object]) -> PageResult:
181182
parsable_page, dict
182183
) else getattr(parsable_page, 'odata_next_link', '')
183184

184-
page: PageResult = PageResult(next_link, value)
185-
return page
185+
return PageResult(next_link, value)
186186

187187
async def fetch_next_page(self) -> Optional[Union[T, PageResult]]:
188188
"""
@@ -205,10 +205,9 @@ async def fetch_next_page(self) -> Optional[Union[T, PageResult]]:
205205
request_info.headers = self.headers
206206
if self.request_options:
207207
request_info.add_request_options(*self.request_options)
208-
response = await self.request_adapter.send_async(
208+
return await self.request_adapter.send_async(
209209
request_info, self.parsable_factory, self.error_mapping # type: ignore
210210
)
211-
return response
212211

213212
def enumerate(self, callback: Optional[Callable] = None) -> bool:
214213
"""

0 commit comments

Comments
 (0)