pyd icon indicating copy to clipboard operation
pyd copied to clipboard

add complex class test

Open mw66 opened this issue 5 years ago • 5 comments

This is a bug report actually:

$ cat c.py

c = complex(2,-1)
h = c.__hash__();

print(c)
print(h)

# python output
$ python c.py 
(2-1j)
-2000004   # here!

however, pyd output:

$ dub build
$ ./simple_embedded 
1 + 2
(2-1j)
<method-wrapper '__hash__' of complex object at 0x7fa8c49897d0>  # here!

mw66 avatar Dec 19 '20 06:12 mw66

I just found the work around how to make the pyd call:

    auto h = c.__hash__()();

I think here we should use the python convention:

  c.__hash__;    // return the method-wrapper
  c.__hash__();  // return the result of the function call.

mw66 avatar Dec 19 '20 06:12 mw66

Ah, yeah, that's kind of annoying. I would certainly like it if I could get D to do as you suggest, but there is no way (or wasn't last time I checked, admittedly a while) to get opDispatch to distinguish between obj.property and obj.property(). So we have this kind of compromise where no parameters are treated as obj.property and presence of parameters are treated as a method call.

ariovistus avatar Dec 20 '20 03:12 ariovistus

OK, I added the work-around, so new user can follow the example to make the call.

mw66 avatar Dec 20 '20 05:12 mw66

@ariovistus: I'm a git idiot, I tried to add python39 support (which I have been used for a year without problem on my local machine), but I messed up my PR and my local branches.

It should be just a single file PR (commit hash 170ac4b) for dub.json:

https://github.com/ariovistus/pyd/pull/143/commits/170ac4b2094de249c8588a3cafd59ab6bfafc64f

If you have time, can you separate this file as a single PR and merge it, then we can have python39 support.

Thanks.

mw66 avatar Mar 10 '22 22:03 mw66

done

ariovistus avatar Mar 12 '22 16:03 ariovistus