Skip to content

Commit

Permalink
resolve typing errors in the project
Browse files Browse the repository at this point in the history
  • Loading branch information
andrueastman committed Sep 13, 2024
1 parent 1f879d7 commit 2227122
Show file tree
Hide file tree
Showing 28 changed files with 177 additions and 144 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ jobs:
working-directory: ${{ matrix.library.path }}
run: |
poetry run pylint ${{ matrix.library.name }} --disable=W --rcfile=.pylintrc
# - name: Static type checking with Mypy
# working-directory: ${{ matrix.library.path }}
# run: |
# poetry run mypy ${{ matrix.library.name }} --ignore-missing-imports
- name: Static type checking with Mypy
working-directory: ${{ matrix.library.path }}
run: |
poetry run mypy ${{ matrix.library.name }}
- name: Run the tests
working-directory: ${{ matrix.library.path }}
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------
from typing import Any, Dict, Union
from typing import Any, Dict, Optional, Union

from .request_adapter import RequestAdapter
from .request_information import RequestInformation
Expand All @@ -14,7 +14,7 @@ class BaseRequestBuilder:

def __init__(
self, request_adapter: RequestAdapter, url_template: str,
path_parameters: Union[Dict[str, Any], str]
path_parameters: Optional[Union[Dict[str, Any], str]]
) -> None:
"""Initializes a new instance of the BaseRequestBuilder class."""
if path_parameters is None:
Expand All @@ -28,7 +28,7 @@ def __init__(
raise TypeError("url_template cannot be null.") # Empty string is allowed

# Path parameters for the request
self.path_parameters: Union[Dict[str, Any], str] = path_parameters
self.path_parameters: Dict[str, Any] = path_parameters
# Url template to use to build the URL for the current request builder
self.url_template: str = url_template
# The request adapter to use to execute the requests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class NativeResponseHandler(ResponseHandler):
async def handle_response_async(
self,
response: NativeResponseType,
error_map: Optional[Dict[str, Optional[ParsableFactory]]] = None
error_map: Optional[Dict[str, ParsableFactory]] = None
) -> NativeResponseType:
"""Callback method that is invoked when a response is received.
Args:
response (NativeResponseType): The type of the native response object.
error_map (Optional[Dict[str, Optional[ParsableFactory]]]): the error dict to use
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use
in case of a failed request.
Returns:
Any: The native response object.
Expand Down
34 changes: 17 additions & 17 deletions packages/abstractions/kiota_abstractions/request_adapter.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from abc import ABC, abstractmethod
from datetime import datetime
from io import BytesIO
from typing import Dict, Generic, List, Optional, TypeVar
from typing import Dict, Generic, List, Optional, TypeVar, Union

from .request_information import RequestInformation
from .serialization import Parsable, ParsableFactory, SerializationWriterFactory
from .store import BackingStoreFactory

ResponseType = TypeVar("ResponseType", str, int, float, bool, datetime, BytesIO)
ResponseType = TypeVar("ResponseType")
ModelType = TypeVar("ModelType", bound=Parsable)
RequestType = TypeVar("RequestType")


class RequestAdapter(ABC, Generic[ResponseType, ModelType, RequestType]):
class RequestAdapter(ABC, Generic[RequestType]):
"""Service responsible for translating abstract Request Info into concrete native HTTP requests.
"""
# The base url for every request.
base_url = str
base_url = str()

@abstractmethod
def get_serialization_writer_factory(self) -> SerializationWriterFactory:
Expand All @@ -30,8 +30,8 @@ def get_serialization_writer_factory(self) -> SerializationWriterFactory:

@abstractmethod
async def send_async(
self, request_info: RequestInformation, parsable_factory: ParsableFactory,
error_map: Dict[str, Optional[ParsableFactory]]
self, request_info: RequestInformation, parsable_factory: ParsableFactory[ModelType],
error_map: Optional[Dict[str, ParsableFactory]]
) -> Optional[ModelType]:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized response model.
Expand All @@ -40,7 +40,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 (Dict[str, Optional[ParsableFactory]]): the error dict to use in case
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in case
of a failed request.
Returns:
Expand All @@ -53,7 +53,7 @@ async def send_collection_async(
self,
request_info: RequestInformation,
parsable_factory: ParsableFactory,
error_map: Dict[str, Optional[ParsableFactory]],
error_map: Optional[Dict[str, ParsableFactory]],
) -> Optional[List[ModelType]]:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized response model collection.
Expand All @@ -62,7 +62,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 (Dict[str, Optional[ParsableFactory]]): the error dict to use in
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
case of a failed request.
Returns:
Expand All @@ -75,7 +75,7 @@ async def send_collection_of_primitive_async(
self,
request_info: RequestInformation,
response_type: ResponseType,
error_map: Dict[str, Optional[ParsableFactory]],
error_map: Optional[Dict[str, ParsableFactory]],
) -> Optional[List[ResponseType]]:
"""Excutes the HTTP request specified by the given RequestInformation and returns the
deserialized response model collection.
Expand All @@ -84,7 +84,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 (Dict[str, Optional[ParsableFactory]]): the error dict to use in
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
case of a failed request.
Returns:
Expand All @@ -94,17 +94,17 @@ async def send_collection_of_primitive_async(

@abstractmethod
async def send_primitive_async(
self, request_info: RequestInformation, response_type: ResponseType,
error_map: Dict[str, Optional[ParsableFactory]]
self, request_info: RequestInformation, response_type: str,
error_map: Optional[Dict[str, 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 (ResponseType): the class of the response model to deserialize the
response_type (str): the class name of the response model to deserialize the
response into.
error_map (Dict[str, Optional[ParsableFactory]]): the error dict to use in
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
case of a failed request.
Returns:
Expand All @@ -114,14 +114,14 @@ async def send_primitive_async(

@abstractmethod
async def send_no_response_content_async(
self, request_info: RequestInformation, error_map: Dict[str, Optional[ParsableFactory]]
self, request_info: RequestInformation, error_map: Optional[Dict[str, 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, Optional[Optional[ParsableFactory]]): the error dict to use in
error_map (Optional[Dict[str, 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
Expand Up @@ -79,7 +79,7 @@ def __init__(
# The Request Body
self.content: Optional[bytes] = None

def configure(self, request_configuration: RequestConfiguration) -> None:
def configure(self, request_configuration: Optional[RequestConfiguration]) -> None:
"""Configures the current request information headers, query parameters, and options
based on the request configuration provided
Expand Down
5 changes: 2 additions & 3 deletions packages/abstractions/kiota_abstractions/response_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ class ResponseHandler(ABC):

@abstractmethod
async def handle_response_async(
self, response: NativeResponseType, error_map: Optional[Dict[str,
Optional[ParsableFactory]]]
self, response: NativeResponseType, error_map: Optional[Dict[str, ParsableFactory]]
) -> Any:
"""Callback method that is invoked when a response is received.
Args:
response (NativeResponseType): The type of the native response object.
error_map (Optional[Dict[str, Optional[ParsableFactory]]]): the error dict to use
error_map (Optional[Dict[str, ParsableFactory]]]): the error dict to use
in case of a failed request.
Returns:
Any: The deserialized response.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from abc import abstractmethod
from typing import Optional
from typing import Generic, Optional, TypeVar

from .parsable import Parsable
from .parse_node import ParseNode

U = TypeVar("U", bound=Parsable)

class ParsableFactory(Parsable):

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

@staticmethod
@abstractmethod
def create_from_discriminator_value(parse_node: Optional[ParseNode]) -> Parsable:
def create_from_discriminator_value(parse_node: Optional[ParseNode]) -> U:
"""Create a new parsable object from the given serialized data.
Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .parsable import Parsable

T = TypeVar("T")
T = TypeVar("T", bool, str, int, float, UUID, datetime, timedelta, date, time, bytes)

U = TypeVar("U", bound=Parsable)

Expand All @@ -25,7 +25,7 @@ class ParseNode(ABC):
"""

@abstractmethod
def get_str_value(self) -> str:
def get_str_value(self) -> Optional[str]:
"""Gets the string value of the node
Returns:
Expand All @@ -34,7 +34,7 @@ def get_str_value(self) -> str:
pass

@abstractmethod
def get_child_node(self, identifier: str) -> ParseNode:
def get_child_node(self, identifier: str) -> Optional[ParseNode]:
"""Gets a new parse node for the given identifier
Args:
Expand Down Expand Up @@ -118,16 +118,17 @@ def get_time_value(self) -> Optional[time]:
pass

@abstractmethod
def get_collection_of_primitive_values(self) -> List[T]:
def get_collection_of_primitive_values(self, primitive_type) -> Optional[List[T]]:
"""Gets the collection of primitive values of the node
Args:
primitive_type: The type of primitive to return.
Returns:
List[T]: The collection of primitive values
"""
pass

@abstractmethod
def get_collection_of_object_values(self, factory: ParsableFactory) -> List[U]:
def get_collection_of_object_values(self, factory: ParsableFactory) -> 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.
Expand All @@ -137,7 +138,7 @@ def get_collection_of_object_values(self, factory: ParsableFactory) -> List[U]:
pass

@abstractmethod
def get_collection_of_enum_values(self) -> List[K]:
def get_collection_of_enum_values(self, enum_class: K) -> List[Optional[K]]:
"""Gets the collection of enum values of the node
Returns:
Expand All @@ -146,7 +147,7 @@ def get_collection_of_enum_values(self) -> List[K]:
pass

@abstractmethod
def get_enum_value(self) -> Enum:
def get_enum_value(self, enum_class: K) -> Optional[K]:
"""Gets the enum value of the node
Returns:
Expand All @@ -155,17 +156,17 @@ def get_enum_value(self) -> Enum:
pass

@abstractmethod
def get_object_value(self, factory: ParsableFactory) -> Parsable:
def get_object_value(self, factory: ParsableFactory[U]) -> U:
"""Gets the model object value of the node
Args:
factory (ParsableFactory): The factory to use to create the model object.
Returns:
Parsable: The model object value of the node
U: The model object value of the node
"""
pass

@abstractmethod
def get_bytes_value(self) -> bytes:
def get_bytes_value(self) -> Optional[bytes]:
"""Get a bytes value from the nodes
Returns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def write_collection_of_enum_values(
pass

@abstractmethod
def write_bytes_value(self, key: Optional[str], value: bytes) -> None:
def write_bytes_value(self, key: Optional[str], value: Optional[bytes]) -> None:
"""Writes the specified byte array as a base64 string to the stream with an optional
given key.
Expand All @@ -157,7 +157,7 @@ def write_bytes_value(self, key: Optional[str], value: bytes) -> None:

@abstractmethod
def write_object_value(
self, key: Optional[str], value: U, additional_values_to_merge: Optional[List[U]]
self, key: Optional[str], value: Optional[U], *additional_values_to_merge: Optional[List[U]]
) -> None:
"""Writes the specified model object to the stream with an optional given key.
Expand Down
Loading

0 comments on commit 2227122

Please sign in to comment.