From abb42dcd4886705d6ba8af27f68ef605218ac67c Mon Sep 17 00:00:00 2001 From: Philip Paquette Date: Wed, 11 Sep 2019 12:58:45 -0400 Subject: Added ReadtheDocs documentation for the public API - Reformatted the docstring to be compatible - Added tests to make sure the documentation compiles properly - Added sphinx as a pip requirement Co-authored-by: Philip Paquette Co-authored-by: notoraptor --- diplomacy/utils/sorted_set.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'diplomacy/utils/sorted_set.py') diff --git a/diplomacy/utils/sorted_set.py b/diplomacy/utils/sorted_set.py index 01cfb34..0bd327c 100644 --- a/diplomacy/utils/sorted_set.py +++ b/diplomacy/utils/sorted_set.py @@ -21,15 +21,16 @@ from copy import copy from diplomacy.utils import exceptions from diplomacy.utils.common import is_sequence -class SortedSet(): +class SortedSet: """ Sorted set (sorted values, each value appears once). """ __slots__ = ('__type', '__list') def __init__(self, element_type, content=()): """ Initialize a typed sorted set. + :param element_type: Expected type for values. :param content: (optional) Sequence of values to initialize sorted set with. - """ + """ if not is_sequence(content): raise exceptions.TypeException('sequence', type(content)) self.__type = element_type @@ -40,12 +41,15 @@ class SortedSet(): @staticmethod def builder(element_type): """ Return a function to build sorted sets from content (sequence of values). - :param element_type: expected type for sorted set values. - :return: callable - Returned function expects a content parameter like SortedSet initializer. + + .. code-block:: python + builder_fn = SortedSet.builder(str) my_sorted_set = builder_fn(['c', '3', 'p', '0']) + + :param element_type: expected type for sorted set values. + :return: callable """ return lambda iterable: SortedSet(element_type, iterable) @@ -104,9 +108,9 @@ class SortedSet(): return best_position def get_next_value(self, element): - """ Get lowest value in sorted set greater than given element, or None if such values does not exists - in the sorted set. Given element may not exists in the sorted set. - """ + """ Get lowest value in sorted set greater than given element, or None if such values + does not exists in the sorted set. Given element may not exists in the sorted set. + """ assert isinstance(element, self.__type) if self.__list: best_position = bisect.bisect_right(self.__list, element) @@ -118,8 +122,8 @@ class SortedSet(): return None def get_previous_value(self, element): - """ Get greatest value in sorted set less the given element, or None if such value does not exists - in the sorted set. Given element may not exists in the sorted set. + """ Get greatest value in sorted set less the given element, or None if such value + does not exists in the sorted set. Given element may not exists in the sorted set. """ assert isinstance(element, self.__type) if self.__list: -- cgit v1.2.3