Conversation
| return False | ||
|
|
||
|
|
||
| def to_string(value: AttributeType) -> str: |
There was a problem hiding this comment.
Handle an array of strings?
There was a problem hiding this comment.
You could normalize boolean, None and arrays by converting to JSON. Just about every language has some library that can convert to JSON, so this would work for every SDK:

So the logic might be:
if isinstance(value, str):
return value
elif value.is_integer():
return str(int(value))
return json.dumps(value)
There was a problem hiding this comment.
AttributeType = Union[str, int, float, bool]
Attribute cannot be an array -- but good call that we do want to handle null.
Using json is a great suggestion, but I do want to make sure we aren't losing a lot of performance (I've seen json being very slow, but perhaps here it's sufficiently quickly given that the input is small)
There was a problem hiding this comment.
Yeah, that's a valid concern. It still might be useful as an "else" case for any value that we don't expect (sort of a cross-language toString()), while handling the cases that we expect in a more performant way, but I'm good with whatever you decide so long as we handle None / null
There was a problem hiding this comment.
it looks like they're equal because they both landed on if isinstance(value, str):. You should try it out with no conditionals -- just running the functions we want tested: (str vs json.dumps)
There was a problem hiding this comment.
But in any case, the json.dumps only happens after all other conditionals fail, so we're still good here.
greghuels
left a comment
There was a problem hiding this comment.
suggestion to use json to handle edge cases
|
@coderabbitai review |
Actions performedReview triggered.
|
WalkthroughThe recent changes in the Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant Client
participant Rules
participant TestSuite
Client->>Rules: Call evaluate_condition()
Rules->>Rules: Convert attributes using to_string()
Rules-->>Client: Return evaluation result
TestSuite->>Rules: Call to_string() with various data types
Rules-->>TestSuite: Return string representations
TestSuite->>Rules: Call evaluate_condition() with boolean values as strings
Rules-->>TestSuite: Return evaluation results
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- eppo_client/rules.py (3 hunks)
- test/rules_test.py (4 hunks)
Additional comments not posted (3)
eppo_client/rules.py (1)
52-52: Consider caching the string conversion to improve performance.
[PERFORMANCE]
In conditions likeONE_OFandNOT_ONE_OF, theto_string(subject_value)is called multiple times which can be inefficient. Consider caching the result in a variable at the start of the function to avoid repeated conversions.Also applies to: 56-56, 59-59, 63-65
test/rules_test.py (2)
409-425: Consider adding edge case tests forto_string.
[TESTS]
The current tests cover basic functionality. Consider adding tests for edge cases such as empty strings, very large numbers, and special characters to ensure robustness.
141-156: Expand testing for boolean values in conditions.
[TESTS]
The tests for boolean values are a good start, but consider adding more scenarios to cover cases where boolean values are mixed with other data types or used in complex expressions to ensure comprehensive coverage.Also applies to: 364-367
eppo_client/rules.py
Outdated
| def to_string(value: AttributeType) -> str: | ||
| if isinstance(value, str): | ||
| return value | ||
| elif isinstance(value, bool): | ||
| return "true" if value else "false" | ||
| elif isinstance(value, float): | ||
| return str(int(value)) if value.is_integer() else str(value) | ||
| return str(value) |
There was a problem hiding this comment.
Optimize float conversion in to_string.
- return str(int(value)) if value.is_integer() else str(value)
+ return f"{value:.0f}" if value.is_integer() else str(value)This change uses formatted strings to handle float to integer conversion more efficiently.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
| def to_string(value: AttributeType) -> str: | |
| if isinstance(value, str): | |
| return value | |
| elif isinstance(value, bool): | |
| return "true" if value else "false" | |
| elif isinstance(value, float): | |
| return str(int(value)) if value.is_integer() else str(value) | |
| return str(value) | |
| def to_string(value: AttributeType) -> str: | |
| if isinstance(value, str): | |
| return value | |
| elif isinstance(value, bool): | |
| return "true" if value else "false" | |
| elif isinstance(value, float): | |
| return f"{value:.0f}" if value.is_integer() else str(value) | |
| return str(value) |

labels: mergeable
Fixes: #issue
Motivation and Context
Ensure consistent conversion of subject attribute values to strings across SDKs
Description
Custom conversion from integer floats and booleans to strings
Related PR to update docs:
Eppo-exp/eppo-docs#382
How has this been tested?
Summary by CodeRabbit
New Features
Tests