Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Python 3 regressions #71

Merged
merged 1 commit into from
Oct 21, 2016
Merged

Conversation

dirk-thomas
Copy link
Member

@dirk-thomas dirk-thomas commented Oct 19, 2016

Regressions from #63.

@eric-wieser FYI

@@ -226,6 +228,9 @@ def to_time(self):
"""
return self.to_sec()

def __hash__(self):
return super(Time, self).__hash__()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these needed? Doesn't the base class provide them>

Copy link
Member Author

@dirk-thomas dirk-thomas Oct 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is needed.

Copy link
Contributor

@eric-wieser eric-wieser Oct 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, clearly the base class does provide them, because we're calling super!

What I meant to say, is why do we need to overload them? This works just fine for me in python 2.7 and 3.5

class Base(object):
    def __hash__(self):
        return 4

class Derived(Base): pass

class DerivedWithOverride(Base):
    def __hash__(self):
        return super(DerivedWithOverride, self).__hash__()

assert hash(Base()) == hash(DerivedWithOverride()) == hash(Derived()) == 4

So what exactly is adding these lines trying to fix?

Copy link
Member Author

@dirk-thomas dirk-thomas Oct 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't work for me in the case of the Duration and Time classes. You can try to remove them from this patch and it should fail with:

TypeError: 'NoneType' object is not callable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me the full traceback?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traceback (most recent call last):
  File "/home/dthomas/ros/kinetic/github/ros/genpy/test/test_genpy_rostime.py", line 180, in test_Time
    self.test_TVal(TVal=Time, test_neg=False)
  File "/home/dthomas/ros/kinetic/github/ros/genpy/test/test_genpy_rostime.py", line 61, in test_TVal
    self.assertEquals(v.__hash__(), TVal(0, 0).__hash__())
TypeError: 'NoneType' object is not callable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see it now. Something weird seems to be happening, so in the absence of knowing the reason, reintroducing these lines makes sense!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for drawing my attention to this, and sorry for the bad patch before. In case you're interested, the minimal case is http://stackoverflow.com/q/40186509/102441

@@ -180,7 +180,9 @@ def __ne__(self, other):
def __cmp__(self, other):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably the real issue here is implementing __cmp__ in python 3 at all. If cmp doesn't exist, then __cmp__ will never be called. So I don't understand what this patch is fixing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what the issue is - the implementation of __lt__ delegates to __cmp__

@dirk-thomas dirk-thomas merged commit e176e70 into kinetic-devel Oct 21, 2016
@dirk-thomas dirk-thomas deleted the fix_python3_regressions branch October 21, 2016 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants