|
9 | 9 | Classes: |
10 | 10 | PageResult: Represents a page of items in a paged response. |
11 | 11 | """ |
12 | | -from typing import Any, List, Optional |
| 12 | +from typing import List, Optional, Dict, Callable |
13 | 13 | from dataclasses import dataclass |
14 | 14 | from __future__ import annotations |
15 | 15 |
|
|
23 | 23 |
|
24 | 24 |
|
25 | 25 | @dataclass |
26 | | -class PageResult(Parsable, Generic[T]): |
27 | | - """ |
28 | | - Represents a page of items in a paged response. |
29 | | - """ |
30 | | - object_type: Optional[Any] = None |
| 26 | +class PageResult(Parsable): |
31 | 27 | odata_next_link: Optional[str] = None |
32 | | - value: Optional[List[T]] = None |
| 28 | + value: Optional[List[Parsable]] = None |
33 | 29 |
|
34 | 30 | @staticmethod |
35 | | - def create_from_discriminator_value(parse_node: ParseNode) -> PageResult: # pylint: disable=unused-argument |
| 31 | + def create_from_discriminator_value(parse_node: Optional[ParseNode] = None) -> PageResult: |
36 | 32 | """ |
37 | | - Creates a PageResult from a discriminator value. |
38 | | - Returns: |
39 | | - PageResult: The created PageResult. |
| 33 | + Creates a new instance of the appropriate class based on discriminator value |
| 34 | + Args: |
| 35 | + parseNode: The parse node to use to read the discriminator value and create the object |
| 36 | + Returns: Attachment |
40 | 37 | """ |
41 | | - impprt_statement = f"from msgraph.generated.models.{str(PageResult.object_type).lower()} \ |
42 | | - import {PageResult.object_type}" |
43 | | - |
44 | | - # pylint: disable=exec-used |
45 | | - exec(impprt_statement) |
46 | | - if isinstance(PageResult.object_type, str): |
47 | | - return PageResult(locals()[PageResult.object_type]) |
| 38 | + if not parse_node: |
| 39 | + raise TypeError("parse_node cannot be null") |
48 | 40 | return PageResult() |
49 | 41 |
|
50 | | - def set_value(self, value: List[Any]): |
51 | | - """ |
52 | | - Sets the items in the page. |
53 | | -
|
54 | | - Args: |
55 | | - value (List[Any]): The items to set. |
56 | | - """ |
57 | | - self.value = value |
| 42 | + def get_field_deserializers(self) -> Dict[str, Callable[[ParseNode], None]]: |
| 43 | + """Gets the deserialization information for this object. |
58 | 44 |
|
59 | | - def get_field_deserializers(self): |
60 | | - """ |
61 | | - Gets the field deserializers for the PageResult. |
62 | 45 | Returns: |
63 | | - Dict[str, Callable]: The field deserializers. |
| 46 | + Dict[str, Callable[[ParseNode], None]]: The deserialization information for this |
| 47 | + object where each entry is a property key with its deserialization callback. |
64 | 48 | """ |
65 | | - class_name = PageResult.object_type |
66 | | - # pylint: disable=not-callable |
67 | | - instance = class_name() |
68 | | - module_path = instance.__class__.__module__ |
69 | | - class_name = instance.__class__.__name__ |
70 | | - import_statement = f'from {module_path} import {class_name}' |
71 | | - # pylint: disable=exec-used |
72 | | - exec(import_statement) |
73 | | - serialization_model = locals()[class_name] |
74 | 49 | return { |
75 | | - '@odata.nextLink': |
76 | | - lambda parse_node: setattr(self, 'odata_next_link', parse_node.get_str_value()), |
77 | | - 'odata.deltaLink': |
78 | | - lambda parse_node: setattr(self, 'odata_delta_link', parse_node.get_str_value()), |
79 | | - 'value': |
80 | | - lambda parse_node: self. |
81 | | - set_value(parse_node.get_collection_of_object_values(serialization_model)) |
| 50 | + "@odata.nextLink": lambda x: setattr(self, "odata_next_link", x.get_str_value()), |
| 51 | + "value": lambda x: setattr(self, "value", x.get_collection_of_object_values(Parsable)) |
82 | 52 | } |
83 | 53 |
|
84 | 54 | def serialize(self, writer: SerializationWriter) -> None: |
85 | | - """ |
86 | | - Serializes the PageResult into a SerializationWriter. |
| 55 | + """Writes the objects properties to the current writer. |
| 56 | +
|
87 | 57 | Args: |
88 | | - writer (SerializationWriter): The writer to serialize into. |
| 58 | + writer (SerializationWriter): The writer to write to. |
89 | 59 | """ |
90 | | - writer.write_str_value('@odata.nextLink', self.odata_next_link, self.value) |
91 | | - if self.value is not None: |
92 | | - writer.write_collection_of_object_values(None, list(self.value)) |
| 60 | + if not writer: |
| 61 | + raise TypeError("Writer cannot be null") |
| 62 | + writer.write_str_value("@odata.nextLink", self.odata_next_link) |
| 63 | + writer.write_collection_of_object_values("value", self.value) |
0 commit comments