-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Datetime serialization and advice #5422
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
Conversation
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.
Minor comments, then LGTM
docs/dev/style.md
Outdated
``` | ||
|
||
Protobuf APIs will return "aware" `datetime` objects. JSON de-serialization will | ||
promote values to "aware" `datetime` objects upon deserialization. |
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.
Might also want to suggest that in cirq functions when we compare datetime
instances (for equality or ordering) we should compare .timestamp()
instead of comparing the datetime instances directly, since this will work for aware and naive datetimes just like serialization.
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.
wellllllllllllllll in #5301 (comment) (specifically the linked comment) the proposal was to compare the datetimes. This was in the context of dataclass-like member variables where the motivation was to mirror the behavior of the components. I suppose the tradeoffs could be different in functions where we just want it to work.
Propose adding:
Comparing (or testing equality) between "naive" and "aware"
datetime
objects throws
an exception.
If you are implementing a class that hasdatetime
member variables, delegate equality
and comparison operators to the built-indatetime
equality and comparison operators.
If you're writing a function that comparesdatetime
objects, you can defensively promote
them to "aware" objects or use their.timestamp()
properties for a comparison that will
never throw an exception.
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.
@maffoo does this sound good?
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.
SGTM
fixes quantumlib#5301 See quantumlib#5301 for motivation
fixes quantumlib#5301 See quantumlib#5301 for motivation
fixes #5301
See #5301 for motivation