From 2eec7ce5d052ef1c690549b0a9e115f2a726fa18 Mon Sep 17 00:00:00 2001 From: Frazer McLean Date: Thu, 26 Mar 2026 17:19:30 +0100 Subject: [PATCH 1/3] Return NotImplemented for unsupported comparisons See https://docs.python.org/3.14/reference/datamodel.html#object.__eq__ --- plotly/basedatatypes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plotly/basedatatypes.py b/plotly/basedatatypes.py index 6821eeb8d0..ec4038b7fa 100644 --- a/plotly/basedatatypes.py +++ b/plotly/basedatatypes.py @@ -789,7 +789,7 @@ def __contains__(self, prop): def __eq__(self, other): if not isinstance(other, BaseFigure): # Require objects to both be BaseFigure instances - return False + return NotImplemented else: # Compare plotly_json representations @@ -5017,7 +5017,7 @@ def __eq__(self, other): """ if not isinstance(other, self.__class__): # Require objects to be of the same plotly type - return False + return NotImplemented else: # Compare plotly_json representations From 7a609a7fd333581ab577cc0018c95c37bbbad75d Mon Sep 17 00:00:00 2001 From: Frazer McLean Date: Fri, 27 Mar 2026 10:41:58 +0100 Subject: [PATCH 2/3] Add test --- .../test_graph_objs/test_figure_properties.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_core/test_graph_objs/test_figure_properties.py b/tests/test_core/test_graph_objs/test_figure_properties.py index d7847a5876..9676137397 100644 --- a/tests/test_core/test_graph_objs/test_figure_properties.py +++ b/tests/test_core/test_graph_objs/test_figure_properties.py @@ -1,4 +1,5 @@ from unittest import TestCase +from unittest.mock import MagicMock import pytest import plotly.graph_objs as go @@ -42,6 +43,15 @@ def test_contains(self): def test_iter(self): self.assertEqual(set(self.figure), {"data", "layout", "frames"}) + def test_unsupported_eq_returns_not_implemented(self): + other = MagicMock() + self.assertFalse(self.figure == other) + other.__eq__.assert_called_once_with(self.figure) + + other.reset_mock() + self.assertFalse(self.figure.layout == other) + other.__eq__.assert_called_once_with(self.figure.layout) + def test_attr_item(self): # test that equal objects can be retrieved using attr or item # syntax From d67290778ebaeaeee1d7dc6771cd314af1004740 Mon Sep 17 00:00:00 2001 From: Frazer McLean Date: Fri, 27 Mar 2026 10:45:01 +0100 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 941722802c..0f71737a58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Update `numpy.percentile` syntax to stop using deprecated alias [[5483](https://github.com/plotly/plotly.py/pull/5483)], with thanks to @Mr-Neutr0n for the contribution! - `numpy` with a version less than 1.22 is no longer supported. +- The `__eq__` method for `graph_objects` classes now returns `NotImplemented` to give the other operand an opportunity to handle the comparison. ## [6.6.0] - 2026-03-02