-
Notifications
You must be signed in to change notification settings - Fork 2
upgrade to pydantic 2.3 (FF-957) #24
Changes from all commits
bebce94
dca179b
a1b2355
767e1f5
fe3ca68
4ee89e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
from typing import Dict | ||
from eppo_client.base_model import BaseModel | ||
from pydantic import ConfigDict | ||
|
||
|
||
class AssignmentLogger: | ||
class AssignmentLogger(BaseModel): | ||
model_config = ConfigDict(arbitrary_types_allowed=True) | ||
|
||
leoromanovsky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def log_assignment(self, assignment_event: Dict): | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,6 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
def to_camel(s: str): | ||
words = s.split("_") | ||
if len(words) > 1: | ||
return words[0] + "".join([w.capitalize() for w in words[1:]]) | ||
return words[0] | ||
Comment on lines
-2
to
-8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. glad they have an official version publish! our |
||
from pydantic import ConfigDict, BaseModel | ||
from pydantic.alias_generators import to_camel | ||
|
||
|
||
class SdkBaseModel(BaseModel): | ||
class Config: | ||
alias_generator = to_camel | ||
allow_population_by_field_name = True | ||
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) | ||
Comment on lines
5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ def get_string_assignment( | |
subject_key, flag_key, subject_attributes, VariationType.STRING | ||
) | ||
return ( | ||
assigned_variation.typedValue | ||
assigned_variation.typed_value | ||
if assigned_variation is not None | ||
else assigned_variation | ||
) | ||
|
@@ -54,7 +54,7 @@ def get_numeric_assignment( | |
subject_key, flag_key, subject_attributes, VariationType.NUMERIC | ||
) | ||
return ( | ||
assigned_variation.typedValue | ||
assigned_variation.typed_value | ||
if assigned_variation is not None | ||
else assigned_variation | ||
) | ||
|
@@ -66,7 +66,7 @@ def get_boolean_assignment( | |
subject_key, flag_key, subject_attributes, VariationType.BOOLEAN | ||
) | ||
return ( | ||
assigned_variation.typedValue | ||
assigned_variation.typed_value | ||
if assigned_variation is not None | ||
else assigned_variation | ||
) | ||
|
@@ -78,7 +78,7 @@ def get_parsed_json_assignment( | |
subject_key, flag_key, subject_attributes, VariationType.JSON | ||
) | ||
return ( | ||
assigned_variation.typedValue | ||
assigned_variation.typed_value | ||
if assigned_variation is not None | ||
else assigned_variation | ||
) | ||
|
@@ -221,7 +221,7 @@ def _get_subject_variation_override( | |
return VariationDto( | ||
name="override", | ||
value=experiment_config.overrides[subject_hash], | ||
typedValue=experiment_config.typedOverrides[subject_hash], | ||
typed_value=experiment_config.typed_overrides[subject_hash], | ||
shard_range=ShardRange(start=0, end=10000), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. python classes now have snake case, as they're supposed to |
||
) | ||
return None | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
from eppo_client.configuration_store import ConfigurationStore | ||
from eppo_client.http_client import HttpClient | ||
from eppo_client.rules import Rule | ||
|
||
from eppo_client.shard import ShardRange | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -13,7 +12,7 @@ | |
class VariationDto(SdkBaseModel): | ||
name: str | ||
value: str | ||
typedValue: Any | ||
typed_value: Any = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pydantic required this |
||
shard_range: ShardRange | ||
|
||
|
||
|
@@ -25,9 +24,9 @@ class AllocationDto(SdkBaseModel): | |
class ExperimentConfigurationDto(SdkBaseModel): | ||
subject_shards: int | ||
enabled: bool | ||
name: Optional[str] | ||
name: Optional[str] = None | ||
overrides: Dict[str, str] = {} | ||
typedOverrides: Dict[str, Any] = {} | ||
typed_overrides: Dict[str, Any] = {} | ||
rules: List[Rule] = [] | ||
allocations: Dict[str, AllocationDto] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ packages = eppo_client | |
python_requires = >=3.6 | ||
include_package_data=True | ||
install_requires = | ||
pydantic<2 | ||
pydantic | ||
pydantic-settings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is there a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't know what the intention was here, but I believe the convention is about abstract vs concrete dependencies https://martin-thoma.com/python-requirements/#abstract-dependencies |
||
requests | ||
cachetools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssignmentLogger
does not inherit fromSdkBaseModel
because it has unique serialization requirements from the json dto objects