Skip to content

Commit 17e8f48

Browse files
author
Tercio de Melo
committed
Moves step direction setting from To to /by/
1 parent e9b9962 commit 17e8f48

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

syntax_sugar/infix.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ def step(self):
5050
def step(self, value):
5151
if value == 0 or not value /is_a/ int:
5252
raise TypeError('Interval must be an integer different from 0')
53-
if self.end >= self.start and value < 0:
54-
self._step = -value
55-
elif self.end <= self.start and value > 0:
56-
self._step = -value
57-
else:
58-
self._step = value
53+
self._step = value
5954

6055
def __mul__(self, rhs):
6156
return product(self, rhs)
@@ -105,7 +100,13 @@ def to(start, end):
105100

106101
@infix
107102
def by(to_object, step):
108-
to_object.step = step
103+
if to_object.end >= to_object.start and step < 0:
104+
to_object.step = -step
105+
elif to_object.end <= to_object.start and step > 0:
106+
to_object.step = -step
107+
else:
108+
to_object.step = step
109+
109110
return to_object
110111

111112

0 commit comments

Comments
 (0)