These are chat archives for dropbox/pyston

8th
Aug 2015
Sun
@Daetalus
Aug 08 2015 08:24

Hi, I know it is weekend now. But could I ask one more question please?

How to let the subclass of `complex has correct tp_name. Now the subclass of complex always is complex. I cross-compared float and complex code, but still don't know where cause the error.

Kevin Modzelewski
@kmod
Aug 08 2015 08:27
how does that show up?
just messing with it on the REPL seems to give the right results
Sun
@Daetalus
Aug 08 2015 08:36
class complex0(complex):
    """Test usage of __complex__() when inheriting from 'complex'"""
    def __complex__(self):
        return 42j
c0 = complex0(1j)
print(type(c0))
<type 'complex'>

Either my new implementation of complexNew, or the master branch complexNew with commented RELEASE_ASSERT(_cls == complex_cls, ""); will output same result.

PS: _cls check should use isSubclass.

Kevin Modzelewski
@kmod
Aug 08 2015 09:09
are you sure that c0 is actually a complex0 object?
maybe the tp_name is right but __new__ is wrong?
you could try doing print type(c0) is complex0, type(c0) is complex
I think we had this issue with strNew recently
Sun
@Daetalus
Aug 08 2015 09:50
print(type(c0) is complex0, type(c0) is complex)
# CPython
(True, False)
# Pyston
(False, True)
Kevin Modzelewski
@kmod
Aug 08 2015 09:52
yeah, sounds like we get complexNew wrong
I think we have this same bug with floatNew and some other ones
Sun
@Daetalus
Aug 08 2015 09:53
Acctually, floatNew seems correct...
class Foo(float):
    pass

bar = Foo()
print(type(bar) is float, type(bar) is Foo)
The output of Pyston was same as CPython
Kevin Modzelewski
@kmod
Aug 08 2015 09:54
oh ok
do you have this in a branch?
Sun
@Daetalus
Aug 08 2015 09:57
Not commit yet. Due to this issue, I can't pass the complex which is a complex subclass that have custom __complex__.
^can't pass the complex test
Kevin Modzelewski
@kmod
Aug 08 2015 09:59
hmm well it's a bit hard to try to guess without seeing what you changed
if you want to just put it on a branch (you don't have to submit a pr for it yet) I'd be happy to take a look
did you make sure to create the object as new (cls) BoxedComplex()?
Sun
@Daetalus
Aug 08 2015 10:00
Got it. Next time I will commit the code before I ask.
Kevin Modzelewski
@kmod
Aug 08 2015 10:01
you don't have to block the question on that, but it can be nice if we can't figure it out :)
Sun
@Daetalus
Aug 08 2015 10:02
Sorry, I didn't understand the last message. What does new (cls) BoxedComplex() mean?
Which I did is just like original one ' return new BoxedComplex(real_f, imag_f);
' return new BoxedComplex(real_f, imag_f);`
Kevin Modzelewski
@kmod
Aug 08 2015 10:03
without that (cls) part it default to setting the class complex_cls
basically it's the way to tell operator new() what the class of the object is
Sun
@Daetalus
Aug 08 2015 10:03
Ok, I will try it
Kevin Modzelewski
@kmod
Aug 08 2015 10:04
so the extra (cls) is actually allocation-arguments rather than constructor-arguments
and we need to pass the class to the allocation so that we know how much memory to allocate
Sun
@Daetalus
Aug 08 2015 10:04
I think that is the problem...
Kevin Modzelewski
@kmod
Aug 08 2015 10:04
if you don't specify one, it has a default
which for BoxedComplex is complex_cls (and for BoxedInt is int_cls, etc)
this is what the DEFAULT_CLASS(int_cls) annotations in the C++ class definitions are for
Sun
@Daetalus
Aug 08 2015 10:06
Got it, I will write it done...
Thanks @kmod , solved! It's my mistake, I just compared _floatNew with complexNew. Thanks for your time!
Kevin Modzelewski
@kmod
Aug 08 2015 10:11
glad I could help!
thanks for all the improvements :)
Sun
@Daetalus
Aug 08 2015 10:12
You are welcome. Have a good night!