Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
7f5cc569
Commit
7f5cc569
authored
5 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
fix tests
parent
063b7b07
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
satella/coding/structures/dictionaries/expiring.py
+2
-0
2 additions, 0 deletions
satella/coding/structures/dictionaries/expiring.py
satella/coding/structures/proxy.py
+14
-13
14 additions, 13 deletions
satella/coding/structures/proxy.py
with
16 additions
and
13 deletions
satella/coding/structures/dictionaries/expiring.py
+
2
−
0
View file @
7f5cc569
...
@@ -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
,
...
...
This diff is collapsed.
Click to expand it.
satella/coding/structures/proxy.py
+
14
−
13
View file @
7f5cc569
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment