Skip to content

Commit cd4f181

Browse files
committed
Supporting Python 2.6
1 parent 791c2b9 commit cd4f181

File tree

8 files changed

+34
-32
lines changed

8 files changed

+34
-32
lines changed

source_py2/python_toolbox/combi/perming/_fixed_map_managing_mixin.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ def free_values(self):
4444
# case of recurrent sequences, we don't want to remove all the sequence
4545
# items that are in `self.fixed_map.values()` but only as many as there
4646
# are in `self.fixed_map.values()`.
47+
from python_toolbox.nifty_collections import Bag
4748
free_values = []
48-
fixed_counter = collections.Counter(self.fixed_map.values())
49+
fixed_counter = Bag(self.fixed_map.values())
4950
for item in self.sequence:
5051
if fixed_counter[item]:
5152
fixed_counter[item] -= 1
@@ -78,16 +79,16 @@ def _n_cycles_in_fixed_items_of_just_fixed(self):
7879
@caching.CachedProperty
7980
def _undapplied_fixed_map(self):
8081
if self.is_dapplied:
81-
return {self.domain.index(key): value for key, value
82-
in self.fixed_map.items()}
82+
return dict((self.domain.index(key), value) for key, value
83+
in self.fixed_map.items())
8384
else:
8485
return self.fixed_map
8586

8687
@caching.CachedProperty
8788
def _undapplied_unrapplied_fixed_map(self):
8889
if self.is_dapplied or self.is_rapplied:
89-
return {self.domain.index(key): self.sequence.index(value)
90-
for key, value in self.fixed_map.items()}
90+
return dict((self.domain.index(key), self.sequence.index(value))
91+
for key, value in self.fixed_map.items())
9192
else:
9293
return self.fixed_map
9394

source_py2/python_toolbox/combi/perming/_variation_adding_mixin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def get_rapplied(self, sequence):
2121
raise Exception
2222
return PermSpace(
2323
sequence, n_elements=self.n_elements, domain=self.domain,
24-
fixed_map={key: sequence[value] for key, value in
25-
self.fixed_map.items()},
24+
fixed_map=dict((key, sequence[value]) for key, value in
25+
self.fixed_map.items()),
2626
degrees=self.degrees, slice_=self.canonical_slice,
2727
is_combination=self.is_combination,
2828
perm_type=self.perm_type
@@ -87,8 +87,8 @@ def get_dapplied(self, domain):
8787
raise Exception
8888
return PermSpace(
8989
self.sequence, n_elements=self.n_elements, domain=domain,
90-
fixed_map={domain[key]: value for key, value in
91-
self._undapplied_fixed_map},
90+
fixed_map=dict((domain[key], value) for key, value in
91+
self._undapplied_fixed_map),
9292
degrees=self.degrees, slice_=self.canonical_slice,
9393
is_combination=self.is_combination,
9494
perm_type=self.perm_type

source_py2/python_toolbox/combi/perming/_variation_removing_mixin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def unrapplied(self):
3232
return PermSpace(
3333
self.sequence_length, n_elements=self.n_elements,
3434
domain=self.domain,
35-
fixed_map={key: self.sequence.index(value) for
36-
key, value in self.fixed_map.items()},
35+
fixed_map=dict((key, self.sequence.index(value)) for
36+
key, value in self.fixed_map.items()),
3737
degrees=self.degrees, slice_=self.canonical_slice,
3838
is_combination=self.is_combination, perm_type=self.perm_type
3939
)

source_py2/python_toolbox/combi/perming/calculating_length.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ def calculate_length_of_recurrent_perm_space(k, fbb):
5959
### Doing phase one, getting all sub-FBBs: ################################
6060
# #
6161
levels = []
62-
current_fbbs = {fbb}
62+
current_fbbs = set((fbb,))
6363
while len(levels) < k and current_fbbs:
6464
k_ = k - len(levels)
6565
levels.append(
66-
{fbb_: fbb_.get_sub_fbbs_for_one_key_removed()
67-
for fbb_ in current_fbbs if (k_, fbb_) not in cache}
66+
dict((fbb_, fbb_.get_sub_fbbs_for_one_key_removed())
67+
for fbb_ in current_fbbs if (k_, fbb_) not in cache)
6868
)
6969
current_fbbs = set(itertools.chain(*levels[-1].values()))
7070
# #
@@ -144,12 +144,12 @@ def calculate_length_of_recurrent_comb_space(k, fbb):
144144
### Doing phase one, getting all sub-FBBs: ################################
145145
# #
146146
levels = []
147-
current_fbbs = {fbb}
147+
current_fbbs = set((fbb,))
148148
while len(levels) < k and current_fbbs:
149149
k_ = k - len(levels)
150150
levels.append(
151-
{fbb_: fbb_.get_sub_fbbs_for_one_key_and_previous_piles_removed()
152-
for fbb_ in current_fbbs if (k_, fbb_) not in cache}
151+
dict((fbb_, fbb_.get_sub_fbbs_for_one_key_and_previous_piles_removed())
152+
for fbb_ in current_fbbs if (k_, fbb_) not in cache)
153153
)
154154
current_fbbs = set(itertools.chain(*levels[-1].values()))
155155
# #

source_py2/python_toolbox/combi/perming/perm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Copyright 2009-2015 Ram Rachum.
22
# This program is distributed under the MIT license.
33

4-
import functools
54
import abc
65
import collections
76
import numbers
87

8+
from python_toolbox.third_party import functools
9+
910
from python_toolbox import misc_tools
1011
from python_toolbox import nifty_collections
1112
from python_toolbox import caching

source_py2/python_toolbox/combi/perming/perm_space.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,13 @@ def __init__(self, iterable_or_length, n_elements=None, domain=None,
273273
fixed_map = {}
274274
if not isinstance(fixed_map, dict):
275275
if isinstance(fixed_map, collections.Callable):
276-
fixed_map = {item: fixed_map(item) for item in self.sequence}
276+
fixed_map = dict((item, fixed_map(item)) for item in self.sequence)
277277
else:
278278
fixed_map = dict(fixed_map)
279279
if fixed_map:
280-
self.fixed_map = {key: value for (key, value) in
281-
fixed_map.items() if (key in self.domain) and
282-
(value in self.sequence)}
280+
self.fixed_map = dict((key, value) for (key, value) in
281+
fixed_map.items() if (key in self.domain) and
282+
(value in self.sequence))
283283

284284
else:
285285
(self.fixed_map, self.free_indices, self.free_keys,
@@ -1005,11 +1005,11 @@ def _create_with_cut_prefix(cls, sequence, domain=None,
10051005
# More efficient than removing the element, we filter these out
10061006
# later.
10071007

1008-
shit_set = {misc.MISSING_ELEMENT} | shit_set
1008+
shit_set = set((misc.MISSING_ELEMENT,)) | shit_set
10091009
sequence = [item for item in sequence if item not in shit_set]
10101010

1011-
fixed_map = {key - len(prefix): value
1012-
for key, value in fixed_map.items()}
1011+
fixed_map = dict((key - len(prefix), value)
1012+
for key, value in fixed_map.items())
10131013

10141014
perm_space = cls(
10151015
sequence, n_elements=n_elements, fixed_map=fixed_map,

source_py2/python_toolbox/cute_inspect/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def getcallargs(func, *positional, **named):
1818
A dict is returned, with keys the function argument names (including the
1919
names of the * and ** arguments, if any), and values the respective bound
2020
values from 'positional' and 'named'."""
21-
# from inspect import *
21+
from inspect import ismethod
2222
args, varargs, varkw, defaults = getargspec(func)
2323
f_name = func.__name__
2424
arg2value = {}

source_py2/test_python_toolbox/test_combi/test_perm_space.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_perm_spaces():
3939

4040
assert cute_iter_tools.are_equal(pure_0a, pure_0b, pure_0c, pure_0d)
4141

42-
assert set(map(bool, (pure_0a, pure_0b, pure_0c, pure_0d))) == {True}
42+
assert set(map(bool, (pure_0a, pure_0b, pure_0c, pure_0d))) == set((True,))
4343

4444
pure_perm_space = pure_0a
4545
assert pure_0a.is_pure
@@ -141,7 +141,7 @@ def test_perm_spaces():
141141
(Perm((0, 1, 2, 3)) ** (0)) == (Perm((0, 1, 2, 3)) ** (1)) == \
142142
(Perm((0, 1, 2, 3)) ** 2) == (Perm((0, 1, 2, 3)) ** 3)
143143

144-
assert set(map(bool, (pure_0a[4:4], pure_0a[3:2]))) == {False}
144+
assert set(map(bool, (pure_0a[4:4], pure_0a[3:2]))) == set((False,))
145145
assert pure_0a[2:6][1:-1] == pure_0a[3:5]
146146
assert tuple(pure_0a[2:6][1:-1]) == tuple(pure_0a[3:5])
147147
assert pure_0a[2:6][1:-1][1] == pure_0a[3:5][1]
@@ -420,7 +420,7 @@ def test_partial_perm_space():
420420
assert empty_partial_perm_space.length == 0
421421
assert empty_partial_perm_space.variation_selection == \
422422
perming.variations.VariationSelection(
423-
{perming.variations.Variation.PARTIAL})
423+
set((perming.variations.Variation.PARTIAL,)))
424424
assert empty_partial_perm_space != PermSpace(5, n_elements=7)
425425
with cute_testing.RaiseAssertor(IndexError):
426426
empty_partial_perm_space[0]
@@ -447,15 +447,15 @@ def test_partial_perm_space():
447447
assert perm_space_3.is_partial and not perm_space_3.is_combination
448448
assert perm_space_4.is_partial and not perm_space_4.is_combination
449449
assert set(map(type, (perm_space_0, perm_space_1, perm_space_2,
450-
perm_space_3, perm_space_4))) == {PermSpace}
450+
perm_space_3, perm_space_4))) == set((PermSpace,))
451451

452452
assert not perm_space_5.is_partial and perm_space_5.is_combination
453453
assert perm_space_6.is_partial and perm_space_6.is_combination
454454
assert perm_space_7.is_partial and perm_space_7.is_combination
455455
assert perm_space_8.is_partial and perm_space_8.is_combination
456456
assert perm_space_9.is_partial and perm_space_9.is_combination
457457
assert set(map(type, (perm_space_5, perm_space_6, perm_space_7,
458-
perm_space_8, perm_space_9))) == {CombSpace}
458+
perm_space_8, perm_space_9))) == set((CombSpace,))
459459

460460
assert CombSpace(5, n_elements=2) == perm_space_7
461461

@@ -610,7 +610,7 @@ def test_unrecurrented():
610610
assert unrecurrented_perm_space.length == math_tools.factorial(6)
611611
perm = unrecurrented_perm_space[100]
612612
assert all(i in 'abc' for i in perm)
613-
assert set(map(perm.index, 'abc')) < {0, 1, 2, 3, 4}
613+
assert set(map(perm.index, 'abc')) < set((0, 1, 2, 3, 4))
614614
assert set(''.join(perm)) == set('abc')
615615

616616

0 commit comments

Comments
 (0)