From 8ad9c5d09f8e1fedaa8bc40a87a2826d1ae06031 Mon Sep 17 00:00:00 2001 From: PythonCoderAS <13932583+PythonCoderAS@users.noreply.github.com> Date: Sun, 20 Feb 2022 08:18:37 -0500 Subject: [PATCH 1/2] Improve documentation --- smart_range/smart_range.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/smart_range/smart_range.py b/smart_range/smart_range.py index 8390776..67a1f0a 100644 --- a/smart_range/smart_range.py +++ b/smart_range/smart_range.py @@ -6,7 +6,7 @@ class SmartRange: """The class that represents a range of values. Input consists of a string containing the range. - A range string is a comma-separated list of range items. There are 4 types of range items supported by the class: + A range string is a comma-separated list of range items. There are 5 types of range items supported by the class: #. Classic range with a defined start and finish. Example: ``1-5`` @@ -34,6 +34,10 @@ class SmartRange: `` - `` * Example where the range string is ``1-5,+8`` -> ``1-5,6-13`` + + #. A singular dash, indicating a range with an undefined start and an undefined finish. This requires the + ``min_val`` and the ``max_val`` parameter to be supplied to the :py:meth:`~SmartRange.__init__` method. + Additionally, this item can only show up once at the end of a range string. Example: ``-`` """ ranges: List[range] From 6843bf79de1bd4f7f05d752c5fc7779ab0df3426 Mon Sep 17 00:00:00 2001 From: PythonCoderAS <13932583+PythonCoderAS@users.noreply.github.com> Date: Sun, 20 Feb 2022 08:20:03 -0500 Subject: [PATCH 2/2] Update documentation and fix bug in exception raising. --- setup.py | 2 +- smart_range/smart_range.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 9356dd1..088ecd4 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='smart_range', - version='1.1.0', + version='1.1.1', packages=['smart_range'], url='https://github.com/PythonCoderAS/SmartRange', license='MIT', diff --git a/smart_range/smart_range.py b/smart_range/smart_range.py index 67a1f0a..1fca152 100644 --- a/smart_range/smart_range.py +++ b/smart_range/smart_range.py @@ -118,9 +118,9 @@ def _parse_range(self, range_str: str, min_val: Optional[int] = None, max_val: O end = start + int(part[1:]) - 1 # If we say +25, we want 25 numbers, not to end at the 25th index (26 numbers). if start is None: - raise NoMinimumValueError(part) + raise NoMinimumValueError(end) if end is None: - raise NoMaximumValueError(part) + raise NoMaximumValueError(start) if end < start: raise NegativeRangeError(start, end) if locked_max and max(start, end) > locked_max: @@ -130,7 +130,7 @@ def _parse_range(self, range_str: str, min_val: Optional[int] = None, max_val: O return ranges def __iter__(self) -> Generator[int, None, None]: - """Returns a generator containing all of the numbers in the smart range. + """Returns a generator containing all the numbers in the smart range. .. note:: In order to iterate over the list of range objects, use the :py:attr:`ranges` attribute, such as: