[
https://issues.apache.org/jira/browse/BEAM-3761?focusedWorklogId=80469&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-80469
]
ASF GitHub Bot logged work on BEAM-3761:
----------------------------------------
Author: ASF GitHub Bot
Created on: 14/Mar/18 19:05
Start Date: 14/Mar/18 19:05
Worklog Time Spent: 10m
Work Description: holdenk commented on a change in pull request #4774:
[BEAM-3761]Fix Python 3 cmp usage
URL: https://github.com/apache/beam/pull/4774#discussion_r174577680
##########
File path: sdks/python/apache_beam/testing/test_stream.py
##########
@@ -46,44 +46,65 @@ class Event(object):
__metaclass__ = ABCMeta
- def __cmp__(self, other):
- if type(self) is not type(other):
- return cmp(type(self), type(other))
- return self._typed_cmp(other)
-
- @abstractmethod
- def _typed_cmp(self, other):
- raise NotImplementedError
-
+@total_ordering
class ElementEvent(Event):
"""Element-producing test stream event."""
def __init__(self, timestamped_values):
self.timestamped_values = timestamped_values
- def _typed_cmp(self, other):
- return cmp(self.timestamped_values, other.timestamped_values)
+ def __eq__(self, other):
+ return (type(self) is type(other) and
+ self.timestamped_values == other.timestamped_values)
+
+ def __ne__(self, other):
Review comment:
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
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 80469)
Time Spent: 5h 20m (was: 5h 10m)
> Fix Python 3 cmp function
> -------------------------
>
> Key: BEAM-3761
> URL: https://issues.apache.org/jira/browse/BEAM-3761
> Project: Beam
> Issue Type: Improvement
> Components: sdk-py-core
> Reporter: holdenk
> Priority: Major
> Time Spent: 5h 20m
> Remaining Estimate: 0h
>
> Various functions don't exist in Python 3 that did in python 2. This Jira is
> to fix the use of cmp (which often will involve rewriting __cmp__ as well).
>
> Note: there are existing PRs for basestring and unicode (
> [https://github.com/apache/beam/pull/4697|https://github.com/apache/beam/pull/4697,]
> , [https://github.com/apache/beam/pull/4730] )
>
> Note once all of the missing names/functions are fixed we can enable F821 in
> falke8 python 3.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)