Add __len__ to BatchStatement
A __len__ method on BatchStatement would allow getting the length of the batch without poking around in the 'private' _statements_and_parameters field.
This commit is contained in:
@@ -791,10 +791,13 @@ class BatchStatement(Statement):
|
|||||||
self._maybe_set_routing_attributes(statement)
|
self._maybe_set_routing_attributes(statement)
|
||||||
self._update_custom_payload(statement)
|
self._update_custom_payload(statement)
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self._statements_and_parameters)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
consistency = ConsistencyLevel.value_to_name.get(self.consistency_level, 'Not Set')
|
consistency = ConsistencyLevel.value_to_name.get(self.consistency_level, 'Not Set')
|
||||||
return (u'<BatchStatement type=%s, statements=%d, consistency=%s>' %
|
return (u'<BatchStatement type=%s, statements=%d, consistency=%s>' %
|
||||||
(self.batch_type, len(self._statements_and_parameters), consistency))
|
(self.batch_type, len(self), consistency))
|
||||||
__repr__ = __str__
|
__repr__ = __str__
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user