Skip to content

Commit

Permalink
Fix parsing logic to correctly handle special characters and update t…
Browse files Browse the repository at this point in the history
…est assertions
  • Loading branch information
arthur-debert committed Dec 5, 2024
1 parent a677a3b commit db0b642
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions rangy/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def parse_range(range_input):

start, end = _normalize_to_sequence(range_input)


try:
if start == '*':
parsed_start = 0
Expand All @@ -112,9 +113,7 @@ def parse_range(range_input):
else:
parsed_start = _convert_string_part(start)

if end == '*' or end == '+':
parsed_end = INFINITY
elif not isinstance(end, str):
if not isinstance(end, str):
converter = ConverterRegistry.get(end)
parsed_end = converter(end)
else:
Expand Down
4 changes: 2 additions & 2 deletions rangy/rangy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _parse(self, rangy) -> Tuple[Union[int, float], Union[int, float]]:
elif isinstance(rangy, str) and any(sep in rangy for sep in "-,:;"):
raise ParseRangeError(f"Invalid rangy specification: {rangy}")
elif isinstance(rangy, (int, str)):
if rangy in SPECIAL_CHARS.keys():
if rangy in SPECIAL_CHARS.values():
min_val = rangy
max_val = rangy
else:
Expand All @@ -64,7 +64,7 @@ def _parse(self, rangy) -> Tuple[Union[int, float], Union[int, float]]:
else:
raise ParseRangeError(f"Invalid rangy specification: {rangy}")

chars = SPECIAL_CHARS.keys()
chars = SPECIAL_CHARS.values()
min_val = int(min_val) if min_val not in chars else min_val
max_val = int(max_val) if max_val not in chars else max_val

Expand Down
2 changes: 1 addition & 1 deletion tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_from_string_any():
def test_from_string_at_least_one():
count = Rangy("+")
assert count._type == AT_LEAST_ONE
assert count.values == (1, 1000000)
assert count.values == (1, 000000)

def test_from_string_range():
count = Rangy("1-3")
Expand Down

0 comments on commit db0b642

Please sign in to comment.