1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +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:
Ran Benita 2019-05-03 13:03:14 +03:00 committed by Mariusz Felisiak
parent 459f30f73e
commit a57d5d9bbc
2 changed files with 1 additions and 10 deletions

View File

@ -119,13 +119,6 @@ def lazy(func, *resultclasses):
continue
meth = cls.__promise__(method_name)
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
def __promise__(cls, method_name):

View File

@ -234,9 +234,7 @@ class FunctionalTests(SimpleTestCase):
def test_lazy_bytes_and_str_result_classes(self):
lazy_obj = lazy(lambda: "test", str, bytes)
msg = "Cannot call lazy() with both bytes and text return types."
with self.assertRaisesMessage(ValueError, msg):
lazy_obj()
self.assertEqual(str(lazy_obj()), "test")
def test_lazy_str_cast_mixed_result_types(self):
lazy_value = lazy(lambda: [1], str, list)()