From 6e6806880b1fa0a43d63a97b937461d688e62ea0 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Thu, 7 Nov 2024 15:03:38 +0300 Subject: [PATCH] fix: fixes typing issues discovered from github api generation --- .../kiota_abstractions/request_adapter.py | 2 +- .../kiota_abstractions/request_information.py | 17 ++++++----------- .../serialization/parse_node.py | 4 ++-- .../httpx/kiota_http/httpx_request_adapter.py | 2 +- .../kiota_serialization_form/form_parse_node.py | 4 ++-- .../kiota_serialization_json/json_parse_node.py | 4 ++-- .../kiota_serialization_text/text_parse_node.py | 4 ++-- 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/packages/abstractions/kiota_abstractions/request_adapter.py b/packages/abstractions/kiota_abstractions/request_adapter.py index 7ef551b6..959ba299 100644 --- a/packages/abstractions/kiota_abstractions/request_adapter.py +++ b/packages/abstractions/kiota_abstractions/request_adapter.py @@ -75,7 +75,7 @@ async def send_collection_async( async def send_collection_of_primitive_async( self, request_info: RequestInformation, - response_type: ResponseType, + response_type: type[ResponseType], error_map: Optional[Dict[str, type[ParsableFactory]]], ) -> Optional[List[ResponseType]]: """Excutes the HTTP request specified by the given RequestInformation and returns the diff --git a/packages/abstractions/kiota_abstractions/request_information.py b/packages/abstractions/kiota_abstractions/request_information.py index 590e788c..e32e6dea 100644 --- a/packages/abstractions/kiota_abstractions/request_information.py +++ b/packages/abstractions/kiota_abstractions/request_information.py @@ -28,7 +28,8 @@ from .request_adapter import RequestAdapter Url = str -T = TypeVar("T", bound=Parsable) +T = TypeVar("T", bool, str, int, float, UUID, datetime, timedelta, date, time, bytes) +U = TypeVar("U", bound=Parsable) QueryParameters = TypeVar('QueryParameters') OBSERVABILITY_TRACER_NAME = "microsoft-python-kiota-abstractions" tracer = trace.get_tracer(OBSERVABILITY_TRACER_NAME, VERSION) @@ -155,7 +156,7 @@ def set_content_from_parsable( self, request_adapter: RequestAdapter, content_type: str, - values: Union[T, List[T]], + values: Union[U, List[U]], ) -> None: """Sets the request body from a model with the specified content type. @@ -163,12 +164,12 @@ def set_content_from_parsable( request_adapter (Optional[RequestAdapter]): The adapter service to get the serialization writer from. content_type (Optional[str]): the content type. - values (Union[T, List[T]]): the models. + values (Union[U, List[U]]): the models. """ with tracer.start_as_current_span( self._create_parent_span_name("set_content_from_parsable") ) as span: - writer = self._get_serialization_writer(request_adapter, content_type, values, span) + writer = self._get_serialization_writer(request_adapter, content_type, span) if isinstance(values, MultipartBody): content_type += f"; boundary={values.boundary}" values.request_adapter = request_adapter @@ -198,7 +199,7 @@ def set_content_from_scalar( with tracer.start_as_current_span( self._create_parent_span_name("set_content_from_scalar") ) as span: - writer = self._get_serialization_writer(request_adapter, content_type, values, span) + writer = self._get_serialization_writer(request_adapter, content_type, span) if isinstance(values, list): writer.writer = writer.write_collection_of_primitive_values(None, values) @@ -255,7 +256,6 @@ def _get_serialization_writer( self, request_adapter: Optional["RequestAdapter"], content_type: Optional[str], - values: Union[T, List[T]], parent_span: trace.Span, ): """_summary_ @@ -263,7 +263,6 @@ def _get_serialization_writer( Args: request_adapter (RequestAdapter): _description_ content_type (str): _description_ - values (Union[T, List[T]]): _description_ """ _span = self._start_local_tracing_span("_get_serialization_writer", parent_span) try: @@ -275,10 +274,6 @@ def _get_serialization_writer( exc = ValueError("Content Type cannot be null") _span.record_exception(exc) raise exc - if not values: - exc = ValueError("Values cannot be null") - _span.record_exception(exc) - raise exc return request_adapter.get_serialization_writer_factory( ).get_serialization_writer(content_type) finally: diff --git a/packages/abstractions/kiota_abstractions/serialization/parse_node.py b/packages/abstractions/kiota_abstractions/serialization/parse_node.py index e8c7e841..339a03e8 100644 --- a/packages/abstractions/kiota_abstractions/serialization/parse_node.py +++ b/packages/abstractions/kiota_abstractions/serialization/parse_node.py @@ -118,7 +118,7 @@ def get_time_value(self) -> Optional[time]: pass @abstractmethod - def get_collection_of_primitive_values(self, primitive_type) -> Optional[List[T]]: + def get_collection_of_primitive_values(self, primitive_type: type[T]) -> Optional[List[T]]: """Gets the collection of primitive values of the node Args: primitive_type: The type of primitive to return. @@ -128,7 +128,7 @@ def get_collection_of_primitive_values(self, primitive_type) -> Optional[List[T] pass @abstractmethod - def get_collection_of_object_values(self, factory: ParsableFactory) -> Optional[List[U]]: + def get_collection_of_object_values(self, factory: ParsableFactory[U]) -> Optional[List[U]]: """Gets the collection of model object values of the node Args: factory (ParsableFactory): The factory to use to create the model object. diff --git a/packages/http/httpx/kiota_http/httpx_request_adapter.py b/packages/http/httpx/kiota_http/httpx_request_adapter.py index 533d085d..2d1fbcf1 100644 --- a/packages/http/httpx/kiota_http/httpx_request_adapter.py +++ b/packages/http/httpx/kiota_http/httpx_request_adapter.py @@ -250,7 +250,7 @@ async def send_collection_async( async def send_collection_of_primitive_async( self, request_info: RequestInformation, - response_type: ResponseType, + response_type: type[ResponseType], error_map: Optional[Dict[str, type[ParsableFactory]]], ) -> Optional[List[ResponseType]]: """Excutes the HTTP request specified by the given RequestInformation and returns the diff --git a/packages/serialization/form/kiota_serialization_form/form_parse_node.py b/packages/serialization/form/kiota_serialization_form/form_parse_node.py index 93798109..09ab1479 100644 --- a/packages/serialization/form/kiota_serialization_form/form_parse_node.py +++ b/packages/serialization/form/kiota_serialization_form/form_parse_node.py @@ -167,7 +167,7 @@ def get_child_node(self, field_name: str) -> Optional[ParseNode]: return FormParseNode(self._fields[field_name]) return None - def get_collection_of_primitive_values(self, primitive_type: type) -> Optional[List[T]]: + def get_collection_of_primitive_values(self, primitive_type: type[T]) -> Optional[List[T]]: """Gets the collection of primitive values of the node Args: primitive_type: The type of primitive to return. @@ -189,7 +189,7 @@ def get_collection_of_primitive_values(self, primitive_type: type) -> Optional[L return result raise Exception(f"Encountered an unknown type during deserialization {primitive_type}") - def get_collection_of_object_values(self, factory: ParsableFactory) -> Optional[List[U]]: + def get_collection_of_object_values(self, factory: ParsableFactory[U]) -> Optional[List[U]]: raise Exception("Collection of object values is not supported with uri form encoding.") def get_collection_of_enum_values(self, enum_class: K) -> Optional[List[K]]: diff --git a/packages/serialization/json/kiota_serialization_json/json_parse_node.py b/packages/serialization/json/kiota_serialization_json/json_parse_node.py index cb561aa1..e147e940 100644 --- a/packages/serialization/json/kiota_serialization_json/json_parse_node.py +++ b/packages/serialization/json/kiota_serialization_json/json_parse_node.py @@ -139,7 +139,7 @@ def get_time_value(self) -> Optional[time]: return datetime_obj return None - def get_collection_of_primitive_values(self, primitive_type: Any) -> Optional[List[T]]: + def get_collection_of_primitive_values(self, primitive_type: type[T]) -> Optional[List[T]]: """Gets the collection of primitive values of the node Args: primitive_type: The type of primitive to return. @@ -161,7 +161,7 @@ def func(item): return list(map(func, json.loads(self._json_node))) return list(map(func, list(self._json_node))) - def get_collection_of_object_values(self, factory: ParsableFactory) -> Optional[List[U]]: + def get_collection_of_object_values(self, factory: ParsableFactory[U]) -> Optional[List[U]]: """Gets the collection of type U values from the json node Returns: List[U]: The collection of model object values of the node diff --git a/packages/serialization/text/kiota_serialization_text/text_parse_node.py b/packages/serialization/text/kiota_serialization_text/text_parse_node.py index c2aca3f7..76f7d7a3 100644 --- a/packages/serialization/text/kiota_serialization_text/text_parse_node.py +++ b/packages/serialization/text/kiota_serialization_text/text_parse_node.py @@ -133,7 +133,7 @@ def get_time_value(self) -> Optional[time]: return datetime_obj.time() return None - def get_collection_of_primitive_values(self, primitive_type) -> List[T]: + def get_collection_of_primitive_values(self, primitive_type: type[T]) -> List[T]: """Gets the collection of primitive values of the node Args: primitive_type: The type of primitive to return. @@ -142,7 +142,7 @@ def get_collection_of_primitive_values(self, primitive_type) -> List[T]: """ raise Exception(self.NO_STRUCTURED_DATA_MESSAGE) - def get_collection_of_object_values(self, factory: ParsableFactory) -> List[U]: + def get_collection_of_object_values(self, factory: ParsableFactory[U]) -> List[U]: """Gets the collection of type U values from the text node Returns: List[U]: The collection of model object values of the node