Skip to content

Commit 680d874

Browse files
author
Axel Viala
committed
Add documentation in GtidSet class.
1 parent f80733b commit 680d874

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pymysqlreplication/gtid.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,23 @@ def __ge__(self, other):
277277

278278

279279
class GtidSet(object):
280+
"""Represents a set of Gtid"""
280281
def __init__(self, gtid_set):
282+
"""
283+
Construct a GtidSet initial state depends of the nature of `gtid_set` param.
284+
285+
params:
286+
- gtid_set:
287+
- None: then the GtidSet start empty
288+
- a set of Gtid either as a their textual representation separated by comma
289+
- A set or list of gtid
290+
- A GTID alone.
291+
292+
Raises:
293+
- ValueError: if `gtid_set` is a string separated with comma, but with malformated Gtid.
294+
- Exception: if Gtid interval are either malformated or overlapping
295+
"""
296+
281297
def _to_gtid(element):
282298
if isinstance(element, Gtid):
283299
return element
@@ -302,13 +318,25 @@ def merge_gtid(self, gtid):
302318
self.gtids = new_gtids
303319

304320
def __contains__(self, other):
321+
"""
322+
Raises:
323+
- NotImplementedError other is not a GtidSet neither a Gtid,
324+
please convert it first to one of them
325+
"""
305326
if isinstance(other, GtidSet):
306327
return all(other_gtid in self.gtids for other_gtid in other.gtids)
307328
if isinstance(other, Gtid):
308329
return any(other in x for x in self.gtids)
309330
raise NotImplementedError
310331

311332
def __add__(self, other):
333+
"""
334+
Merge current instance with an other GtidSet or with a Gtid alone.
335+
336+
Raises:
337+
- NotImplementedError other is not a GtidSet neither a Gtid,
338+
please convert it first to one of them
339+
"""
312340
if isinstance(other, Gtid):
313341
new = GtidSet(self.gtids)
314342
new.merge_gtid(other)
@@ -323,6 +351,9 @@ def __add__(self, other):
323351
raise NotImplementedError
324352

325353
def __str__(self):
354+
"""
355+
Returns a comma separated string of gtids.
356+
"""
326357
return ','.join(str(x) for x in self.gtids)
327358

328359
def __repr__(self):

0 commit comments

Comments
 (0)