> 1. Should the result of ugettext_lazy somehow inherit from unicode? If indeed
> the "result of a ugettext_lazy() call can be used wherever you would use a
> unicode string"
I don't think making isinstance(lazy_str, unicode) return True would really fix
things, as it will probably break somewhere deeper then. In essence I think this
boils down to the other libs not duck-typing "correctly". However it is
definitely worth mentioning those limitations in the docs.
> 2. Or should my reusable app be calling force_text on /everything/ it might
> receive from its callers before passing on to other packages? Essentially
> saying, lazy strings are really only valid while inside the Django world,
> and a (currently-undocumented) responsibility of reusable apps is to convert
> all lazy strings before handing them off to other (non-Django) python code.
You don't need force_text() for that, calling str(my_lazy_str) is enough (or
six.text_type(my_lazy_str) if you want to support Python 2.7).
I think this would be actually the best duck-typing approach.
> 3. Or should I just be telling my app's users to call force_text themselves if
> they're using ugettext_lazy? (Not thrilled with this idea, as missing it can
> lead to very subtle errors. See the 'p4' example below. And this might
> warrant a clarification to "... can be used wherever you would use a unicode
> string..." in the docs.)
I don't think this error is subtle, I mean the function name tells you exactly
that it is lazy. I would say it is the responsibility of the programmer using
ugettext_lazy() to transform it to a string when using libraries that know
nothing about Django. Still, I'd say a reusable Django app should probably be
able to deal with lazy strings.
The best "fix" in my opinion is to add a note in the docs.
Moritz