Skip to content

Commit 69123c0

Browse files
committed
-
1 parent e6ee07e commit 69123c0

File tree

6 files changed

+13
-75
lines changed

6 files changed

+13
-75
lines changed

source_py3/python_toolbox/cute_iter_tools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@
1010
import builtins
1111
import numbers
1212

13-
from python_toolbox import sys_tools
14-
from python_toolbox import misc_tools
1513
from python_toolbox import math_tools
16-
from python_toolbox import logic_tools
17-
1814

1915
infinity = float('inf')
2016

17+
2118
class _EMPTY_SENTINEL:
2219
pass
2320

@@ -395,6 +392,8 @@ def get_single_if_any(iterable,
395392

396393

397394
def are_equal(*sequences):
395+
from python_toolbox import sys_tools
396+
from python_toolbox import logic_tools
398397
sequence_types = set(map(type, sequences))
399398

400399
if not sys_tools.is_pypy: # Hack around Pypy bug 1799
@@ -420,6 +419,7 @@ def are_equal(*sequences):
420419

421420

422421
def is_sorted(iterable, key=None):
422+
from python_toolbox import misc_tools
423423
if key is None:
424424
key = misc_tools.identity_function
425425
for first_item, second_item in \

source_py3/python_toolbox/math_tools/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# This program is distributed under the MIT license.
33

44
import abc
5+
import numbers
56

67

78
class _PossiblyInfiniteIntegralType(abc.ABCMeta):

source_py3/python_toolbox/misc_tools/__init__.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33

44
'''This module defines miscellaneous tools.'''
55

6-
from .misc_tools import (
7-
is_subclass, get_mro_depth_of_method, frange, getted_vars,
8-
_ascii_variable_pattern, is_legal_ascii_variable_name,
9-
is_magic_variable_name, get_actual_type, is_number, identity_function,
10-
do_nothing, OwnNameDiscoveringDescriptor, find_clear_place_on_circle,
11-
general_sum, general_product, is_legal_email_address, is_type, NonInstatiable,
12-
repeat_getattr, add_extension_if_plain, set_attributes, pocket,
13-
decimal_number_from_string
14-
)
6+
from .misc_tools import *
157
from . import name_mangling
168
from .proxy_property import ProxyProperty

source_py3/python_toolbox/nifty_collections/lazy_tuple.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
from python_toolbox import decorator_tools
1515
from python_toolbox import comparison_tools
16-
from python_toolbox import sequence_tools
1716

1817

1918
infinity = float('inf')
@@ -141,6 +140,8 @@ def exhaust(self, i=infinity):
141140
This will take enough items so we will have `i` items in total,
142141
including the items we had before.
143142
'''
143+
from python_toolbox import sequence_tools
144+
144145
if self.exhausted:
145146
return
146147

@@ -153,14 +154,14 @@ def exhaust(self, i=infinity):
153154
# todo: can be smart and figure out if it's an empty slice and then
154155
# not exhaust.
155156

156-
(start, stop, step) = sequence_tools.parse_slice(i)
157+
canonical_slice = sequence_tools.CanonicalSlice(i)
157158

158159
exhaustion_point = max(
159-
_convert_index_to_exhaustion_point(start),
160-
_convert_index_to_exhaustion_point(stop)
160+
_convert_index_to_exhaustion_point(canonical_slice.start),
161+
_convert_index_to_exhaustion_point(canonical_slice.stop)
161162
)
162163

163-
if step > 0: # Compensating for excluded last item:
164+
if canonical_slice.step > 0: # Compensating for excluded last item:
164165
exhaustion_point -= 1
165166

166167
while len(self.collected_data) <= exhaustion_point:

source_py3/python_toolbox/sequence_tools.py

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -159,58 +159,6 @@ def is_immutable_sequence(thing):
159159
isinstance(thing, collections.MutableSequence)
160160

161161

162-
def parse_slice(s):
163-
'''
164-
Parse a `slice` object into a canonical `(start, stop, step)`.
165-
166-
This is helpful because `slice`'s own `.start`, `.stop` and `.step` are
167-
sometimes specified as `None` for convenience, so Python will infer them
168-
automatically. Here we make them explicit.
169-
170-
if `start` is `None`, it will be set to `0` (if the `step` is positive) or
171-
`infinity` (if the `step` is negative.)
172-
173-
if `stop` is `None`, it will be set to `infinity` (if the `step` is
174-
positive) or `0` (if the `step` is negative.)
175-
176-
If `step` is `None`, it will be changed to the default `1`.
177-
'''
178-
assert isinstance(s, slice)
179-
180-
### Parsing `step`:
181-
assert s.step != 0
182-
if s.step is None:
183-
step = 1
184-
else:
185-
step = s.step
186-
###
187-
188-
### Parsing `start`:
189-
if s.start is not None:
190-
start = s.start
191-
else:
192-
assert s.start is None
193-
if step > 0:
194-
start = 0
195-
else:
196-
assert step < 0
197-
start = infinity
198-
###
199-
200-
### Parsing `stop`:
201-
if s.stop is not None:
202-
stop = s.stop
203-
else:
204-
assert s.stop is None
205-
if step > 0:
206-
stop = infinity
207-
else:
208-
assert step < 0
209-
stop = -infinity
210-
###
211-
212-
return (start, stop, step)
213-
214162

215163
def to_tuple(single_or_sequence, item_type=None, item_test=None):
216164
'''
@@ -360,7 +308,6 @@ def ensure_iterable_is_sequence(iterable, default_type=tuple,
360308
return default_type(iterable)
361309

362310

363-
364311
class CanonicalSlice: # blockodo replace parse_slice everywhere
365312
def __init__(self, slice_, iterable_or_length=None, offset=0):
366313
'''
@@ -481,7 +428,7 @@ def __init__(self, slice_, iterable_or_length=None, offset=0):
481428

482429

483430

484-
class CuteSequenceMixin(shy_misc_tools.AlternativeLengthMixin):
431+
class CuteSequenceMixin(misc_tools.AlternativeLengthMixin):
485432
def take_random(self):
486433
return self[random.randint(0, get_length(self))]
487434

source_py3/test_python_toolbox/test_sequence_tools/test_parse_slice.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Copyright 2009-2014 Ram Rachum.
22
# This program is distributed under the MIT license.
33

4-
'''Testing module for `sequence_tools.parse_slice`.'''
5-
64
from python_toolbox import math_tools
75

86
from python_toolbox.sequence_tools import parse_slice
@@ -12,7 +10,6 @@
1210

1311

1412
def test():
15-
'''Test the basic workings of `parse_slice`.'''
1613

1714
r1 = list(range(5))
1815
r2 = list(range(2, 10))

0 commit comments

Comments
 (0)