Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,29 @@ jobs:
working-directory: ${{ matrix.library.path }}
run: |
poetry run pytest

validation-workflow-with-generated-code:
runs-on: ubuntu-latest
timeout-minutes: 40
strategy:
max-parallel: 10
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
working-directory: "./tests/validation"
run: |
python -m pip install --upgrade poetry
poetry install
- name: Static type checking with Mypy
working-directory: "./tests/validation"
run: |
poetry run mypy validation

24 changes: 13 additions & 11 deletions packages/abstractions/kiota_abstractions/request_adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from abc import ABC, abstractmethod
from datetime import datetime
from io import BytesIO
Expand Down Expand Up @@ -31,7 +32,7 @@ def get_serialization_writer_factory(self) -> SerializationWriterFactory:
@abstractmethod
async def send_async(
self, request_info: RequestInformation, parsable_factory: ParsableFactory[ModelType],
error_map: Optional[Dict[str, ParsableFactory]]
error_map: Optional[Dict[str, type[ParsableFactory]]]
) -> Optional[ModelType]:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized response model.
Expand All @@ -40,7 +41,7 @@ async def send_async(
request_info (RequestInformation): the request info to execute.
parsable_factory (ParsableFactory): the class of response model to
deserialize the response into.
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in case
error_map (Optional[Dict[str, type[ParsableFactory]]]): the error dict to use in case
of a failed request.

Returns:
Expand All @@ -52,8 +53,8 @@ async def send_async(
async def send_collection_async(
self,
request_info: RequestInformation,
parsable_factory: ParsableFactory,
error_map: Optional[Dict[str, ParsableFactory]],
parsable_factory: ParsableFactory[ModelType],
error_map: Optional[Dict[str, type[ParsableFactory]]],
) -> Optional[List[ModelType]]:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized response model collection.
Expand All @@ -62,7 +63,7 @@ async def send_collection_async(
request_info (RequestInformation): the request info to execute.
parsable_factory (ParsableFactory): the class of response model to
deserialize the response into.
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
error_map (Optional[Dict[str, type[ParsableFactory]]]): the error dict to use in
case of a failed request.

Returns:
Expand All @@ -75,7 +76,7 @@ async def send_collection_of_primitive_async(
self,
request_info: RequestInformation,
response_type: ResponseType,
error_map: Optional[Dict[str, ParsableFactory]],
error_map: Optional[Dict[str, type[ParsableFactory]]],
) -> Optional[List[ResponseType]]:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized response model collection.
Expand All @@ -84,7 +85,7 @@ async def send_collection_of_primitive_async(
request_info (RequestInformation): the request info to execute.
response_type (ResponseType): the class of the response model to deserialize the
response into.
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
error_map (Optional[Dict[str, type[ParsableFactory]]]): the error dict to use in
case of a failed request.

Returns:
Expand All @@ -95,7 +96,7 @@ async def send_collection_of_primitive_async(
@abstractmethod
async def send_primitive_async(
self, request_info: RequestInformation, response_type: str,
error_map: Optional[Dict[str, ParsableFactory]]
error_map: Optional[Dict[str, type[ParsableFactory]]]
) -> Optional[ResponseType]:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized primitive response model.
Expand All @@ -104,7 +105,7 @@ async def send_primitive_async(
request_info (RequestInformation): the request info to execute.
response_type (str): the class name of the response model to deserialize the
response into.
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
error_map (Optional[Dict[str, type[ParsableFactory]]]): the error dict to use in
case of a failed request.

Returns:
Expand All @@ -114,14 +115,15 @@ async def send_primitive_async(

@abstractmethod
async def send_no_response_content_async(
self, request_info: RequestInformation, error_map: Optional[Dict[str, ParsableFactory]]
self, request_info: RequestInformation, error_map: Optional[Dict[str,
type[ParsableFactory]]]
) -> None:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized primitive response model.

Args:
request_info (RequestInformation):the request info to execute.
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
error_map (Optional[Dict[str, type[ParsableFactory]]]): the error dict to use in
case of a failed request.
"""
pass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from abc import abstractmethod
from typing import Generic, Optional, TypeVar
from typing import Generic, Optional, Protocol, TypeVar

from .parsable import Parsable
from .parse_node import ParseNode

U = TypeVar("U", bound=Parsable)
U_co = TypeVar("U_co", bound="Parsable", covariant=True)


class ParsableFactory(Generic[U]):
class ParsableFactory(Protocol, Generic[U_co]):
"""Defines the factory for creating parsable objects.
"""

@staticmethod
@abstractmethod
def create_from_discriminator_value(parse_node: Optional[ParseNode]) -> U:
def create_from_discriminator_value(parse_node: ParseNode) -> U_co:
"""Create a new parsable object from the given serialized data.

Args:
Expand Down
28 changes: 15 additions & 13 deletions packages/http/httpx/kiota_http/httpx_request_adapter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""HTTPX client request adapter."""
from __future__ import annotations
import re
from datetime import datetime
from typing import Any, Dict, Generic, List, Optional, TypeVar, Union
Expand Down Expand Up @@ -152,15 +153,15 @@ async def send_async(
self,
request_info: RequestInformation,
parsable_factory: ParsableFactory[ModelType],
error_map: Optional[Dict[str, ParsableFactory]],
error_map: Optional[Dict[str, type[ParsableFactory]]],
) -> Optional[ModelType]:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized response model.
Args:
request_info (RequestInformation): the request info to execute.
parsable_factory (ParsableFactory): the class of the response model
to deserialize the response into.
error_map (Dict[str, ParsableFactory]): the error dict to use in
error_map (Dict[str, type[ParsableFactory]]): the error dict to use in
case of a failed request.

Returns:
Expand Down Expand Up @@ -197,15 +198,15 @@ async def send_collection_async(
self,
request_info: RequestInformation,
parsable_factory: ParsableFactory,
error_map: Optional[Dict[str, ParsableFactory]],
error_map: Optional[Dict[str, type[ParsableFactory]]],
) -> Optional[List[ModelType]]:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized response model collection.
Args:
request_info (RequestInformation): the request info to execute.
parsable_factory (ParsableFactory): the class of the response model
to deserialize the response into.
error_map (Dict[str, ParsableFactory]): the error dict to use in
error_map (Dict[str, type[ParsableFactory]]): the error dict to use in
case of a failed request.

Returns:
Expand Down Expand Up @@ -244,15 +245,15 @@ async def send_collection_of_primitive_async(
self,
request_info: RequestInformation,
response_type: ResponseType,
error_map: Optional[Dict[str, ParsableFactory]],
error_map: Optional[Dict[str, type[ParsableFactory]]],
) -> Optional[List[ResponseType]]:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized response model collection.
Args:
request_info (RequestInformation): the request info to execute.
response_type (ResponseType): the class of the response model
to deserialize the response into.
error_map (Dict[str, ParsableFactory]): the error dict to use in
error_map (Dict[str, type[ParsableFactory]]): the error dict to use in
case of a failed request.

Returns:
Expand Down Expand Up @@ -291,15 +292,15 @@ async def send_primitive_async(
self,
request_info: RequestInformation,
response_type: str,
error_map: Optional[Dict[str, ParsableFactory]],
error_map: Optional[Dict[str, type[ParsableFactory]]],
) -> Optional[ResponseType]:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized primitive response model.
Args:
request_info (RequestInformation): the request info to execute.
response_type (str): the class name of the response model to deserialize the
response into.
error_map (Dict[str, ParsableFactory]): the error dict to use in case
error_map (Dict[str, type[ParsableFactory]]): the error dict to use in case
of a failed request.

Returns:
Expand Down Expand Up @@ -352,13 +353,14 @@ async def send_primitive_async(
parent_span.end()

async def send_no_response_content_async(
self, request_info: RequestInformation, error_map: Optional[Dict[str, ParsableFactory]]
self, request_info: RequestInformation, error_map: Optional[Dict[str,
type[ParsableFactory]]]
) -> None:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized primitive response model.
Args:
request_info (RequestInformation):the request info to execute.
error_map (Dict[str, ParsableFactory]): the error dict to use in case
error_map (Dict[str, type[ParsableFactory]]): the error dict to use in case
of a failed request.
"""
parent_span = self.start_tracing_span(request_info, "send_no_response_content_async")
Expand Down Expand Up @@ -418,7 +420,7 @@ def _should_return_none(self, response: httpx.Response) -> bool:
async def throw_failed_responses(
self,
response: httpx.Response,
error_map: Optional[Dict[str, ParsableFactory]],
error_map: Optional[Dict[str, type[ParsableFactory]]],
parent_span: trace.Span,
attribute_span: trace.Span,
) -> None:
Expand Down Expand Up @@ -644,13 +646,13 @@ async def convert_to_native_async(self, request_info: RequestInformation) -> htt
parent_span.end()

def _error_class_not_in_error_mapping(
self, error_map: Dict[str, ParsableFactory], status_code: int
self, error_map: Dict[str, type[ParsableFactory]], status_code: int
) -> bool:
"""Helper function to check if the error class corresponding to a response status code
is not in the error mapping.

Args:
error_map (Dict[str, ParsableFactory]): The error mapping.
error_map (Dict[str, type[ParsableFactory]]): The error mapping.
status_code (int): The response status code.

Returns:
Expand Down
Empty file.
Loading