pyd: implementing __hash__ and __str__ for PyD wrapped classes
harfel via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Apr 5 05:35:21 PDT 2017
On Wednesday, 5 April 2017 at 11:39:47 UTC, Nicholas Wilson wrote:
> On Wednesday, 5 April 2017 at 09:31:09 UTC, harfel wrote:
>> Dear all,
>>
>> [...]
>>
>> Following the documentation and code examples, I got the basic
>> functionality working. However, I am struggling with
>> implementing the magic functions __str__ and __hash__ of the
>> extension class. >> Is there a way to declare these slots in
>> PyD? I noticed that Repr does this for __repr__ and the
>> operator overloads do this of course for their respective
>> slots, but I could not find anything for __hash__ and __str__.
>>
>> [...]
>
> I haven't chased the source but most likely __hash__ and
> __str__ will be "magically" generated from toHash() and
> toString() respectively (both methods of Object,
> see:https://dlang.org/phobos/object.html#.Object).
Unfortunately, this does not seem to be the case, as my D classes
do override
toHash and toString, but they are not called by the corresponding
python classes.
More information about the Digitalmars-d-learn
mailing list