Skip to content

Commit

Permalink
Merge pull request #185 from youknowone/fix-key-class
Browse files Browse the repository at this point in the history
Fix key override for class
  • Loading branch information
youknowone authored Sep 29, 2021
2 parents f22fcdb + 8e4eb90 commit 650df62
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ring/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.9.0'
__version__ = '0.9.1'
2 changes: 1 addition & 1 deletion ring/func/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def __init__(self, rope):
self._rope = rope

def key(self, func):
self._rope.compose_key = lambda pargs: func(*pargs.args, **pargs.kwargs)
self._rope.compose_key = lambda pargs: func(*(pargs.bounds + pargs.args), **pargs.kwargs)

def encode(self, func):
self._rope._encode = func
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ norecursedirs=.git py ci
[flake8]
ignore=E501,E701
[metadata]
version_from_file: ring/__init__.py
version_from_file: ring/__version__.py
17 changes: 16 additions & 1 deletion tests/test_customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ring


def test_override_key():
def test_override_key_function():

@ring.dict({})
def f(v):
Expand All @@ -29,3 +29,18 @@ def f_decode(v):

assert f.storage.backend['test:5'] == ('encoded', 5)
assert f.get(5) == 6


def test_override_key_class():
# https://github.com/youknowone/ring/issues/184
class A:
@ring.dict({})
def get_entity(self, id):
return {"test": "ok"}

@get_entity.ring.key
def get_entity_key(self, id):
return "test:{id}".format(id=id)

a = A()
a.get_entity("123")

0 comments on commit 650df62

Please sign in to comment.