Skip to content
Snippets Groups Projects
Commit 7f5cc569 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

fix tests

parent 063b7b07
No related branches found
No related tags found
No related merge requests found
...@@ -78,6 +78,7 @@ class SelfCleaningDefaultDict(Monitor, tp.MutableMapping[K, V], Cleanupable): ...@@ -78,6 +78,7 @@ class SelfCleaningDefaultDict(Monitor, tp.MutableMapping[K, V], Cleanupable):
""" """
def __len__(self) -> int: def __len__(self) -> int:
self.cleanup()
return len(self.data) return len(self.data)
def __init__(self, default_factory: tp.Callable[[], V], *args, **kwargs): def __init__(self, default_factory: tp.Callable[[], V], *args, **kwargs):
...@@ -137,6 +138,7 @@ class ExpiringEntryDict(Monitor, tp.MutableMapping[K, V], Cleanupable): ...@@ -137,6 +138,7 @@ class ExpiringEntryDict(Monitor, tp.MutableMapping[K, V], Cleanupable):
""" """
def __len__(self) -> int: def __len__(self) -> int:
self.cleanup()
return len(self.data) return len(self.data)
def __init__(self, expiration_timeout: float, *args, def __init__(self, expiration_timeout: float, *args,
......
...@@ -43,12 +43,17 @@ class Proxy(tp.Generic[T]): ...@@ -43,12 +43,17 @@ class Proxy(tp.Generic[T]):
Note that this overloads __repr__, __str__ and __dir__, which may prove confusing. Note that this overloads __repr__, __str__ and __dir__, which may prove confusing.
Handle this in your descendant classes. Handle this in your descendant classes.
If wrap_operations is set, the following code will be executed on the result:
>>> a = a.__add__(b)
>>> return self.__class__(a)
Wrapped operations include all arithmetic operations and bitwise operations,
except for divmod, but including concat, rounding, truncing and ceiling.
:param object_to_wrap: object to wrap :param object_to_wrap: object to wrap
:param wrap_operations: whether results of operations returning something else should be :param wrap_operations: whether results of operations returning something else should be
also proxied. This will be done by the following code: also proxied.
>>> a = a.__add__(b)
>>> return self.__class__(a)
Wrapped operations include all arithmetic operations and bitwise operations.
""" """
__slots__ = ('__obj', '__wrap_operations') __slots__ = ('__obj', '__wrap_operations')
...@@ -62,13 +67,13 @@ class Proxy(tp.Generic[T]): ...@@ -62,13 +67,13 @@ class Proxy(tp.Generic[T]):
def __getitem__(self, item): def __getitem__(self, item):
return self.__obj[item] return self.__obj[item]
def __setitem__(self, key, value): def __setitem__(self, key, value) -> None:
self.__obj[key] = value self.__obj[key] = value
def __delitem__(self, key): def __delitem__(self, key) -> None:
del self.__obj[key] del self.__obj[key]
def __setattr__(self, key, value): def __setattr__(self, key, value) -> None:
if key in _SETTABLE_KEYS: if key in _SETTABLE_KEYS:
super().__setattr__(key, value) super().__setattr__(key, value)
else: else:
...@@ -77,7 +82,7 @@ class Proxy(tp.Generic[T]): ...@@ -77,7 +82,7 @@ class Proxy(tp.Generic[T]):
def __getattr__(self, item): def __getattr__(self, item):
return getattr(self.__obj, item) return getattr(self.__obj, item)
def __delattr__(self, item): def __delattr__(self, item) -> None:
delattr(self.__obj, item) delattr(self.__obj, item)
def __int__(self) -> int: def __int__(self) -> int:
...@@ -121,12 +126,8 @@ class Proxy(tp.Generic[T]): ...@@ -121,12 +126,8 @@ class Proxy(tp.Generic[T]):
def __floordiv__(self, other): def __floordiv__(self, other):
return self.__obj // other return self.__obj // other
@wrap_operation
def __rdivmod__(self, other): def __rdivmod__(self, other):
result = divmod(other, self.__obj) return divmod(other, self.__obj)
if self.__wrap_operations:
result = self.__class__(result)
return result
@wrap_operation @wrap_operation
def __truediv__(self, other): def __truediv__(self, other):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment