@@ -19,6 +19,7 @@ class NoneProperty(Property):
19
19
""" A property that is always None (used for empty schemas) """
20
20
21
21
_type_string : ClassVar [str ] = "None"
22
+ _json_type_string : ClassVar [str ] = "None"
22
23
template : ClassVar [Optional [str ]] = "none_property.pyi"
23
24
24
25
@@ -29,6 +30,7 @@ class StringProperty(Property):
29
30
max_length : Optional [int ] = None
30
31
pattern : Optional [str ] = None
31
32
_type_string : ClassVar [str ] = "str"
33
+ _json_type_string : ClassVar [str ] = "str"
32
34
33
35
34
36
@attr .s (auto_attribs = True , frozen = True )
@@ -38,6 +40,7 @@ class DateTimeProperty(Property):
38
40
"""
39
41
40
42
_type_string : ClassVar [str ] = "datetime.datetime"
43
+ _json_type_string : ClassVar [str ] = "str"
41
44
template : ClassVar [str ] = "datetime_property.pyi"
42
45
43
46
def get_imports (self , * , prefix : str ) -> Set [str ]:
@@ -58,6 +61,7 @@ class DateProperty(Property):
58
61
""" A property of type datetime.date """
59
62
60
63
_type_string : ClassVar [str ] = "datetime.date"
64
+ _json_type_string : ClassVar [str ] = "str"
61
65
template : ClassVar [str ] = "date_property.pyi"
62
66
63
67
def get_imports (self , * , prefix : str ) -> Set [str ]:
@@ -78,6 +82,8 @@ class FileProperty(Property):
78
82
""" A property used for uploading files """
79
83
80
84
_type_string : ClassVar [str ] = "File"
85
+ # Return type of File.to_tuple()
86
+ _json_type_string : ClassVar [str ] = "Tuple[Optional[str], Union[BinaryIO, TextIO], Optional[str]]"
81
87
template : ClassVar [str ] = "file_property.pyi"
82
88
83
89
def get_imports (self , * , prefix : str ) -> Set [str ]:
@@ -98,20 +104,23 @@ class FloatProperty(Property):
98
104
""" A property of type float """
99
105
100
106
_type_string : ClassVar [str ] = "float"
107
+ _json_type_string : ClassVar [str ] = "float"
101
108
102
109
103
110
@attr .s (auto_attribs = True , frozen = True )
104
111
class IntProperty (Property ):
105
112
""" A property of type int """
106
113
107
114
_type_string : ClassVar [str ] = "int"
115
+ _json_type_string : ClassVar [str ] = "int"
108
116
109
117
110
118
@attr .s (auto_attribs = True , frozen = True )
111
119
class BooleanProperty (Property ):
112
120
""" Property for bool """
113
121
114
122
_type_string : ClassVar [str ] = "bool"
123
+ _json_type_string : ClassVar [str ] = "bool"
115
124
116
125
117
126
InnerProp = TypeVar ("InnerProp" , bound = Property )
@@ -122,6 +131,7 @@ class ListProperty(Property, Generic[InnerProp]):
122
131
""" A property representing a list (array) of other properties """
123
132
124
133
inner_property : InnerProp
134
+ _json_type_string : ClassVar [str ] = "List[Any]"
125
135
template : ClassVar [str ] = "list_property.pyi"
126
136
127
137
def get_base_type_string (self ) -> str :
@@ -159,37 +169,38 @@ def __attrs_post_init__(self) -> None:
159
169
self , "has_properties_without_templates" , any (prop .template is None for prop in self .inner_properties )
160
170
)
161
171
162
- def _get_inner_prop_string (self ) -> str :
163
- inner_types = [p .get_type_string (no_optional = True ) for p in self .inner_properties ]
164
- return ", " .join (inner_types )
172
+ def _get_inner_prop_string (self , json : bool = False ) -> str :
173
+ inner_types = [p .get_type_string (no_optional = True , json = json ) for p in self .inner_properties ]
174
+ unique_inner_types = list (dict .fromkeys (inner_types ))
175
+ return ", " .join (unique_inner_types )
165
176
166
177
def get_base_type_string (self ) -> str :
167
178
return f"Union[{ self ._get_inner_prop_string ()} ]"
168
179
169
- def get_type_string (self , no_optional : bool = False , query_parameter : bool = False ) -> str :
180
+ def get_type_string (self , no_optional : bool = False , query_parameter : bool = False , json : bool = False ) -> str :
170
181
"""
171
182
Get a string representation of type that should be used when declaring this property.
172
183
173
184
This implementation differs slightly from `Property.get_type_string` in order to collapse
174
185
nested union types.
175
186
"""
176
- type_string = self .get_base_type_string ()
187
+ type_string = f"Union[ { self ._get_inner_prop_string ( json = json ) } ]"
177
188
if no_optional :
178
189
return type_string
179
190
if self .required :
180
191
if self .nullable :
181
- return f"Union[None, { self ._get_inner_prop_string ()} ]"
192
+ return f"Union[None, { self ._get_inner_prop_string (json = json )} ]"
182
193
else :
183
194
return type_string
184
195
else :
185
196
if self .nullable :
186
- return f"Union[Unset, None, { self ._get_inner_prop_string ()} ]"
197
+ return f"Union[Unset, None, { self ._get_inner_prop_string (json = json )} ]"
187
198
else :
188
199
if query_parameter :
189
200
# For query parameters, None has the same meaning as Unset
190
- return f"Union[Unset, None, { self ._get_inner_prop_string ()} ]"
201
+ return f"Union[Unset, None, { self ._get_inner_prop_string (json = json )} ]"
191
202
else :
192
- return f"Union[Unset, { self ._get_inner_prop_string ()} ]"
203
+ return f"Union[Unset, { self ._get_inner_prop_string (json = json )} ]"
193
204
194
205
def get_imports (self , * , prefix : str ) -> Set [str ]:
195
206
"""
0 commit comments