forked from microsoft/kiota-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs microsoft#285 Add support for untyped nodes.
- Loading branch information
1 parent
e3c80bb
commit 6b4768b
Showing
9 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from .untyped_node import UntypedNode | ||
|
||
class UntypedBoolean(UntypedNode): | ||
""" | ||
Represents an untyped node with boolean value. | ||
""" | ||
|
||
def __init__(self, value: bool) -> None: | ||
""" | ||
Creates a new instance of UntypedBoolean. | ||
Args: | ||
value (bool): The boolean value associated with the node. | ||
""" | ||
self.__value = value | ||
|
||
def get_value(self) -> bool: | ||
""" | ||
Gets the value associated with untyped boolean node. | ||
Returns: | ||
The value associated with untyped boolean node. | ||
""" | ||
return self.__value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from .untyped_node import UntypedNode | ||
|
||
class UntypedDictionary(UntypedNode): | ||
""" | ||
Represents an untyped node with dictionary value. | ||
""" | ||
|
||
def __init__(self, value: dict) -> None: | ||
""" | ||
Creates a new instance of UntypedDictionary. | ||
Args: | ||
value (dict): The key-value pair associated with the node. | ||
""" | ||
self.__value = value | ||
|
||
def get_value(self) -> dict: | ||
""" | ||
Gets the value associated with untyped dictionary node. | ||
Returns: | ||
The value associated with untyped dictionary node. | ||
""" | ||
return self.__value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from .untyped_node import UntypedNode | ||
|
||
class UntypedFloat(UntypedNode): | ||
""" | ||
Represents an untyped node with float value. | ||
""" | ||
|
||
def __init__(self, value: float) -> None: | ||
""" | ||
Creates a new instance of UntypedFloat. | ||
Args: | ||
value (bool): The float value associated with the node. | ||
""" | ||
self.__value = value | ||
|
||
def get_value(self) -> float: | ||
""" | ||
Gets the value associated with untyped float node. | ||
Returns: | ||
The value associated with untyped float node. | ||
""" | ||
return self.__value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from .untyped_node import UntypedNode | ||
|
||
class UntypedInteger(UntypedNode): | ||
""" | ||
Represents an untyped node with integer value. | ||
""" | ||
|
||
def __init__(self, value: int) -> None: | ||
""" | ||
Creates a new instance of UntypedInteger. | ||
Args: | ||
value (bool): The integer value associated with the node. | ||
""" | ||
self.__value = value | ||
|
||
def get_value(self) -> int: | ||
""" | ||
Gets the value associated with untyped integer node. | ||
Returns: | ||
The value associated with untyped integer node. | ||
""" | ||
return self.__value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from .untyped_node import UntypedNode | ||
|
||
class UntypedList(UntypedNode): | ||
""" | ||
Represents an untyped node with list value. | ||
""" | ||
|
||
def __init__(self, value: list) -> None: | ||
""" | ||
Creates a new instance of UntypedList. | ||
Args: | ||
value (bool): The list value associated with the node. | ||
""" | ||
self.__value = value | ||
|
||
def get_value(self) -> list: | ||
""" | ||
Gets the value associated with untyped list node. | ||
Returns: | ||
The value associated with untyped list node. | ||
""" | ||
return self.__value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from collections import defaultdict | ||
from parsable import Parsable | ||
from typing import TYPE_CHECKING, Callable, Dict | ||
|
||
if TYPE_CHECKING: | ||
from .parse_node import ParseNode | ||
from .serialization_writer import SerializationWriter | ||
|
||
class UntypedNode(Parsable): | ||
""" | ||
Base class for untyped node. | ||
""" | ||
|
||
__field_deserializers: Dict[str, Callable[['ParseNode'], None]] = {} | ||
|
||
def get_field_deserializers(self) -> Dict[str, Callable[['ParseNode'], None]]: | ||
""" | ||
The deserialization information for the current model | ||
""" | ||
return UntypedNode.__field_deserializers | ||
|
||
def serialize(self, writer: 'SerializationWriter'): | ||
""" | ||
Serializes information about the current object. | ||
Args: | ||
writer (SerializationWriter): Serialization writer to use to serialize this model. | ||
""" | ||
if not writer: | ||
raise ValueError("writer cannot be None") | ||
|
||
@staticmethod | ||
def create_from_discriminator_value(parse_node: 'Parsable'): | ||
""" | ||
Creates a new instance of the appropriate class based on discriminator value | ||
Args: | ||
parse_node (ParseNode): The parse node to use to read the discriminator value and create the object | ||
""" | ||
if not parse_node: | ||
raise ValueError("parse_node cannot be None") | ||
return UntypedNode() | ||
|
||
def get_value(self): | ||
""" | ||
Gets the value of the current node. | ||
Returns: | ||
The value assigned to untyped node. | ||
""" | ||
raise NotImplementedError("This method is not implemented") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .untyped_node import UntypedNode | ||
|
||
class UntypedNone(UntypedNode): | ||
""" | ||
Represents an untyped node with none value. | ||
""" | ||
|
||
def get_value(self) -> None: | ||
""" | ||
Gets the value associated with untyped none node. | ||
Returns: | ||
The value associated with untyped none node. | ||
""" | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from .untyped_node import UntypedNode | ||
|
||
class UntypedString(UntypedNode): | ||
""" | ||
Represents an untyped node with string value. | ||
""" | ||
|
||
def __init__(self, value: str) -> None: | ||
""" | ||
Creates a new instance of UntypedStr. | ||
Args: | ||
value (bool): The string value associated with the node. | ||
""" | ||
self.__value = value | ||
|
||
def get_value(self) -> str: | ||
""" | ||
Gets the value associated with untyped string node. | ||
Returns: | ||
The value associated with untyped string node. | ||
""" | ||
return self.__value |