mirror of https://github.com/django/django.git
Refs #34445 -- Fixed string-casting of non-string lazy objects when value may be bytes.
If the result type is bytes, then calling bytes() on it does nothing. If the result type is not bytes, we should not cast to bytes, just because the return value may be bytes.
This commit is contained in:
parent
5f2308710b
commit
f5817c24f4
|
@ -144,10 +144,7 @@ def lazy(func, *resultclasses):
|
||||||
return bytes(func(*self.__args, **self.__kw))
|
return bytes(func(*self.__args, **self.__kw))
|
||||||
|
|
||||||
def __cast(self):
|
def __cast(self):
|
||||||
if self._delegate_bytes:
|
return func(*self.__args, **self.__kw)
|
||||||
return self.__bytes_cast()
|
|
||||||
else:
|
|
||||||
return func(*self.__args, **self.__kw)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
# object defines __str__(), so __prepare_class__() won't overload
|
# object defines __str__(), so __prepare_class__() won't overload
|
||||||
|
|
|
@ -242,6 +242,10 @@ class FunctionalTests(SimpleTestCase):
|
||||||
lazy_value = lazy(lambda: [1], str, list)()
|
lazy_value = lazy(lambda: [1], str, list)()
|
||||||
self.assertEqual(str(lazy_value), "[1]")
|
self.assertEqual(str(lazy_value), "[1]")
|
||||||
|
|
||||||
|
def test_lazy_str_cast_mixed_bytes_result_types(self):
|
||||||
|
lazy_value = lazy(lambda: [1], bytes, list)()
|
||||||
|
self.assertEqual(str(lazy_value), "[1]")
|
||||||
|
|
||||||
def test_classproperty_getter(self):
|
def test_classproperty_getter(self):
|
||||||
class Foo:
|
class Foo:
|
||||||
foo_attr = 123
|
foo_attr = 123
|
||||||
|
|
Loading…
Reference in New Issue