33from __future__ import annotations
44
55import dataclasses
6- from typing import Any , Generic , Iterator , TypeVar , TYPE_CHECKING
6+ from typing import Any , Generic , Iterator , TypeVar , TYPE_CHECKING , cast
77
88from sap_cloud_sdk .core .odata ._constants import (
99 DELETE ,
1414 PUT ,
1515)
1616from sap_cloud_sdk .core .odata ._query import OrderDirection , StructuredQuery
17- from sap_cloud_sdk .core .odata ._response import deserialize_collection , deserialize_single
17+ from sap_cloud_sdk .core .odata ._response import (
18+ deserialize_collection ,
19+ deserialize_single ,
20+ )
1821from sap_cloud_sdk .core .odata ._pagination import ODataPageIterator
1922
2023if TYPE_CHECKING :
@@ -57,9 +60,7 @@ class GetAllRequestBuilder(Generic[T]):
5760 )
5861 """
5962
60- def __init__ (
61- self , transport : "ODataHttpTransport" , entity_type : type [T ]
62- ) -> None :
63+ def __init__ (self , transport : "ODataHttpTransport" , entity_type : type [T ]) -> None :
6364 self ._transport = transport
6465 self ._entity_type = entity_type
6566 self ._query = StructuredQuery ()
@@ -105,10 +106,13 @@ def iterate_pages(self) -> Iterator[list[T]]:
105106 params = self ._query .to_params ()
106107 if params :
107108 from urllib .parse import urlencode
109+
108110 first_url += "?" + urlencode (params )
109111
110112 iterator = ODataPageIterator (
111- fetch_page = lambda url : self ._transport .request (GET , _strip_base (url , self ._transport ._base_url )),
113+ fetch_page = lambda url : self ._transport .request (
114+ GET , _strip_base (url , self ._transport ._base_url )
115+ ),
112116 entity_type = self ._entity_type ,
113117 first_url = first_url ,
114118 )
@@ -124,7 +128,7 @@ def _strip_base(url: str, base_url: str) -> str:
124128 """Strip *base_url* prefix from *url* to get a relative path."""
125129 prefix = base_url + "/"
126130 if url .startswith (prefix ):
127- return url [len (prefix ):]
131+ return url [len (prefix ) :]
128132 return url
129133
130134
@@ -160,17 +164,16 @@ def execute(self) -> T:
160164class CreateRequestBuilder (Generic [T ]):
161165 """Builder for OData entity creation (POST)."""
162166
163- def __init__ (
164- self , transport : "ODataHttpTransport" , entity : T
165- ) -> None :
167+ def __init__ (self , transport : "ODataHttpTransport" , entity : T ) -> None :
166168 self ._transport = transport
167169 self ._entity = entity
168170
169171 def execute (self ) -> T :
170172 """Create the entity and return the server response as the same type."""
171173 entity_type = type (self ._entity )
172174 path = _entity_set_path (entity_type )
173- body = self ._entity .to_dict () if hasattr (self ._entity , "to_dict" ) else dataclasses .asdict (self ._entity ) # type: ignore[arg-type]
175+ e : Any = cast (Any , self ._entity )
176+ body = e .to_dict () if hasattr (e , "to_dict" ) else dataclasses .asdict (e )
174177 data = self ._transport .request (POST , path , json = body )
175178 return deserialize_single (data , entity_type )
176179
@@ -205,7 +208,8 @@ def execute(self) -> T:
205208 )
206209 key = {k : getattr (self ._entity , k ) for k in key_fields }
207210 path = _entity_set_path (entity_type ) + _build_key_segment (key )
208- body = self ._entity .to_dict () if hasattr (self ._entity , "to_dict" ) else dataclasses .asdict (self ._entity ) # type: ignore[arg-type]
211+ e : Any = cast (Any , self ._entity )
212+ body = e .to_dict () if hasattr (e , "to_dict" ) else dataclasses .asdict (e )
209213 method = PUT if self ._use_put else PATCH
210214 extra : dict [str , str ] = {}
211215 if self ._etag is not None :
0 commit comments