[Django] #26287: SimpleLazyObject doesn't implement __radd__

44 views
Skip to first unread message

Django

unread,
Feb 27, 2016, 7:06:21 AM2/27/16
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-----------------------------+--------------------
Reporter: kezabelle | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------
Technically, there's a whole bunch of magic methods it doesn't implement,
compared to a ''complete'' proxy implementation, like that of
`wrapt.ObjectProxy`, but `__radd__` being missing is the one that's biting
me at the moment.

As far as I can tell, the implementation can't just be
{{{
__radd__ = new_method_proxy(operator.radd)
}}}
because that doesn't exist, which is rubbish.
{{{
__radd__ = new_method_proxy(operator.attrgetter("__radd__"))
}}}
also won't work because types may not have that attr, and attrgetter
doesn't supress the exception (correctly)

The minimal implementation I've found that works for me is:
{{{

def __radd__(self, other):
if self._wrapped is empty:
self._setup()
return other + self._wrapped
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26287>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 27, 2016, 8:03:13 AM2/27/16
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-----------------------------+--------------------------------------

Reporter: kezabelle | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Could you please give some sample code with your use case?

--
Ticket URL: <https://code.djangoproject.com/ticket/26287#comment:1>

Django

unread,
Feb 27, 2016, 11:15:07 AM2/27/16
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-----------------------------+--------------------------------------

Reporter: kezabelle | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by kezabelle):

In a boiled-down nutshell:
{{{
def lazy_consumer():
# something more complex, obviously.
return [1, 3, 5]
consumer = SimpleLazyObject(lazy_consumer)

# inside third party code ...
def some_func(param):
third_party_code = [...]
# then, through parameter passing, my value is provided to be used.
# param is at this point, `consumer`
third_party_code_plus_mine = third_party_code + param
}}}

which ultimately yields:
{{{
TypeError: unsupported operand type(s) for +: 'list' and
'SimpleLazyObject'
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26287#comment:2>

Django

unread,
Mar 1, 2016, 10:51:36 AM3/1/16
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-----------------------------+------------------------------------

Reporter: kezabelle | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


Comment:

Seems okay, although I'm not an expert on the `SimpleLazyObject` class.

--
Ticket URL: <https://code.djangoproject.com/ticket/26287#comment:3>

Django

unread,
Mar 3, 2016, 8:12:34 AM3/3/16
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-----------------------------+------------------------------------

Reporter: kezabelle | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by Uran198):

Replying to [comment:2 kezabelle]:


> {{{
> def lazy_consumer():
> # something more complex, obviously.
> return [1, 3, 5]
> consumer = SimpleLazyObject(lazy_consumer)
> }}}

If you know what is the resulting type or possible resulting types of your
expression, I think you better use `django.utils.functional.lazy` which
will provide all the necessary methods.

--
Ticket URL: <https://code.djangoproject.com/ticket/26287#comment:4>

Django

unread,
Jul 5, 2016, 3:50:54 PM7/5/16
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-----------------------------+------------------------------------

Reporter: kezabelle | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by debanshuk):

Replying to [ticket:26287 kezabelle]:


> As far as I can tell, the implementation can't just be
> {{{
> __radd__ = new_method_proxy(operator.radd)
> }}}
> because that doesn't exist, which is rubbish.
> {{{
> __radd__ = new_method_proxy(operator.attrgetter("__radd__"))
> }}}
> also won't work because types may not have that attr, and attrgetter
doesn't supress the exception (correctly)

Wouldn't the following code work?

{{{
__add__ = new_method_proxy(operator.add)
__radd__ = new_method_proxy(lambda a, b: operator.add(b, a))
}}}

I have tested this and it seems to work as excepted.

--
Ticket URL: <https://code.djangoproject.com/ticket/26287#comment:5>

Django

unread,
Jul 5, 2016, 4:36:31 PM7/5/16
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-----------------------------+------------------------------------

Reporter: kezabelle | Owner: nobody
Type: New feature | Status: new
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by debanshuk):

* cc: debanshuk2007@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/26287#comment:6>

Django

unread,
Feb 5, 2022, 2:05:01 PM2/5/22
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Theofilos
| Alexiou
Type: New feature | Status: assigned
Component: Utilities | Version: dev

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Theofilos Alexiou):

* owner: nobody => Theofilos Alexiou
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/26287#comment:7>

Django

unread,
Feb 5, 2022, 2:44:37 PM2/5/22
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Theofilos
| Alexiou
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Theofilos Alexiou):

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


Comment:

PR here: [https://github.com/django/django/pull/15400]. Tried the
suggestion by @Debanshu Kundu and it seems to work.

--
Ticket URL: <https://code.djangoproject.com/ticket/26287#comment:8>

Django

unread,
Feb 7, 2022, 12:07:21 AM2/7/22
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Theofilos
| Alexiou
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Ready for checkin => Accepted


Comment:

RFC should be set by reviewer, see
[https://docs.djangoproject.com/en/stable/internals/contributing/triaging-
tickets/#ready-for-checkin docs].

--
Ticket URL: <https://code.djangoproject.com/ticket/26287#comment:9>

Django

unread,
Feb 10, 2022, 5:27:21 AM2/10/22
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Theofilos
| Alexiou
Type: New feature | Status: assigned
Component: Utilities | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26287#comment:10>

Django

unread,
Feb 10, 2022, 7:06:16 AM2/10/22
to django-...@googlegroups.com
#26287: SimpleLazyObject doesn't implement __radd__
-------------------------------------+-------------------------------------
Reporter: Keryn Knight | Owner: Theofilos
| Alexiou
Type: New feature | Status: closed
Component: Utilities | Version: dev
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"f9ec777a826816e20e68021c0e73b5a76be650af" f9ec777a]:
{{{
#!CommitTicketReference repository=""
revision="f9ec777a826816e20e68021c0e73b5a76be650af"
Fixed #26287 -- Added support for addition operations to SimpleLazyObject.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26287#comment:11>

Reply all
Reply to author
Forward
0 new messages