Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import re
from typing import Any, Optional

from .parse_node import ParseNode
from .parse_node_factory import ParseNodeFactory
Expand All @@ -11,9 +12,9 @@ class ParseNodeFactoryRegistry(ParseNodeFactory):
"""
CONTENT_TYPE_ASSOCIATED_FACTORIES: dict[str, ParseNodeFactory] = {}

__instance = None
__instance: Optional[ParseNodeFactoryRegistry] = None

def __new__(cls, *args, **kwargs):
def __new__(cls, *args: Any, **kwargs: Any) -> ParseNodeFactoryRegistry:
"""Default singleton instance of the registry to be used when registering new
factories that should be available by default.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import annotations

import re
from typing import Any, Optional

from .serialization_writer import SerializationWriter
from .serialization_writer_factory import SerializationWriterFactory
Expand All @@ -10,9 +13,9 @@ class SerializationWriterFactoryRegistry(SerializationWriterFactory):
# List of factories that are registered by content type.
CONTENT_TYPE_ASSOCIATED_FACTORIES: dict[str, SerializationWriterFactory] = {}

__instance = None
__instance: Optional[SerializationWriterFactoryRegistry] = None

def __new__(cls, *args, **kwargs):
def __new__(cls, *args: Any, **kwargs: Any) -> SerializationWriterFactoryRegistry:
"""Default singleton instance of the registry to be used when registring new
factories that should be available by default.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import inspect
from pickle import TRUE
from typing import Any, Optional, Union
from urllib.parse import urlparse
from urllib.parse import ParseResult, urlparse

from kiota_abstractions.authentication import AccessTokenProvider, AllowedHostsValidator
from opentelemetry import trace
Expand Down Expand Up @@ -34,7 +34,7 @@ class AzureIdentityAccessTokenProvider(AccessTokenProvider):
def __init__(
self,
credentials: Union["TokenCredential", "AsyncTokenCredential"],
options: Optional[dict],
options: Optional[dict[str, Any]],
scopes: list[str] = [],
allowed_hosts: list[str] = [],
is_cae_enabled: bool = True,
Expand Down Expand Up @@ -126,7 +126,7 @@ def get_allowed_hosts_validator(self) -> AllowedHostsValidator:
"""
return self._allowed_hosts_validator

def _resolve_scopes(self, parsed_url, span) -> list[str]:
def _resolve_scopes(self, parsed_url: ParseResult, span: trace.Span) -> list[str]:
"""Return the scopes to pass to `get_token` for this request.

Caller-supplied scopes are returned verbatim. Otherwise a default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Optional, Union
from typing import TYPE_CHECKING, Any, Optional, Union

from kiota_abstractions.authentication import BaseBearerTokenAuthenticationProvider

Expand All @@ -15,7 +15,7 @@ class AzureIdentityAuthenticationProvider(BaseBearerTokenAuthenticationProvider)
def __init__(
self,
credentials: Union["TokenCredential", "AsyncTokenCredential"],
options: Optional[dict] = None,
options: Optional[dict[str, Any]] = None,
scopes: list[str] = [],
allowed_hosts: list[str] = [],
is_cae_enabled: bool = True,
Expand Down
1 change: 1 addition & 0 deletions packages/authentication/azure/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ name = "kiota_authentication_azure"

[tool.mypy]
warn_unused_configs = true
strict = true
files = "kiota_authentication_azure"

[tool.yapf]
Expand Down
1 change: 1 addition & 0 deletions packages/bundle/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ name = "kiota_bundle"

[tool.mypy]
warn_unused_configs = true
strict = true
files = "kiota_bundle"

[tool.yapf]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def write_any_value(self, key: Optional[str], value: Any) -> Any:
with key {key}"
)

def _serialize_value(self, temp_writer: FormSerializationWriter, value: U):
def _serialize_value(self, temp_writer: FormSerializationWriter, value: U) -> None:
if on_before := self.on_before_object_serialization:
on_before(value)
if on_start := self.on_start_object_serialization:
Expand Down
1 change: 1 addition & 0 deletions packages/serialization/form/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ name = "kiota_serialization_form"

[tool.mypy]
warn_unused_configs = true
strict = true
files = "kiota_serialization_form"

[tool.yapf]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def get_collection_of_primitive_values(self, primitive_type: type[T]) -> Optiona
bytes: self._get_bytes_value,
}

def func(item):
def func(item: Any) -> Any:
t = primitive_type if primitive_type else type(item)
converter = converters.get(t)
if converter is None:
Expand All @@ -150,7 +150,7 @@ def get_collection_of_object_values(self, factory: ParsableFactory[U]) -> Option
if isinstance(self._json_node, list):
return list(
map(
lambda x: self._create_new_node(x).get_object_value(factory), # type: ignore
lambda x: self._create_new_node(x).get_object_value(factory),
self._json_node,
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class JsonSerializationWriter(SerializationWriter):
PROPERTY_SEPARATOR: str = ','

def __init__(self) -> None:
self.writer: dict = {}
self.writer: dict[str, Any] = {}
self.value: Any = None
self._has_root_value = False

Expand Down Expand Up @@ -515,7 +515,7 @@ def write_any_value(self, key: Optional[str], value: Any) -> Any:
f"Encountered an unknown type during serialization {type(value)} with key {key}"
)

def _serialize_value(self, temp_writer: JsonSerializationWriter, value: U):
def _serialize_value(self, temp_writer: JsonSerializationWriter, value: U) -> None:
if on_before := self.on_before_object_serialization:
on_before(value)
if on_start := self.on_start_object_serialization:
Expand Down
1 change: 1 addition & 0 deletions packages/serialization/json/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ name = "kiota_serialization_json"

[tool.mypy]
warn_unused_configs = true
strict = true
files = "kiota_serialization_json"

[tool.yapf]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def on_start_object_serialization(
"""
self._on_start_object_serialization = value

def _serialize_value(self, temp_writer: MultipartSerializationWriter, value: U):
def _serialize_value(self, temp_writer: MultipartSerializationWriter, value: U) -> None:
if on_before := self.on_before_object_serialization:
on_before(value)
if on_start := self.on_start_object_serialization:
Expand Down
1 change: 1 addition & 0 deletions packages/serialization/multipart/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ name = "kiota_serialization_multipart"

[tool.mypy]
warn_unused_configs = true
strict = true
files = "kiota_serialization_multipart"

[tool.yapf]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def __init__(self, text: str) -> None:
Args:
text (str):The text value to initialize the node with
"""
if text or text is False:
self._text = text
self._text = text

def get_str_value(self) -> Optional[str]:
"""Gets the string value from the text node
Expand All @@ -59,8 +58,8 @@ def get_bool_value(self) -> Optional[bool]:
Returns:
bool: The boolean value of the node
"""
if self._text or (self._text is False):
return bool(self._text)
if self._text:
return self._text.strip().lower() == "true"
return None

def get_int_value(self) -> Optional[int]:
Expand Down
1 change: 1 addition & 0 deletions packages/serialization/text/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ name = "kiota_serialization_text"

[tool.mypy]
warn_unused_configs = true
strict = true
files = "kiota_serialization_text"

[tool.yapf]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ def test_get_int_value():
assert result == 1454


def test_get_bool_value():
parse_node = TextParseNode(False)
@pytest.mark.parametrize("text, expected", [("true", True), ("false", False), ("True\n", True)])
def test_get_bool_value(text, expected):
parse_node = TextParseNode(text)
result = parse_node.get_bool_value()
assert result is False
assert result is expected


def test_get_float_value():
Expand Down
Loading