We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Currently, samples.Timestamp implementation for comparisons is:
samples.Timestamp
def __gt__(self, other: "Timestamp") -> bool: return self.sec > other.sec or self.nsec > other.nsec def __lt__(self, other: "Timestamp") -> bool: return self.sec < other.sec or self.nsec < other.nsec
what might not compare correctly. Example:
>>> a = Timestamp(2, 5) >>> b = Timestamp(3, 4) >>> a > b True
In the example, the first part is 2<3, what is false, forcing to perform the next part, what is 5>4, returning True.
2<3
5>4
True
A good implementation could be:
def __gt__(self, other: "Timestamp") -> bool: if self.sec == other.sec: return self.nsec > other.nsec return self.sec > other.sec def __lt__(self, other: "Timestamp") -> bool: if self.sec == other.sec: return self.nsec < other.nsec return self.sec < other.sec
Another option, perhaps even better, is to rely on python's tuples implementation:
def __gt__(self, other: "Timestamp") -> bool: return (self.sec, self.nsec) > (other.sec, other.nsec) def __lt__(self, other: "Timestamp") -> bool: return (self.sec, self.nsec) < (other.sec, other.nsec)
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Currently,
samples.Timestamp
implementation for comparisons is:what might not compare correctly. Example:
In the example, the first part is
2<3
, what is false, forcing to perform the next part, what is5>4
, returningTrue
.A good implementation could be:
Another option, perhaps even better, is to rely on python's tuples implementation:
The text was updated successfully, but these errors were encountered: