Skip to content

Commit a74db55

Browse files
fix(python): update deserialization templates and typing issues (generated)
algolia/api-clients-automation#3780 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 19f8d7e commit a74db55

File tree

506 files changed

+11395
-19530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

506 files changed

+11395
-19530
lines changed

algoliasearch/abtesting/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
from urllib.parse import quote
1313

1414
from pydantic import Field, StrictInt, StrictStr
15+
from typing_extensions import Annotated
1516

1617
if version_info >= (3, 11):
17-
from typing import Annotated, Self
18+
from typing import Self
1819
else:
19-
from typing_extensions import Annotated, Self
20+
from typing_extensions import Self
2021

2122
from algoliasearch.abtesting.config import AbtestingConfig
2223
from algoliasearch.abtesting.models.ab_test import ABTest

algoliasearch/abtesting/models/ab_test.py

Lines changed: 42 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
from json import loads
1010
from sys import version_info
11-
from typing import Any, Dict, List, Optional, Union
11+
from typing import Any, Dict, List, Optional
1212

13-
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
13+
from pydantic import BaseModel, ConfigDict, Field
1414

1515
if version_info >= (3, 11):
1616
from typing import Self
@@ -28,113 +28,78 @@ class ABTest(BaseModel):
2828
ABTest
2929
"""
3030

31-
ab_test_id: StrictInt = Field(
32-
description="Unique A/B test identifier.", alias="abTestID"
33-
)
34-
click_significance: Optional[Union[StrictFloat, StrictInt]] = Field(
35-
default=None, alias="clickSignificance"
36-
)
37-
conversion_significance: Optional[Union[StrictFloat, StrictInt]] = Field(
31+
ab_test_id: int = Field(alias="abTestID")
32+
""" Unique A/B test identifier. """
33+
click_significance: Optional[float] = Field(default=None, alias="clickSignificance")
34+
conversion_significance: Optional[float] = Field(
3835
default=None, alias="conversionSignificance"
3936
)
40-
add_to_cart_significance: Optional[Union[StrictFloat, StrictInt]] = Field(
37+
add_to_cart_significance: Optional[float] = Field(
4138
default=None, alias="addToCartSignificance"
4239
)
43-
purchase_significance: Optional[Union[StrictFloat, StrictInt]] = Field(
40+
purchase_significance: Optional[float] = Field(
4441
default=None, alias="purchaseSignificance"
4542
)
46-
revenue_significance: Optional[Dict[str, Union[StrictFloat, StrictInt]]] = Field(
43+
revenue_significance: Optional[Dict[str, float]] = Field(
4744
default=None, alias="revenueSignificance"
4845
)
49-
updated_at: StrictStr = Field(
50-
description="Date and time when the A/B test was last updated, in RFC 3339 format.",
51-
alias="updatedAt",
52-
)
53-
created_at: StrictStr = Field(
54-
description="Date and time when the A/B test was created, in RFC 3339 format.",
55-
alias="createdAt",
56-
)
57-
end_at: StrictStr = Field(
58-
description="End date and time of the A/B test, in RFC 3339 format.",
59-
alias="endAt",
60-
)
61-
name: StrictStr = Field(description="A/B test name.")
62-
status: Status
63-
variants: List[Variant] = Field(
64-
description="A/B test variants. The first variant is your _control_ index, typically your production index. The second variant is an index with changed settings that you want to test against the control. "
46+
updated_at: str = Field(alias="updatedAt")
47+
""" Date and time when the A/B test was last updated, in RFC 3339 format. """
48+
created_at: str = Field(alias="createdAt")
49+
""" Date and time when the A/B test was created, in RFC 3339 format. """
50+
end_at: str = Field(alias="endAt")
51+
""" End date and time of the A/B test, in RFC 3339 format. """
52+
name: str = Field(alias="name")
53+
""" A/B test name. """
54+
status: Status = Field(alias="status")
55+
variants: List[Variant] = Field(alias="variants")
56+
""" A/B test variants. The first variant is your _control_ index, typically your production index. The second variant is an index with changed settings that you want to test against the control. """
57+
configuration: Optional[ABTestConfiguration] = Field(
58+
default=None, alias="configuration"
6559
)
66-
configuration: Optional[ABTestConfiguration] = None
6760

6861
model_config = ConfigDict(
69-
use_enum_values=True, populate_by_name=True, validate_assignment=True
62+
use_enum_values=True,
63+
populate_by_name=True,
64+
validate_assignment=True,
65+
protected_namespaces=(),
7066
)
7167

7268
def to_json(self) -> str:
7369
return self.model_dump_json(by_alias=True, exclude_unset=True)
7470

7571
@classmethod
76-
def from_json(cls, json_str: str) -> Self:
72+
def from_json(cls, json_str: str) -> Optional[Self]:
7773
"""Create an instance of ABTest from a JSON string"""
7874
return cls.from_dict(loads(json_str))
7975

8076
def to_dict(self) -> Dict[str, Any]:
81-
"""Return the dictionary representation of the model using alias.
82-
83-
This has the following differences from calling pydantic's
84-
`self.model_dump(by_alias=True)`:
85-
86-
* `None` is only added to the output dict for nullable fields that
87-
were set at model initialization. Other fields with value `None`
88-
are ignored.
89-
"""
90-
_dict = self.model_dump(
77+
"""Return the dictionary representation of the model using alias."""
78+
return self.model_dump(
9179
by_alias=True,
92-
exclude={},
9380
exclude_none=True,
9481
exclude_unset=True,
9582
)
96-
_items = []
97-
if self.variants:
98-
for _item in self.variants:
99-
if _item:
100-
_items.append(_item.to_dict())
101-
_dict["variants"] = _items
102-
if self.configuration:
103-
_dict["configuration"] = self.configuration.to_dict()
104-
return _dict
10583

10684
@classmethod
107-
def from_dict(cls, obj: Dict) -> Self:
85+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
10886
"""Create an instance of ABTest from a dict"""
10987
if obj is None:
11088
return None
11189

11290
if not isinstance(obj, dict):
11391
return cls.model_validate(obj)
11492

115-
_obj = cls.model_validate(
116-
{
117-
"abTestID": obj.get("abTestID"),
118-
"clickSignificance": obj.get("clickSignificance"),
119-
"conversionSignificance": obj.get("conversionSignificance"),
120-
"addToCartSignificance": obj.get("addToCartSignificance"),
121-
"purchaseSignificance": obj.get("purchaseSignificance"),
122-
"revenueSignificance": obj.get("revenueSignificance"),
123-
"updatedAt": obj.get("updatedAt"),
124-
"createdAt": obj.get("createdAt"),
125-
"endAt": obj.get("endAt"),
126-
"name": obj.get("name"),
127-
"status": obj.get("status"),
128-
"variants": (
129-
[Variant.from_dict(_item) for _item in obj.get("variants")]
130-
if obj.get("variants") is not None
131-
else None
132-
),
133-
"configuration": (
134-
ABTestConfiguration.from_dict(obj.get("configuration"))
135-
if obj.get("configuration") is not None
136-
else None
137-
),
138-
}
93+
obj["status"] = obj.get("status")
94+
obj["variants"] = (
95+
[Variant.from_dict(_item) for _item in obj["variants"]]
96+
if obj.get("variants") is not None
97+
else None
13998
)
140-
return _obj
99+
obj["configuration"] = (
100+
ABTestConfiguration.from_dict(obj["configuration"])
101+
if obj.get("configuration") is not None
102+
else None
103+
)
104+
105+
return cls.model_validate(obj)

algoliasearch/abtesting/models/ab_test_configuration.py

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,76 +30,58 @@ class ABTestConfiguration(BaseModel):
3030
A/B test configuration.
3131
"""
3232

33-
outliers: Outliers
33+
outliers: Outliers = Field(alias="outliers")
3434
empty_search: Optional[EmptySearch] = Field(default=None, alias="emptySearch")
3535
minimum_detectable_effect: Optional[MinimumDetectableEffect] = Field(
3636
default=None, alias="minimumDetectableEffect"
3737
)
3838

3939
model_config = ConfigDict(
40-
use_enum_values=True, populate_by_name=True, validate_assignment=True
40+
use_enum_values=True,
41+
populate_by_name=True,
42+
validate_assignment=True,
43+
protected_namespaces=(),
4144
)
4245

4346
def to_json(self) -> str:
4447
return self.model_dump_json(by_alias=True, exclude_unset=True)
4548

4649
@classmethod
47-
def from_json(cls, json_str: str) -> Self:
50+
def from_json(cls, json_str: str) -> Optional[Self]:
4851
"""Create an instance of ABTestConfiguration from a JSON string"""
4952
return cls.from_dict(loads(json_str))
5053

5154
def to_dict(self) -> Dict[str, Any]:
52-
"""Return the dictionary representation of the model using alias.
53-
54-
This has the following differences from calling pydantic's
55-
`self.model_dump(by_alias=True)`:
56-
57-
* `None` is only added to the output dict for nullable fields that
58-
were set at model initialization. Other fields with value `None`
59-
are ignored.
60-
"""
61-
_dict = self.model_dump(
55+
"""Return the dictionary representation of the model using alias."""
56+
return self.model_dump(
6257
by_alias=True,
63-
exclude={},
6458
exclude_none=True,
6559
exclude_unset=True,
6660
)
67-
if self.outliers:
68-
_dict["outliers"] = self.outliers.to_dict()
69-
if self.empty_search:
70-
_dict["emptySearch"] = self.empty_search.to_dict()
71-
if self.minimum_detectable_effect:
72-
_dict["minimumDetectableEffect"] = self.minimum_detectable_effect.to_dict()
73-
return _dict
7461

7562
@classmethod
76-
def from_dict(cls, obj: Dict) -> Self:
63+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
7764
"""Create an instance of ABTestConfiguration from a dict"""
7865
if obj is None:
7966
return None
8067

8168
if not isinstance(obj, dict):
8269
return cls.model_validate(obj)
8370

84-
_obj = cls.model_validate(
85-
{
86-
"outliers": (
87-
Outliers.from_dict(obj.get("outliers"))
88-
if obj.get("outliers") is not None
89-
else None
90-
),
91-
"emptySearch": (
92-
EmptySearch.from_dict(obj.get("emptySearch"))
93-
if obj.get("emptySearch") is not None
94-
else None
95-
),
96-
"minimumDetectableEffect": (
97-
MinimumDetectableEffect.from_dict(
98-
obj.get("minimumDetectableEffect")
99-
)
100-
if obj.get("minimumDetectableEffect") is not None
101-
else None
102-
),
103-
}
71+
obj["outliers"] = (
72+
Outliers.from_dict(obj["outliers"])
73+
if obj.get("outliers") is not None
74+
else None
75+
)
76+
obj["emptySearch"] = (
77+
EmptySearch.from_dict(obj["emptySearch"])
78+
if obj.get("emptySearch") is not None
79+
else None
10480
)
105-
return _obj
81+
obj["minimumDetectableEffect"] = (
82+
MinimumDetectableEffect.from_dict(obj["minimumDetectableEffect"])
83+
if obj.get("minimumDetectableEffect") is not None
84+
else None
85+
)
86+
87+
return cls.model_validate(obj)

algoliasearch/abtesting/models/ab_test_response.py

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
from json import loads
1010
from sys import version_info
11-
from typing import Any, Dict
11+
from typing import Any, Dict, Optional
1212

13-
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
13+
from pydantic import BaseModel, ConfigDict, Field
1414

1515
if version_info >= (3, 11):
1616
from typing import Self
@@ -23,61 +23,43 @@ class ABTestResponse(BaseModel):
2323
ABTestResponse
2424
"""
2525

26-
index: StrictStr = Field(
27-
description="Index name of the A/B test variant (case-sensitive)."
28-
)
29-
ab_test_id: StrictInt = Field(
30-
description="Unique A/B test identifier.", alias="abTestID"
31-
)
32-
task_id: StrictInt = Field(
33-
description="Unique identifier of a task. A successful API response means that a task was added to a queue. It might not run immediately. You can check the task's progress with the [`task` operation](#tag/Indices/operation/getTask) and this `taskID`. ",
34-
alias="taskID",
35-
)
26+
index: str = Field(alias="index")
27+
""" Index name of the A/B test variant (case-sensitive). """
28+
ab_test_id: int = Field(alias="abTestID")
29+
""" Unique A/B test identifier. """
30+
task_id: int = Field(alias="taskID")
31+
""" Unique identifier of a task. A successful API response means that a task was added to a queue. It might not run immediately. You can check the task's progress with the [`task` operation](#tag/Indices/operation/getTask) and this `taskID`. """
3632

3733
model_config = ConfigDict(
38-
use_enum_values=True, populate_by_name=True, validate_assignment=True
34+
use_enum_values=True,
35+
populate_by_name=True,
36+
validate_assignment=True,
37+
protected_namespaces=(),
3938
)
4039

4140
def to_json(self) -> str:
4241
return self.model_dump_json(by_alias=True, exclude_unset=True)
4342

4443
@classmethod
45-
def from_json(cls, json_str: str) -> Self:
44+
def from_json(cls, json_str: str) -> Optional[Self]:
4645
"""Create an instance of ABTestResponse from a JSON string"""
4746
return cls.from_dict(loads(json_str))
4847

4948
def to_dict(self) -> Dict[str, Any]:
50-
"""Return the dictionary representation of the model using alias.
51-
52-
This has the following differences from calling pydantic's
53-
`self.model_dump(by_alias=True)`:
54-
55-
* `None` is only added to the output dict for nullable fields that
56-
were set at model initialization. Other fields with value `None`
57-
are ignored.
58-
"""
59-
_dict = self.model_dump(
49+
"""Return the dictionary representation of the model using alias."""
50+
return self.model_dump(
6051
by_alias=True,
61-
exclude={},
6252
exclude_none=True,
6353
exclude_unset=True,
6454
)
65-
return _dict
6655

6756
@classmethod
68-
def from_dict(cls, obj: Dict) -> Self:
57+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
6958
"""Create an instance of ABTestResponse from a dict"""
7059
if obj is None:
7160
return None
7261

7362
if not isinstance(obj, dict):
7463
return cls.model_validate(obj)
7564

76-
_obj = cls.model_validate(
77-
{
78-
"index": obj.get("index"),
79-
"abTestID": obj.get("abTestID"),
80-
"taskID": obj.get("taskID"),
81-
}
82-
)
83-
return _obj
65+
return cls.model_validate(obj)

0 commit comments

Comments
 (0)