Skip to content

Commit 967fcfc

Browse files
committed
-
1 parent 010153f commit 967fcfc

File tree

5 files changed

+19
-47
lines changed

5 files changed

+19
-47
lines changed

source_py3/python_toolbox/combi/variations.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ def __repr__(self):
4848
return '<VariationSelectionSpace>'
4949

5050

51-
class VariationSelection:
51+
class VariationSelection():
52+
__new__ = lambda cls, variations: cls._create_from_tuple(tuple(sorted(set(variations))))
53+
54+
@caching.cache()
55+
def _create_from_tuple(cls, variations):
56+
self.variations = 1 / 0
57+
5258
def __init__(self, variations):
5359
self.variations = variations
5460

@@ -68,5 +74,4 @@ def is_allowed(self):
6874

6975
variation_selection_space = VariationSelectionSpace()
7076
variation_selection_space[7].is_allowed
71-
repr(variation_selection_space[7])
72-
2 / 2
77+
repr(variation_selection_space[7])

source_py3/python_toolbox/comparison_tools.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,6 @@ def underscore_hating_key(string):
1212
return str(string).replace('_', chr(sys.maxunicode))
1313

1414

15-
def total_ordering(cls):
16-
'''
17-
Add full arsenal of ordering methods to a class based on existing subset.
18-
'''
19-
convert = {
20-
'__lt__': [('__gt__', lambda self, other:
21-
not (self < other or self == other)),
22-
('__le__', lambda self, other:
23-
self < other or self == other),
24-
('__ge__', lambda self, other:
25-
not self < other)],
26-
'__le__': [('__ge__', lambda self, other:
27-
not self <= other or self == other),
28-
('__lt__', lambda self, other:
29-
self <= other and not self == other),
30-
('__gt__', lambda self, other:
31-
not self <= other)],
32-
'__gt__': [('__lt__', lambda self, other:
33-
not (self > other or self == other)),
34-
('__ge__', lambda self, other:
35-
self > other or self == other),
36-
('__le__', lambda self, other:
37-
not self > other)],
38-
'__ge__': [('__le__', lambda self, other:
39-
(not self >= other) or self == other),
40-
('__gt__', lambda self, other:
41-
self >= other and not self == other),
42-
('__lt__', lambda self, other:
43-
not self >= other)]
44-
}
45-
roots = set(dir(cls)) & set(convert)
46-
if not roots:
47-
raise ValueError('Must define at least one ordering operation: `<`, '
48-
'`>`, `<=`, or `>=`.')
49-
root = max(roots) # We prefer __lt__ to __le__ to __gt__ to __ge__
50-
for opname, opfunc in convert[root]:
51-
if opname not in roots:
52-
opfunc.__name__ = opname
53-
opfunc.__doc__ = getattr(float, opname).__doc__
54-
setattr(cls, opname, opfunc)
55-
return cls
56-
57-
5815
def process_key_function_or_attribute_name(key_function_or_attribute_name):
5916
'''
6017
Make a key function given either a key function or an attribute name.

source_py3/python_toolbox/nifty_collections/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .frozen_counter import FrozenCounter
1313
from .frozen_crate_counter import FrozenCrateCounter
1414
from .default_sorted_dict import DefaultSortedDict
15+
from .orderable_enum import OrderableEnum
1516

1617
from .emitting_ordered_set import EmittingOrderedSet
1718
from .emitting_weak_key_default_dict import EmittingWeakKeyDefaultDict

source_py3/python_toolbox/nifty_collections/lazy_tuple.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
See its documentation for more information.
88
'''
99

10+
import functools
1011
import threading
1112
import collections
1213
import itertools
@@ -49,7 +50,7 @@ def _with_lock(method, *args, **kwargs):
4950

5051

5152
@collections.Sequence.register
52-
@comparison_tools.total_ordering
53+
@functools.total_ordering
5354
class LazyTuple(collections.Sequence):
5455
'''
5556
A lazy tuple which requests as few values as possible from its iterator.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright 2009-2014 Ram Rachum.
2+
# This program is distributed under the MIT license.
3+
4+
import enum
5+
6+
7+
class OrderableEnum(enum.Enum):
8+
pass

0 commit comments

Comments
 (0)