Opened 10 years ago

Closed 9 years ago

#25000 closed Bug (fixed)

Implement default __str__ and similar for lazy() objects

Reported by: Marten Kenbeek Owned by: Marten Kenbeek
Component: Utilities Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently __str__ returns the string representation of the proxied object only if one of the resultclasses is a string-like object. Otherwise, it returns the pretty much useless <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7fac6332ffd0>.

str(lazy_object) should return the same as str(non_lazy_object). This is easily achievable by providing a default __str__() method on __proxy__:

class __proxy__(Promise):
    def __str__(self):
        return str(self.__cast())

This behaviour would still be overridden for string-like lazy objects. The same could be implemented for bytes() and unicode().

Change History (4)

comment:1 by Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Marten Kenbeek, 10 years ago

Has patch: set
Owner: changed from nobody to Marten Kenbeek
Status: newassigned

comment:3 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 290ff35:

Fixed #25000 -- Fixed cast to string for lazy objects.

Implemented str() to return the string-representation of the
proxied object, not the proxy itself, if the lazy object didn't have
a string-like object in its resultclasses.

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