Code

Opened 7 years ago

Closed 7 years ago

#4541 closed (fixed)

gettext_lazy doesn't work with __cmp__

Reported by: Favo <favo@…> Owned by: adrian
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: UI/UX:

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")

Attachments (0)

Change History (1)

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to fixed
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.