Opened 12 years ago

Closed 12 years ago

#4541 closed (fixed)

gettext_lazy doesn't work with __cmp__

Reported by: Favo <favo@…> Owned by: Adrian Holovaty
Component: Tools Version: master
Severity: Keywords:
Cc: favo@…, Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


if you compare two gettext_lazy objects, will raise error:

from django.utils.translation import gettext_lazy as _
assert _("value") == _("value")
Traceback (most recent call last):
  File "", line 3, in ?
    assert _("value1") == _("value2")
  File "/lib/django/django/utils/", line 43, in __wrapper__
    return self.__dispatch[type(res)][funcname](res, *args, **kw)
KeyError: '__cmp__'

Not sure there's easy way to fix. Because the lazy object try to wrapper all function, and store them in a __dispatch dict. the __dispatch come from type.__dict__. But str.__dict__ do not contain __cmp__. This will not a issue if unicode branch merged, since unicode.__dict__ contain __cmp__.

Currently I just call str() to across the issue:

assert str(_("value")) == _("value")

Change History (1)

comment:1 Changed 12 years ago by Simon G. <dev@…>

Resolution: fixed
Status: newclosed

So.. this should be fixed now since the unicode branch merge?

Note: See TracTickets for help on using tickets.
Back to Top