[issue30469] Inconsistent Execution of Generic Descriptor Attributes

2017-05-24 Thread Ryan Morshead

New submission from Ryan Morshead:

When the `__get__`, `__set__`, or `__delete__` attribute of a descriptor is not 
a method, and is instead a generic callable, the first argument of that 
callable is inconsistent:


class Callable(object):

def __call__(self, first, *args, **kwargs):
print(first)


class Descriptor(object):

__set__ = Callable()
__delete__ = Callable()
__get__ = Callable()


class MyClass(object):

d = Descriptor()


mc = MyClass()
mc.d = 1
del mc.d
mc.d


Prints:


<__main__.MyClass object at 0x10854cda0>
<__main__.MyClass object at 0x10854cda0>
<__main__.Descriptor object at 0x10855f240>


As it turns out, this occurs because `slot_tp_descr_set` (shared by `__set__` 
and `__delete__`) and `slot_tp_descr_get` just aren't consistent in their 
implementation.

See: 
https://stackoverflow.com/questions/44169370/strange-descriptor-behavior/44169805#44169805

Is this behavior intentional? If not, how ought this case be handled?

--
components: ctypes
messages: 294415
nosy: Ryan Morshead
priority: normal
severity: normal
status: open
title: Inconsistent Execution of Generic Descriptor Attributes
type: behavior
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue30469>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30469] Inconsistent Execution of Generic Descriptor Attributes

2017-05-24 Thread Ryan Morshead

Ryan Morshead added the comment:

Is there a reason that `call_method` is not used in `slot_tp_descr_get`

--

___
Python tracker 
<http://bugs.python.org/issue30469>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com