Opened 17 years ago

Closed 17 years ago

#4541 closed (fixed)

gettext_lazy doesn't work with __cmp__

Reported by: Favo <favo@…> Owned by: Adrian Holovaty
Component: Tools Version: dev
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

Description

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 "testlazy.py", line 3, in ?
    assert _("value1") == _("value2")
  File "/lib/django/django/utils/functional.py", 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 by Simon G. <dev@…>, 17 years ago

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