#27382 closed Bug (fixed)
Document that ugettext_lazy() result can't be used with arbitrary Python code
Reported by: | Mike Edmunds | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.10 |
Severity: | Normal | Keywords: | ugettext_lazy |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The documentation currently states that:
The result of a
ugettext_lazy()
call can be used wherever you would use a unicode string (an object with typeunicode
) in Python.
However, the result of ugettext_lazy() does not pass isinstance(lazy_obj, unicode)
. Because instance checks are commonly used to detect text strings, the lazy objects are incompatible with some Python standard library code and other popular Python packages (such as requests).
Proposed doc patch clarifies that ugettext_lazy() can be used with other Django code, but that it should generally be converted to text before passing to arbitrary, non-Django Python code.
Discussion and examples on django-dev: https://groups.google.com/forum/#!topic/django-developers/eFsGf1ZrG7c
Change History (4)
comment:1 by , 8 years ago
Has patch: | set |
---|
comment:2 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Doc change: https://github.com/django/django/pull/7430
(Aside: I did also explore changing ugettext_lazy() to test as an instance of text_type. It's not totally infeasible, but would probably cause at least as many problems as it would solve. https://github.com/medmunds/django/pull/1 if you're curious.)