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:
Frens Jan Rumph
2016-09-06 15:16:09 +02:00
committed by GitHub
parent 3998a9a2bf
commit af0b853c9b

View File

@@ -791,10 +791,13 @@ class BatchStatement(Statement):
self._maybe_set_routing_attributes(statement)
self._update_custom_payload(statement)
def __len__(self):
return len(self._statements_and_parameters)
def __str__(self):
consistency = ConsistencyLevel.value_to_name.get(self.consistency_level, 'Not Set')
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__