Skip to content

Commit 53ae508

Browse files
author
Andrew Omondi
committed
resolve typing issues.
1 parent 1f879d7 commit 53ae508

29 files changed

Lines changed: 1812 additions & 144 deletions

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ jobs:
5959
working-directory: ${{ matrix.library.path }}
6060
run: |
6161
poetry run pylint ${{ matrix.library.name }} --disable=W --rcfile=.pylintrc
62-
# - name: Static type checking with Mypy
63-
# working-directory: ${{ matrix.library.path }}
64-
# run: |
65-
# poetry run mypy ${{ matrix.library.name }} --ignore-missing-imports
62+
- name: Static type checking with Mypy
63+
working-directory: ${{ matrix.library.path }}
64+
run: |
65+
poetry run mypy ${{ matrix.library.name }}
6666
- name: Run the tests
6767
working-directory: ${{ matrix.library.path }}
6868
run: |

packages/abstractions/kiota_abstractions/base_request_builder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License.
44
# See License in the project root for license information.
55
# ------------------------------------
6-
from typing import Any, Dict, Union
6+
from typing import Any, Dict, Optional, Union
77

88
from .request_adapter import RequestAdapter
99
from .request_information import RequestInformation
@@ -14,7 +14,7 @@ class BaseRequestBuilder:
1414

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

3030
# Path parameters for the request
31-
self.path_parameters: Union[Dict[str, Any], str] = path_parameters
31+
self.path_parameters: Dict[str, Any] = path_parameters
3232
# Url template to use to build the URL for the current request builder
3333
self.url_template: str = url_template
3434
# The request adapter to use to execute the requests.

packages/abstractions/kiota_abstractions/native_response_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ class NativeResponseHandler(ResponseHandler):
1414
async def handle_response_async(
1515
self,
1616
response: NativeResponseType,
17-
error_map: Optional[Dict[str, Optional[ParsableFactory]]] = None
17+
error_map: Optional[Dict[str, ParsableFactory]] = None
1818
) -> NativeResponseType:
1919
"""Callback method that is invoked when a response is received.
2020
Args:
2121
response (NativeResponseType): The type of the native response object.
22-
error_map (Optional[Dict[str, Optional[ParsableFactory]]]): the error dict to use
22+
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use
2323
in case of a failed request.
2424
Returns:
2525
Any: The native response object.

packages/abstractions/kiota_abstractions/request_adapter.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
from abc import ABC, abstractmethod
22
from datetime import datetime
33
from io import BytesIO
4-
from typing import Dict, Generic, List, Optional, TypeVar
4+
from typing import Dict, Generic, List, Optional, TypeVar, Union
55

66
from .request_information import RequestInformation
77
from .serialization import Parsable, ParsableFactory, SerializationWriterFactory
88
from .store import BackingStoreFactory
99

10-
ResponseType = TypeVar("ResponseType", str, int, float, bool, datetime, BytesIO)
10+
ResponseType = Union[str | int | float | bool | datetime | bytes]
1111
ModelType = TypeVar("ModelType", bound=Parsable)
1212
RequestType = TypeVar("RequestType")
1313

1414

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

2121
@abstractmethod
2222
def get_serialization_writer_factory(self) -> SerializationWriterFactory:
@@ -30,8 +30,8 @@ def get_serialization_writer_factory(self) -> SerializationWriterFactory:
3030

3131
@abstractmethod
3232
async def send_async(
33-
self, request_info: RequestInformation, parsable_factory: ParsableFactory,
34-
error_map: Dict[str, Optional[ParsableFactory]]
33+
self, request_info: RequestInformation, parsable_factory: ParsableFactory[ModelType],
34+
error_map: Optional[Dict[str, ParsableFactory]]
3535
) -> Optional[ModelType]:
3636
"""Excutes the HTTP request specified by the given RequestInformation and returns the
3737
deserialized response model.
@@ -40,7 +40,7 @@ async def send_async(
4040
request_info (RequestInformation): the request info to execute.
4141
parsable_factory (ParsableFactory): the class of response model to
4242
deserialize the response into.
43-
error_map (Dict[str, Optional[ParsableFactory]]): the error dict to use in case
43+
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in case
4444
of a failed request.
4545
4646
Returns:
@@ -53,7 +53,7 @@ async def send_collection_async(
5353
self,
5454
request_info: RequestInformation,
5555
parsable_factory: ParsableFactory,
56-
error_map: Dict[str, Optional[ParsableFactory]],
56+
error_map: Optional[Dict[str, ParsableFactory]],
5757
) -> Optional[List[ModelType]]:
5858
"""Excutes the HTTP request specified by the given RequestInformation and returns the
5959
deserialized response model collection.
@@ -62,7 +62,7 @@ async def send_collection_async(
6262
request_info (RequestInformation): the request info to execute.
6363
parsable_factory (ParsableFactory): the class of response model to
6464
deserialize the response into.
65-
error_map (Dict[str, Optional[ParsableFactory]]): the error dict to use in
65+
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
6666
case of a failed request.
6767
6868
Returns:
@@ -75,7 +75,7 @@ async def send_collection_of_primitive_async(
7575
self,
7676
request_info: RequestInformation,
7777
response_type: ResponseType,
78-
error_map: Dict[str, Optional[ParsableFactory]],
78+
error_map: Optional[Dict[str, ParsableFactory]],
7979
) -> Optional[List[ResponseType]]:
8080
"""Excutes the HTTP request specified by the given RequestInformation and returns the
8181
deserialized response model collection.
@@ -84,7 +84,7 @@ async def send_collection_of_primitive_async(
8484
request_info (RequestInformation): the request info to execute.
8585
response_type (ResponseType): the class of the response model to deserialize the
8686
response into.
87-
error_map (Dict[str, Optional[ParsableFactory]]): the error dict to use in
87+
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
8888
case of a failed request.
8989
9090
Returns:
@@ -94,17 +94,17 @@ async def send_collection_of_primitive_async(
9494

9595
@abstractmethod
9696
async def send_primitive_async(
97-
self, request_info: RequestInformation, response_type: ResponseType,
98-
error_map: Dict[str, Optional[ParsableFactory]]
97+
self, request_info: RequestInformation, response_type: str,
98+
error_map: Optional[Dict[str, ParsableFactory]]
9999
) -> Optional[ResponseType]:
100100
"""Excutes the HTTP request specified by the given RequestInformation and returns the
101101
deserialized primitive response model.
102102
103103
Args:
104104
request_info (RequestInformation): the request info to execute.
105-
response_type (ResponseType): the class of the response model to deserialize the
105+
response_type (str): the class name of the response model to deserialize the
106106
response into.
107-
error_map (Dict[str, Optional[ParsableFactory]]): the error dict to use in
107+
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
108108
case of a failed request.
109109
110110
Returns:
@@ -114,14 +114,14 @@ async def send_primitive_async(
114114

115115
@abstractmethod
116116
async def send_no_response_content_async(
117-
self, request_info: RequestInformation, error_map: Dict[str, Optional[ParsableFactory]]
117+
self, request_info: RequestInformation, error_map: Optional[Dict[str, ParsableFactory]]
118118
) -> None:
119119
"""Excutes the HTTP request specified by the given RequestInformation and returns the
120120
deserialized primitive response model.
121121
122122
Args:
123123
request_info (RequestInformation):the request info to execute.
124-
error_map (Dict[str, Optional[Optional[ParsableFactory]]): the error dict to use in
124+
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
125125
case of a failed request.
126126
"""
127127
pass

packages/abstractions/kiota_abstractions/request_information.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(
7979
# The Request Body
8080
self.content: Optional[bytes] = None
8181

82-
def configure(self, request_configuration: RequestConfiguration) -> None:
82+
def configure(self, request_configuration: Optional[RequestConfiguration]) -> None:
8383
"""Configures the current request information headers, query parameters, and options
8484
based on the request configuration provided
8585

packages/abstractions/kiota_abstractions/response_handler.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ class ResponseHandler(ABC):
1313

1414
@abstractmethod
1515
async def handle_response_async(
16-
self, response: NativeResponseType, error_map: Optional[Dict[str,
17-
Optional[ParsableFactory]]]
16+
self, response: NativeResponseType, error_map: Optional[Dict[str, ParsableFactory]]
1817
) -> Any:
1918
"""Callback method that is invoked when a response is received.
2019
Args:
2120
response (NativeResponseType): The type of the native response object.
22-
error_map (Optional[Dict[str, Optional[ParsableFactory]]]): the error dict to use
21+
error_map (Optional[Dict[str, ParsableFactory]]]): the error dict to use
2322
in case of a failed request.
2423
Returns:
2524
Any: The deserialized response.

packages/abstractions/kiota_abstractions/serialization/parsable_factory.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
from abc import abstractmethod
2-
from typing import Optional
2+
from typing import Generic, Optional, TypeVar
33

44
from .parsable import Parsable
55
from .parse_node import ParseNode
66

7+
U = TypeVar("U", bound=Parsable)
78

8-
class ParsableFactory(Parsable):
9+
10+
class ParsableFactory(Generic[U]):
911
"""Defines the factory for creating parsable objects.
1012
"""
1113

1214
@staticmethod
1315
@abstractmethod
14-
def create_from_discriminator_value(parse_node: Optional[ParseNode]) -> Parsable:
16+
def create_from_discriminator_value(parse_node: Optional[ParseNode]) -> U:
1517
"""Create a new parsable object from the given serialized data.
1618
1719
Args:

packages/abstractions/kiota_abstractions/serialization/parse_node.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from .parsable import Parsable
1010

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

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

@@ -25,7 +25,7 @@ class ParseNode(ABC):
2525
"""
2626

2727
@abstractmethod
28-
def get_str_value(self) -> str:
28+
def get_str_value(self) -> Optional[str]:
2929
"""Gets the string value of the node
3030
3131
Returns:
@@ -34,7 +34,7 @@ def get_str_value(self) -> str:
3434
pass
3535

3636
@abstractmethod
37-
def get_child_node(self, identifier: str) -> ParseNode:
37+
def get_child_node(self, identifier: str) -> Optional[ParseNode]:
3838
"""Gets a new parse node for the given identifier
3939
4040
Args:
@@ -118,16 +118,17 @@ def get_time_value(self) -> Optional[time]:
118118
pass
119119

120120
@abstractmethod
121-
def get_collection_of_primitive_values(self) -> List[T]:
121+
def get_collection_of_primitive_values(self, primitive_type) -> Optional[List[T]]:
122122
"""Gets the collection of primitive values of the node
123-
123+
Args:
124+
primitive_type: The type of primitive to return.
124125
Returns:
125126
List[T]: The collection of primitive values
126127
"""
127128
pass
128129

129130
@abstractmethod
130-
def get_collection_of_object_values(self, factory: ParsableFactory) -> List[U]:
131+
def get_collection_of_object_values(self, factory: ParsableFactory) -> Optional[List[U]]:
131132
"""Gets the collection of model object values of the node
132133
Args:
133134
factory (ParsableFactory): The factory to use to create the model object.
@@ -137,7 +138,7 @@ def get_collection_of_object_values(self, factory: ParsableFactory) -> List[U]:
137138
pass
138139

139140
@abstractmethod
140-
def get_collection_of_enum_values(self) -> List[K]:
141+
def get_collection_of_enum_values(self, enum_class: K) -> List[Optional[K]]:
141142
"""Gets the collection of enum values of the node
142143
143144
Returns:
@@ -146,7 +147,7 @@ def get_collection_of_enum_values(self) -> List[K]:
146147
pass
147148

148149
@abstractmethod
149-
def get_enum_value(self) -> Enum:
150+
def get_enum_value(self, enum_class: K) -> Optional[K]:
150151
"""Gets the enum value of the node
151152
152153
Returns:
@@ -155,17 +156,17 @@ def get_enum_value(self) -> Enum:
155156
pass
156157

157158
@abstractmethod
158-
def get_object_value(self, factory: ParsableFactory) -> Parsable:
159+
def get_object_value(self, factory: ParsableFactory[U]) -> U:
159160
"""Gets the model object value of the node
160161
Args:
161162
factory (ParsableFactory): The factory to use to create the model object.
162163
Returns:
163-
Parsable: The model object value of the node
164+
U: The model object value of the node
164165
"""
165166
pass
166167

167168
@abstractmethod
168-
def get_bytes_value(self) -> bytes:
169+
def get_bytes_value(self) -> Optional[bytes]:
169170
"""Get a bytes value from the nodes
170171
171172
Returns:

packages/abstractions/kiota_abstractions/serialization/serialization_writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def write_collection_of_enum_values(
145145
pass
146146

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

158158
@abstractmethod
159159
def write_object_value(
160-
self, key: Optional[str], value: U, additional_values_to_merge: Optional[List[U]]
160+
self, key: Optional[str], value: Optional[U], *additional_values_to_merge: Optional[List[U]]
161161
) -> None:
162162
"""Writes the specified model object to the stream with an optional given key.
163163

0 commit comments

Comments
 (0)