You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updated the __eq__ implementations to return NotImplemented instead of False when comparing against an unsupported type. This aligns with Python's data model and allows the other operand to handle the comparison.
Hi @RazerM, thanks for the contribution, and thanks for your patience awaiting review!
I'm trying to make sure I understand the consequences of this change.
It seems that by returning NotImplemented, we would be allowing the possibility for other objects to declare themselves equal to a BaseFigure (or BasePlotlyType) object, if they choose.
I'm having trouble thinking of a scenario where that would be helpful. It's possibly something that could be useful to us internally within plotly.py, but we haven't encountered a need for it yet to my knowledge. Do you have a scenario on your end that would benefit from this change?
we would be allowing the possibility for other objects to declare themselves equal to a BaseFigure (or BasePlotlyType) object, if they choose.
Yes, but they can already do that as long as they're on the LHS. plotly should return NotImplemented so that equality is symmetric (A == B means B == A).
Some use cases are:
a test helper such that I can do e.g. assert figure == snapshot. The snapshot object would serialize to a snapshot file if it does not exist, or if it does deserialize it and then return the comparison result. Right now I have to do assert snapshot == figure.
SQL query builders etc. overload __eq__. E.g. imagine I have an SQLAlchemy type which can serialize figures. This should work symmetrically:
select().where(my_figure == MyModel.figure) # right now this is `.where(False)`!
select().where(MyModel.figure == my_figure)
we would be allowing the possibility for other objects to declare themselves equal to a BaseFigure (or BasePlotlyType) object, if they choose.
Yes, but they can already do that as long as they're on the LHS. plotly should return NotImplemented so that equality is symmetric (A == B means B == A).
Good point, that's a solid argument in favor. Thanks for the other examples as well. I'll approve!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue
Closes #5546
Description of change
Updated the
__eq__implementations to returnNotImplementedinstead ofFalsewhen comparing against an unsupported type. This aligns with Python's data model and allows the other operand to handle the comparison.Demo
N/A
Testing strategy
Additional information (optional)
https://docs.python.org/3.14/reference/datamodel.html#object.__eq__
Guidelines