DataMedSci / beprof

Beam Profile Analysing Tools
MIT License
2 stars 2 forks source link

Profile.__new__() is somewhat bugged when running simple tests using Python 2.7 #99

Closed antnieszka closed 7 years ago

antnieszka commented 7 years ago

(Python 2.7.12) I started writing some tests for Profile class and this came out:

When trying to invoke main() from Profile.py with just one line added at the end Profile(). Yes, an empty call. It does not error like in Python 3.x, it gives this output:

File "/home/ant6/PycharmProjects/beprof/beprof/profile.py", line 21, in __new__
    new = super().__new__(cls, input_array, **meta)
TypeError: super() takes at least 1 argument (0 given)

Ok, let's read what people on Stack have to say... I changed this line to:

new = super(curve.Curve, cls).__new__(cls, input_array, **meta)

To give explicit class - for the record - we're in class Profile(curve.Curve). Nope, still errors...

new = super(curve.Curve, cls).__new__(cls, input_array, **meta)
TypeError: an integer is required

So I then I tried putting Profile as super's argument... like this:

new = super(Profile).__new__(cls, input_array, **meta)

and got something on the very end of this class:

File "/home/ant6/PycharmProjects/beprof/beprof/profile.py", line 159, in __str__
    ret = super().__str__()
TypeError: super() takes at least 1 argument (0 given)

at this point I just put ret = super(Profile).__str__() here. Well, now it seemed fine:

Traceback (most recent call last):
  File "/home/ant6/PycharmProjects/beprof/beprof/profile.py", line 197, in <module>
    main()
  File "/home/ant6/PycharmProjects/beprof/beprof/profile.py", line 193, in main
    Profile()
TypeError: __new__() takes at least 2 arguments (1 given)

TypeError, that is what we wanted. Or maybe expected it to be. But... now this goes totally wrong:

def main():
    print('\nProfile')
    p = Profile([[0, 0], [1, 1], [2, 2], [3, 1]],
                some='exemplary',
                meta='data')
    print(p)

gives:

Profile
<super: <class 'Profile'>, NULL>
 FWHM = 2.000

or

Profile
<super: <class 'Curve'>, NULL>
 FWHM = 2.000

if we use ret = super(curve.Curve).__str__().

It may look weird, but I when I wrote 'simple' call to Curve's __str__ (ret = curve.Curve.__str__(self)) - printing went well:

Profile
shape: (4, 2)
X : [0.000,3.000]
Y : [0.000000,2.000000]
Metadata : {'meta': 'data', 'some': 'exemplary'}
 FWHM = 2.000

Now it seems weird and all that but test pass on both Python 2.7.12 and Python 3.4 (I only have those two versions locally). You can see the diff here: https://github.com/ant6/beprof/commit/3df19431b8a365a6ad5161ec7a0e94d080d0f466

The question is - what should I do with this? Leave it with my little changes or?

antnieszka commented 7 years ago

@grzanka any advice? :)

grzanka commented 7 years ago

I need to investigate first...

antnieszka commented 7 years ago

Resolved in #110