Skip to content

Commit 2959138

Browse files
committed
-
1 parent 8732687 commit 2959138

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

source_py3/python_toolbox/caching/decorators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from python_toolbox import binary_search
1616
from python_toolbox import decorator_tools
1717
from python_toolbox.sleek_reffing import SleekCallArgs
18-
from python_toolbox.nifty_collections import OrderedDict
1918

2019
infinity = float('inf')
2120

@@ -70,6 +69,8 @@ def f(a, b=2):
7069
# have to go through so much shit. update: probably it will help only for
7170
# completely argumentless function. so do one for those.
7271

72+
from python_toolbox.nifty_collections import OrderedDict
73+
7374
if time_to_keep is not None:
7475
if max_size != infinity:
7576
raise NotImplementedError

source_py3/python_toolbox/combi/variations.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import enum
2-
31
from python_toolbox import cute_iter_tools
42
from python_toolbox import nifty_collections
53
from python_toolbox import caching
@@ -14,7 +12,7 @@ class UnsupportedVariationCombinationException(Exception):
1412
make variation classes mostly for this and testing'''
1513

1614

17-
class PermSpaceVariation(enum.Enum):
15+
class PermSpaceVariation(nifty_collections.CuteEnum):
1816
RAPPLIED = 'rapplied'
1917
RECURRENT = 'recurrent'
2018
PARTIAL = 'partial'
@@ -25,8 +23,6 @@ class PermSpaceVariation(enum.Enum):
2523
SLICED = 'sliced'
2624

2725

28-
PermSpaceVariation.index = tuple(PermSpaceVariation).index
29-
3026
variation_clashes = (
3127
{PermSpaceVariation.DEGREED, PermSpaceVariation.COMBINATION},
3228
{PermSpaceVariation.DEGREED, PermSpaceVariation.PARTIAL},
@@ -49,11 +45,12 @@ def __repr__(self):
4945

5046

5147
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
48+
__new__ = lambda cls, variations: cls._create_from_tuple(
49+
tuple(sorted(set(variations)))
50+
)
51+
_create_from_tuple = caching.cache()(lambda self: super().__new__(variations))
52+
# This method exsits so we could cache canonically. The `__new__` method
53+
# canonicalizes the `variations` argument and we cache according to it.
5754

5855
def __init__(self, variations):
5956
self.variations = variations

source_py3/test_python_toolbox/test_caching/test_cached_property.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ class A:
3535

3636
assert a2.personality == a1.personality + 1
3737

38+
def test_inheritance():
39+
class A:
40+
personality = CachedProperty(counting_func)
41+
42+
class B(A):
43+
pass
44+
45+
assert isinstance(B.personality, CachedProperty)
46+
47+
b1 = B()
48+
assert b1.personality == b1.personality == b1.personality
49+
50+
b2 = B()
51+
assert b2.personality == b2.personality == b2.personality
52+
53+
assert b2.personality == b1.personality + 1
54+
3855
def test_value():
3956
'''Test `CachedProperty` when giving a value instead of a getter.'''
4057
class B:

0 commit comments

Comments
 (0)