In [11]: force_text(A)
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
<ipython-input-13-f9169705858c> in <module>()
----> 1 force_text(A)
.../django/utils/encoding.pyc in force_text(s, encoding, strings_only,
errors)
97 if not isinstance(s, six.string_types):
98 if hasattr(s, '__unicode__'):
---> 99 s = s.__unicode__()
100 else:
101 if six.PY3:
TypeError: unbound method __unicode__() must be called with A instance as
first argument (got nothing instead)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21019>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
https://github.com/django/django/pull/1543
--
Ticket URL: <https://code.djangoproject.com/ticket/21019#comment:1>
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
https://github.com/django/django/pull/1543
--
Ticket URL: <https://code.djangoproject.com/ticket/21019#comment:2>
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
https://code.djangoproject.com/ticket/21019
--
Ticket URL: <https://code.djangoproject.com/ticket/21019#comment:3>
* owner: nobody => drtyrsa
* needs_better_patch: => 0
* status: new => assigned
* needs_tests: => 0
* needs_docs: => 0
Comment:
https://code.djangoproject.com/ticket/21019
--
Ticket URL: <https://code.djangoproject.com/ticket/21019#comment:4>
* status: assigned => closed
* resolution: => invalid
Comment:
I think that calling `force_text` on the class itself is not a valid use
case, unless you can demonstrate the opposite.
--
Ticket URL: <https://code.djangoproject.com/ticket/21019#comment:5>
Comment (by drtyrsa):
What are valid use cases for `smart_text` then? As I understand it takes
some object and returns its str (unicode) representation. Why can not this
object be class itself?
I am using it to log the args of the function (some args can be models
classes). Isn't it valid use case?
--
Ticket URL: <https://code.djangoproject.com/ticket/21019#comment:6>
Comment (by claudep):
Currently, `force_text`/`smart_text` are meant to receive instances, not
classes. I'd say that for your specific use case, you may test your
argument before passing it to `force_text`, for example with the
`inspect.isclass` method.
--
Ticket URL: <https://code.djangoproject.com/ticket/21019#comment:7>