Produce consistent string for __repr__() of NoValue
The :attr:`.api.NO_VALUE` constant now has a fixed ``__repr__()`` output, so that scenarios where this constant's string value ends up being used as a cache key do not create multiple values. Pull request courtesy Paul Brown. Change-Id: Iecc9633d6be562bc6821bf4ee2ff3f29d1b31e80 Pull-request: https://bitbucket.org/zzzeek/dogpile.cache/pull-requests/61
This commit is contained in:
parent
2f82d8f3c0
commit
eec8a9731b
|
@ -14,6 +14,14 @@ Changelog
|
|||
problems for backends like that of Redis. Pull request courtesy
|
||||
Tobias Sauerwein.
|
||||
|
||||
.. change::
|
||||
:tags: bug
|
||||
|
||||
The :attr:`.api.NO_VALUE` constant now has a fixed ``__repr__()``
|
||||
output, so that scenarios where this constant's string value
|
||||
ends up being used as a cache key do not create multiple values.
|
||||
Pull request courtesy Paul Brown.
|
||||
|
||||
.. changelog::
|
||||
:version: 0.6.3
|
||||
:released: Thu May 18, 2017
|
||||
|
|
|
@ -13,6 +13,13 @@ class NoValue(object):
|
|||
def payload(self):
|
||||
return self
|
||||
|
||||
def __repr__(self):
|
||||
"""Ensure __repr__ is a consistent value in case NoValue is used to
|
||||
fill another cache key.
|
||||
|
||||
"""
|
||||
return '<dogpile.cache.api.NoValue object>'
|
||||
|
||||
if py3k:
|
||||
def __bool__(self): # pragma NO COVERAGE
|
||||
return False
|
||||
|
@ -20,6 +27,7 @@ class NoValue(object):
|
|||
def __nonzero__(self): # pragma NO COVERAGE
|
||||
return False
|
||||
|
||||
|
||||
NO_VALUE = NoValue()
|
||||
"""Value returned from ``get()`` that describes
|
||||
a key not present."""
|
||||
|
|
|
@ -17,6 +17,11 @@ def key_mangler(key):
|
|||
return "HI!" + key
|
||||
|
||||
|
||||
class APITest(TestCase):
|
||||
def test_no_value_str(self):
|
||||
eq_(str(NO_VALUE), "<dogpile.cache.api.NoValue object>")
|
||||
|
||||
|
||||
class RegionTest(TestCase):
|
||||
|
||||
def _region(self, init_args={}, config_args={}, backend="mock"):
|
||||
|
|
Loading…
Reference in New Issue