django.utils.text.smart_strip does not work with lazy strings (TypeError)
|Reported by:||bmispelon||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
>>> from django.utils.text import smart_split >>> from django.utils.translation import ugettext_lazy as _ >>> smart_split(_('a b c d')) <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7f53e20b0e10> >>> list(smart_split(_('a b c d'))) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "./django/utils/functional.py", line 128, in __wrapper__ raise TypeError("Lazy object returned unexpected type.") TypeError: Lazy object returned unexpected type.
This is caused by this line: https://github.com/django/django/blob/master/django/utils/text.py#L359
I don't think the allow_lazy decorator can be applied to a generator function so I think the line should be removed altogether.
If we remove the decorator, then lazy strings are evaluated when the generator is called.
This is not exactly backwards-incompatible since this function never actually worked with lazy strings in the first place.
Change History (3)
comment:1 Changed 2 years ago by claudep
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted