Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 42830db

Browse files
upgrade to pydantic 2.3 (FF-957) (#24)
* upgrade to pydantic 2.3 (FF-957) * remove unused import * fix revert * replace to_camel custom code with pydantic alias generator * setup.cfg? * version 1.3.0
1 parent ee0690c commit 42830db

File tree

11 files changed

+45
-50
lines changed

11 files changed

+45
-50
lines changed

eppo_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from eppo_client.http_client import HttpClient, SdkParams
1111
from eppo_client.read_write_lock import ReadWriteLock
1212

13-
__version__ = "1.2.3"
13+
__version__ = "1.3.0"
1414

1515
__client: Optional[EppoClient] = None
1616
__lock = ReadWriteLock()

eppo_client/assignment_logger.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from typing import Dict
2+
from eppo_client.base_model import BaseModel
3+
from pydantic import ConfigDict
24

35

4-
class AssignmentLogger:
6+
class AssignmentLogger(BaseModel):
7+
model_config = ConfigDict(arbitrary_types_allowed=True)
8+
59
def log_assignment(self, assignment_event: Dict):
610
pass

eppo_client/base_model.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
from pydantic import BaseModel
2-
3-
4-
def to_camel(s: str):
5-
words = s.split("_")
6-
if len(words) > 1:
7-
return words[0] + "".join([w.capitalize() for w in words[1:]])
8-
return words[0]
1+
from pydantic import ConfigDict, BaseModel
2+
from pydantic.alias_generators import to_camel
93

104

115
class SdkBaseModel(BaseModel):
12-
class Config:
13-
alias_generator = to_camel
14-
allow_population_by_field_name = True
6+
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)

eppo_client/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_string_assignment(
4242
subject_key, flag_key, subject_attributes, VariationType.STRING
4343
)
4444
return (
45-
assigned_variation.typedValue
45+
assigned_variation.typed_value
4646
if assigned_variation is not None
4747
else assigned_variation
4848
)
@@ -54,7 +54,7 @@ def get_numeric_assignment(
5454
subject_key, flag_key, subject_attributes, VariationType.NUMERIC
5555
)
5656
return (
57-
assigned_variation.typedValue
57+
assigned_variation.typed_value
5858
if assigned_variation is not None
5959
else assigned_variation
6060
)
@@ -66,7 +66,7 @@ def get_boolean_assignment(
6666
subject_key, flag_key, subject_attributes, VariationType.BOOLEAN
6767
)
6868
return (
69-
assigned_variation.typedValue
69+
assigned_variation.typed_value
7070
if assigned_variation is not None
7171
else assigned_variation
7272
)
@@ -78,7 +78,7 @@ def get_parsed_json_assignment(
7878
subject_key, flag_key, subject_attributes, VariationType.JSON
7979
)
8080
return (
81-
assigned_variation.typedValue
81+
assigned_variation.typed_value
8282
if assigned_variation is not None
8383
else assigned_variation
8484
)
@@ -221,7 +221,7 @@ def _get_subject_variation_override(
221221
return VariationDto(
222222
name="override",
223223
value=experiment_config.overrides[subject_hash],
224-
typedValue=experiment_config.typedOverrides[subject_hash],
224+
typed_value=experiment_config.typed_overrides[subject_hash],
225225
shard_range=ShardRange(start=0, end=10000),
226226
)
227227
return None

eppo_client/config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,3 @@ class Config(SdkBaseModel):
1111

1212
def _validate(self):
1313
validate_not_blank("api_key", self.api_key)
14-
15-
class Config:
16-
# needed for the AssignmentLogger class which is not of type SdkBaseModel
17-
arbitrary_types_allowed = True

eppo_client/configuration_requestor.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from eppo_client.configuration_store import ConfigurationStore
55
from eppo_client.http_client import HttpClient
66
from eppo_client.rules import Rule
7-
87
from eppo_client.shard import ShardRange
98

109
logger = logging.getLogger(__name__)
@@ -13,7 +12,7 @@
1312
class VariationDto(SdkBaseModel):
1413
name: str
1514
value: str
16-
typedValue: Any
15+
typed_value: Any = None
1716
shard_range: ShardRange
1817

1918

@@ -25,9 +24,9 @@ class AllocationDto(SdkBaseModel):
2524
class ExperimentConfigurationDto(SdkBaseModel):
2625
subject_shards: int
2726
enabled: bool
28-
name: Optional[str]
27+
name: Optional[str] = None
2928
overrides: Dict[str, str] = {}
30-
typedOverrides: Dict[str, Any] = {}
29+
typed_overrides: Dict[str, Any] = {}
3130
rules: List[Rule] = []
3231
allocations: Dict[str, AllocationDto]
3332

eppo_client/rules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class OperatorType(Enum):
1919
class Condition(SdkBaseModel):
2020
operator: OperatorType
2121
attribute: str
22-
value: Any
22+
value: Any = None
2323

2424

2525
class Rule(SdkBaseModel):

eppo_client/variation_type.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ def is_expected_type(
1414
cls, assigned_variation: VariationDto, expected_variation_type: str
1515
) -> bool:
1616
if expected_variation_type == cls.STRING:
17-
return isinstance(assigned_variation.typedValue, str)
17+
return isinstance(assigned_variation.typed_value, str)
1818
elif expected_variation_type == cls.NUMERIC:
19-
return isinstance(assigned_variation.typedValue, Number) and not isinstance(
20-
assigned_variation.typedValue, bool
21-
)
19+
return isinstance(
20+
assigned_variation.typed_value, Number
21+
) and not isinstance(assigned_variation.typed_value, bool)
2222
elif expected_variation_type == cls.BOOLEAN:
23-
return isinstance(assigned_variation.typedValue, bool)
23+
return isinstance(assigned_variation.typed_value, bool)
2424
elif expected_variation_type == cls.JSON:
2525
try:
2626
parsed_json = json.loads(assigned_variation.value)
27-
json.dumps(assigned_variation.typedValue)
28-
return parsed_json == assigned_variation.typedValue
27+
json.dumps(assigned_variation.typed_value)
28+
return parsed_json == assigned_variation.typed_value
2929
except (json.JSONDecodeError, TypeError):
3030
pass
3131
return False

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
pydantic==1.10.*
1+
pydantic==2.4.*
2+
pydantic-settings==2.0.*
23
requests==2.31.*
34
cachetools==5.3.*
45
types-cachetools==5.3.*

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ packages = eppo_client
1919
python_requires = >=3.6
2020
include_package_data=True
2121
install_requires =
22-
pydantic<2
22+
pydantic
23+
pydantic-settings
2324
requests
2425
cachetools

0 commit comments

Comments
 (0)