-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[BEAM-3761]Fix Python 3 cmp usage #4774
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
[BEAM-3761]Fix Python 3 cmp usage #4774
Conversation
|
cc @aaltay |
|
cc @robertwb |
| # pylint: enable=ungrouped-imports | ||
|
|
||
|
|
||
| @deprecated(since="v2.4") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we deprecating these functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So they encourage cmp like behaviour and I didn't see them used internally. This is as a separate commit, I can keep them non-deprecated and just use the rewrite for the internal cmp usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are in the public API surface, it may have users. Let's not deprecate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the counterargument see What's new in Python 3: The cmp() function should be treated as gone, and the __cmp__() special method is no longer supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not follow the counterargument. These two are static functions for comparing datastore keys and paths. Providing these functions should be orthogonal to having cmp functions in the language or not. We can deprecate this if we think that they do not provide value to users, but the decision should not depend on the availability of cmp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can avoid deprecating them for now and revisit it later.
| return (type(self) is type(other) and | ||
| self.timestamped_values == other.timestamped_values) | ||
|
|
||
| def __ne__(self, other): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to implement ne, is not this the default implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@holdenk what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Python3 we are fine but in Python 2.7, ne isn't inherited from object. If you see the docs for total_ordering. See the notes in https://bugs.python.org/issue25732
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
|
|
||
| from abc import ABCMeta | ||
| from abc import abstractmethod | ||
| from functools import total_ordering |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we compare these events?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping?
| def __ne__(self, other): | ||
| return not self.__eq__(other) | ||
|
|
||
| def __lt__(self, other): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a type mismatch should return NotImplemented here, or raise an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable, I'll try that.
|
|
||
| def __eq__(self, other): | ||
| return self.start == other.start and self.end == other.end | ||
| return type(self) == type(other) and \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about type mismatch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put the whole test in parens and avoid backslash line termination as recommended in PEP8? The problem with backslash line termination is that a whitespace character to the right of the backslash breaks the script but is invisible to the reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
| def __eq__(self, other): | ||
| return self.value == other.value and self.timestamp == other.timestamp | ||
|
|
||
| def __hash_(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to implement this? Also there is a typo in the name __hash_.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess its not needed then :) I'll remove it.
| """ | ||
| if type(left) is not type(right): | ||
| return cmp(type(left), type(right)) | ||
| return 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change in behaviour even though it matches the comment above. What does this affect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the tests pass. If you were to sort a windowed value with something which was not a windowed value the ordering could change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
cc: @robertwb since this pertains to the todo below.
|
@holdenk Is this ready to review again? Github comment threading is confusing, I cannot always tell if all comments received a response or not. |
|
I need to fix the multi-line ''s I think. I'm busy dealing with some internal company stuff (it turns out I like getting paid) and this week is Strata SJ so I'll try and update this Tuesday night. |
|
ok cc @aaltay |
cclauss
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
8d36869 to
89f757a
Compare
|
@holdenk I still see that datastore helper methods are being deprecated. I thought we decided not to do that. Also there is an open question to you in |
|
So the open "test_stream" issue, you pinged someone else on it for comment? Or is there another one? |
|
Removed the deprecation as well, sorry about that. cc @aaltay |
|
I can merge it once tests are green. For some reason, tests were not completed yet after a day. |
|
retest this please |
…ed as performance important so please take a look, but this should be strictly a perf improvement.
…and it encourages cmp like behaviour.
…sn't seem to be used.
43b9c66 to
cd98dae
Compare
|
CC @aaltay |
|
@holdenk do you know why tests are failing before we merge? |
|
There seems to be a failure installing cython==0.26.1... The current cython on PyPI is 0.28.1 |
|
@cclauss perhaps it is a flake with installation? 0.26.1 is also available on pypi even though it is not the latest version. |
|
Also getting this error :( |
|
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@beam.apache.org list. Thank you for your contributions. |
|
This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time. |
Fixes our usage of cmp as part of Python 3 port. In some places where cmp was not being used remove the function entirely, in others rewrite to use total_ordering annotation.
Follow this checklist to help us incorporate your contribution quickly and easily:
[BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replaceBEAM-XXXwith the appropriate JIRA issue.mvn clean verifyto make sure basic checks pass. A more thorough check will be performed on your pull request automatically. (ran python tests instead)