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 , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 10 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:3 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
PR: https://github.com/django/django/pull/4896