Skip to content

Commit c4d6db2

Browse files
committed
style: address SonarCloud findings in delta link extraction
Use PEP 604 union syntax for the type hint and extract the repeated '@odata.deltaLink' literal into a constant.
1 parent 258ebaa commit c4d6db2

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/msgraph_core/tasks/page_iterator.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
T = TypeVar('T', bound=Parsable)
3434

35+
ODATA_DELTA_LINK_KEY = '@odata.deltaLink'
36+
3537

3638
class PageIterator:
3739
"""
@@ -156,7 +158,7 @@ async def next(self) -> Optional[PageResult]:
156158
return PageResult(odata_next_link=next_link, value=value)
157159

158160
@staticmethod
159-
def _extract_delta_link(response: Union[T, dict, object]) -> str:
161+
def _extract_delta_link(response: T | dict | object) -> str:
160162
"""
161163
Extracts the '@odata.deltaLink' from a response.
162164
Checks the additional data bag first (for models that do not
@@ -169,10 +171,10 @@ def _extract_delta_link(response: Union[T, dict, object]) -> str:
169171
str: The delta link, or an empty string if none is present.
170172
"""
171173
if isinstance(response, dict):
172-
return response.get('@odata.deltaLink', '')
174+
return response.get(ODATA_DELTA_LINK_KEY, '')
173175
additional_data = getattr(response, 'additional_data', None)
174-
if additional_data and additional_data.get('@odata.deltaLink'):
175-
return additional_data.get('@odata.deltaLink')
176+
if additional_data and additional_data.get(ODATA_DELTA_LINK_KEY):
177+
return additional_data.get(ODATA_DELTA_LINK_KEY)
176178
return getattr(response, 'odata_delta_link', '')
177179

178180
@staticmethod

0 commit comments

Comments
 (0)