Skip to content

Commit aae0a8f

Browse files
committed
Implement condition __str__
1 parent c6f2b63 commit aae0a8f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

boto3/dynamodb/conditions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121

2222
ATTR_NAME_REGEX = re.compile(r'[^.\[\]]+(?![^\[]*\])')
23+
EXPR_STR_FORMAT_REGEX = re.compile(r"\{(\d+)\}")
2324

2425

2526
class ConditionBase:
@@ -60,6 +61,14 @@ def __eq__(self, other):
6061
def __ne__(self, other):
6162
return not self.__eq__(other)
6263

64+
def __str__(self) -> str:
65+
format_str = EXPR_STR_FORMAT_REGEX.sub(
66+
r"{values[\1]}", self.expression_format
67+
)
68+
return format_str.format(
69+
values=self._values, operator=self.expression_operator
70+
)
71+
6372

6473
class AttributeBase:
6574
def __init__(self, name):
@@ -133,6 +142,9 @@ def __eq__(self, other):
133142
def __ne__(self, other):
134143
return not self.__eq__(other)
135144

145+
def __str__(self) -> str:
146+
return self.name
147+
136148

137149
class ConditionAttributeBase(ConditionBase, AttributeBase):
138150
"""This base class is for conditions that can have attribute methods.

0 commit comments

Comments
 (0)