Skip to content

Commit

Permalink
refs microsoft#285 Add type constraint for constructor arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitkrsoni committed Jun 6, 2024
1 parent 3cf2a67 commit 88572f7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion kiota_abstractions/serialization/untyped_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ def __init__(self, value: bool) -> None:
Args:
value (bool): The boolean value associated with the node.
"""
if not isinstance(value, bool):
raise TypeError("Value of UntypedBoolean must be of type bool")
self.__value = value

def get_value(self) -> bool:
"""
Gets the value associated with untyped boolean node.
Expand Down
10 changes: 8 additions & 2 deletions kiota_abstractions/serialization/untyped_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ class UntypedDictionary(UntypedNode):
Represents an untyped node with dictionary value.
"""

def __init__(self, value: dict) -> None:
def __init__(self, value: dict[str:UntypedNode]) -> None:
"""
Creates a new instance of UntypedDictionary.
Args:
value (dict): The key-value pair associated with the node.
"""
if not isinstance(value, dict):
if not all(isinstance(key, str) for key in value.keys()):
raise TypeError("Keys of UntypedDictionary must be of type str")
if not all(isinstance(value, UntypedNode) for value in value.values()):
raise TypeError("Values of UntypedDictionary must be of type UntypedNode")
raise TypeError("Value of UntypedDictionary must be of type dict")
self.__value = value

def get_value(self) -> dict:
def get_value(self) -> dict[str:UntypedNode]:
"""
Gets the value associated with untyped dictionary node.
Expand Down
2 changes: 2 additions & 0 deletions kiota_abstractions/serialization/untyped_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def __init__(self, value: float) -> None:
Args:
value (bool): The float value associated with the node.
"""
if not isinstance(value, float):
raise TypeError("Value of UntypedFloat must be of type float")
self.__value = value

def get_value(self) -> float:
Expand Down
2 changes: 2 additions & 0 deletions kiota_abstractions/serialization/untyped_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def __init__(self, value: int) -> None:
Args:
value (bool): The integer value associated with the node.
"""
if not isinstance(value, int):
raise TypeError("Value of UntypedInteger must be of type int")
self.__value = value

def get_value(self) -> int:
Expand Down
4 changes: 4 additions & 0 deletions kiota_abstractions/serialization/untyped_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def __init__(self, value: list[UntypedNode]) -> None:
Args:
value (bool): The list value associated with the node.
"""
if not isinstance(value, list):
if not all(isinstance(value, UntypedNode) for value in value):
raise TypeError("Values of UntypedList must be of type UntypedNode")
raise TypeError("Value of UntypedList must be of type list")
self.__value = value

def get_value(self) -> list[UntypedNode]:
Expand Down
2 changes: 2 additions & 0 deletions kiota_abstractions/serialization/untyped_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def __init__(self, value: str) -> None:
Args:
value (bool): The string value associated with the node.
"""
if not isinstance(value, str):
raise TypeError("Value of UntypedStr must be of type str")
self.__value = value

def get_value(self) -> str:
Expand Down

0 comments on commit 88572f7

Please sign in to comment.