Skip to content

IronPython handles descriptor replacement differently than CPython #843

@mickp

Description

@mickp

If a type is patched with a descriptor, referencing the name on the type (rather than an instance) hits the descriptor's getter/setter, where it does not in CPython.

class SomeDescriptor(object):
    def __get__(self, obj, obj_type=None):
        print('__get__', self, obj, obj_type)
        return self

    def __set__(self, obj, value):
        print('__set__', self, obj, value)
        return self


class Thing(object):
    @property
    def value(self):
        return 123


original_property = Thing.value
Thing.value = SomeDescriptor()
Thing.value = original_property
print(Thing().value)

CPython gives:

123

while IronPython gives

('__set__', <SomeDescriptor object at 0x000000000000006C>, None, <property object at 0x000000000000006D>)
('__get__', <SomeDescriptor object at 0x000000000000006C>, <Thing object at 0x000000000000006E>, <class '__main__.Thing'>)
<SomeDescriptor object at 0x000000000000006C>

Version info:
IronPython 2.7.12 (2.7.12.1000)
[.NETFramework,Version=v4.5 on .NET Framework 4.8.9232.0 (64-bit)]

Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)] on win32

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions