Skip to content

Commit a0c5f2e

Browse files
author
czheo
committed
add 1 /to/ ...
1 parent a8e4f89 commit a0c5f2e

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

syntax_sugar/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
from ._stream import *
66
from ._placeholder import *
77
from ._match import *
8+
from ._iter import *

syntax_sugar/_iter.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from ._pipe import pipe
22
from itertools import tee, islice
33

4+
__all__ = [
5+
'INF',
6+
]
7+
48
INF = float('inf')
5-
NEGINF = float('-inf')
69

710
class Iterator:
811
def __init__(self, data):
@@ -33,11 +36,14 @@ def slice(self, start=0, stop=None, step=1):
3336

3437
class Range:
3538
def __init__(self, start, end):
36-
if start in {INF, NEGINF}:
39+
if start in {INF, -INF}:
3740
raise ValueError('Cannot start range from infinity')
3841

42+
if end == Ellipsis:
43+
end = INF
44+
3945
valid_char = lambda c: isinstance(c, str) and len(c) == 1
40-
valid_integer = lambda i: isinstance(i, int) or i == INF or i == NEGINF
46+
valid_integer = lambda i: isinstance(i, int) or i == INF or i == -INF
4147

4248
if valid_integer(start) and valid_integer(end):
4349
self.type = 'number'

syntax_sugar/_util.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
'as_a',
88
'to',
99
'step',
10-
'INF',
1110
'has',
1211
'take',
1312
'drop',
1413
]
1514

16-
INF = float('inf')
17-
1815
def flip(fn):
1916
def wrapper(*args):
2017
return fn(args[1], args[0])

tests/test_iter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pytest import raises
2-
from syntax_sugar._iter import Range, Iterator
3-
from syntax_sugar._util import take, to, INF
2+
from syntax_sugar._iter import Range, Iterator, INF
3+
from syntax_sugar._util import take, to
44
from itertools import product
55

66

0 commit comments

Comments
 (0)