mirror of
https://github.com/django/django.git
synced 2025-03-31 19:46:42 +00:00
Made bytes and str return types no longer mutually exclusive in lazy().
They are no longer special cased.
This commit is contained in:
parent
459f30f73e
commit
a57d5d9bbc
@ -119,13 +119,6 @@ def lazy(func, *resultclasses):
|
|||||||
continue
|
continue
|
||||||
meth = cls.__promise__(method_name)
|
meth = cls.__promise__(method_name)
|
||||||
setattr(cls, method_name, meth)
|
setattr(cls, method_name, meth)
|
||||||
cls._delegate_bytes = bytes in resultclasses
|
|
||||||
cls._delegate_text = str in resultclasses
|
|
||||||
if cls._delegate_bytes and cls._delegate_text:
|
|
||||||
raise ValueError(
|
|
||||||
"Cannot call lazy() with both bytes and text return types."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __promise__(cls, method_name):
|
def __promise__(cls, method_name):
|
||||||
|
@ -234,9 +234,7 @@ class FunctionalTests(SimpleTestCase):
|
|||||||
|
|
||||||
def test_lazy_bytes_and_str_result_classes(self):
|
def test_lazy_bytes_and_str_result_classes(self):
|
||||||
lazy_obj = lazy(lambda: "test", str, bytes)
|
lazy_obj = lazy(lambda: "test", str, bytes)
|
||||||
msg = "Cannot call lazy() with both bytes and text return types."
|
self.assertEqual(str(lazy_obj()), "test")
|
||||||
with self.assertRaisesMessage(ValueError, msg):
|
|
||||||
lazy_obj()
|
|
||||||
|
|
||||||
def test_lazy_str_cast_mixed_result_types(self):
|
def test_lazy_str_cast_mixed_result_types(self):
|
||||||
lazy_value = lazy(lambda: [1], str, list)()
|
lazy_value = lazy(lambda: [1], str, list)()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user