From 8471732dc05709e2852cb215f8ee01b77f557b4c Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 15 Jan 2020 22:11:53 +0200 Subject: [PATCH 1/3] Fix for Python 4: replace unsafe six.PY3 with PY2 --- .../test_get_figure/test_get_figure.py | 2 +- .../test_get_requests/test_get_requests.py | 30 +++++++++---------- .../python/plotly/plotly/basedatatypes.py | 11 +++---- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_figure/test_get_figure.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_figure/test_get_figure.py index a2ae4ae1d6a..69b6da830c6 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_figure/test_get_figure.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_figure/test_get_figure.py @@ -99,7 +99,7 @@ def test_get_figure_raw(self): class TestBytesVStrings(PlotlyTestCase): - @skipIf(not six.PY3, "Decoding and missing escapes only seen in PY3") + @skipIf(six.PY2, "Decoding and missing escapes only seen in PY3") def test_proper_escaping(self): un = "PlotlyImageTest" ak = "786r5mecv0" diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_requests/test_get_requests.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_requests/test_get_requests.py index 7aac9ccd2c9..a57487f3107 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_requests/test_get_requests.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_requests/test_get_requests.py @@ -36,10 +36,10 @@ def test_user_does_not_exist(self): hd["plotly-apikey"] = api_key resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id) response = requests.get(server + resource, headers=hd) - if six.PY3: - content = _json.loads(response.content.decode("unicode_escape")) - else: + if six.PY2: content = _json.loads(response.content) + else: + content = _json.loads(response.content.decode("unicode_escape")) error_message = ( "Aw, snap! We don't have an account for {0}. Want to " "try again? Sign in is not case sensitive.".format(username) @@ -58,10 +58,10 @@ def test_file_does_not_exist(self): hd["plotly-apikey"] = api_key resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id) response = requests.get(server + resource, headers=hd) - if six.PY3: - content = _json.loads(response.content.decode("unicode_escape")) - else: + if six.PY2: content = _json.loads(response.content) + else: + content = _json.loads(response.content.decode("unicode_escape")) error_message = ( "Aw, snap! It looks like this file does " "not exist. Want to try again?" ) @@ -96,10 +96,10 @@ def test_private_permission_defined(self): hd["plotly-apikey"] = api_key resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id) response = requests.get(server + resource, headers=hd) - if six.PY3: - content = _json.loads(response.content.decode("unicode_escape")) - else: + if six.PY2: content = _json.loads(response.content) + else: + content = _json.loads(response.content.decode("unicode_escape")) self.assertEqual(response.status_code, 403) # Private File that is shared @@ -115,10 +115,10 @@ def test_missing_headers(self): hd = copy.copy(default_headers) del hd[header] response = requests.get(server + resource, headers=hd) - if six.PY3: - content = _json.loads(response.content.decode("unicode_escape")) - else: + if six.PY2: content = _json.loads(response.content) + else: + content = _json.loads(response.content.decode("unicode_escape")) self.assertEqual(response.status_code, 422) @attr("slow") @@ -132,10 +132,10 @@ def test_valid_request(self): hd["plotly-apikey"] = api_key resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id) response = requests.get(server + resource, headers=hd) - if six.PY3: - content = _json.loads(response.content.decode("unicode_escape")) - else: + if six.PY2: content = _json.loads(response.content) + else: + content = _json.loads(response.content.decode("unicode_escape")) self.assertEqual(response.status_code, 200) # content = _json.loads(res.content) # response_payload = content['payload'] diff --git a/packages/python/plotly/plotly/basedatatypes.py b/packages/python/plotly/plotly/basedatatypes.py index cd551fc31c7..b5a4a749f17 100644 --- a/packages/python/plotly/plotly/basedatatypes.py +++ b/packages/python/plotly/plotly/basedatatypes.py @@ -4458,11 +4458,7 @@ def __dir__(self): Custom __dir__ that handles dynamic subplot properties """ # Include any active subplot values - if six.PY3: - return list(super(BaseLayoutHierarchyType, self).__dir__()) + sorted( - self._subplotid_props - ) - else: + if six.PY2: def get_attrs(obj): import types @@ -4493,6 +4489,11 @@ def dir2(obj): return list(attrs) return dir2(self) + sorted(self._subplotid_props) + else: + + return list(super(BaseLayoutHierarchyType, self).__dir__()) + sorted( + self._subplotid_props + ) class BaseTraceHierarchyType(BasePlotlyType): From 0fd758010549b2f1cfbb51743bca3b7c2a2e0b78 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 16 Jan 2020 16:11:09 +0200 Subject: [PATCH 2/3] Fix for Python 4: do not compare sys.version_info.minor to integer --- .../chart_studio/tests/test_plot_ly/test_api/__init__.py | 2 +- .../tests/test_plot_ly/test_plotly/test_credentials.py | 2 +- .../chart_studio/tests/test_plot_ly/test_plotly/test_plot.py | 2 +- packages/python/plotly/_plotly_utils/utils.py | 2 +- .../tests/test_core/test_figure_messages/test_add_traces.py | 2 +- .../tests/test_core/test_figure_messages/test_batch_animate.py | 2 +- .../test_core/test_figure_messages/test_move_delete_traces.py | 2 +- .../tests/test_core/test_figure_messages/test_on_change.py | 2 +- .../test_core/test_figure_messages/test_plotly_relayout.py | 2 +- .../tests/test_core/test_figure_messages/test_plotly_restyle.py | 2 +- .../tests/test_core/test_figure_messages/test_plotly_update.py | 2 +- .../test_core/test_optional_imports/test_optional_imports.py | 2 +- packages/python/plotly/plotly/tests/test_io/test_renderers.py | 2 +- .../python/plotly/plotly/tests/test_io/test_to_from_json.py | 2 +- .../plotly/plotly/tests/test_orca/test_image_renderers.py | 2 +- packages/python/plotly/plotly/tests/test_orca/test_to_image.py | 2 +- packages/python/plotly/setup.py | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_api/__init__.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_api/__init__.py index 8307806d5c9..72d362744e4 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_api/__init__.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_api/__init__.py @@ -8,7 +8,7 @@ import sys # import from mock -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import patch else: from mock import patch diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_credentials.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_credentials.py index 9175f5f03e7..ac6fa75ad99 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_credentials.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_credentials.py @@ -9,7 +9,7 @@ import sys # import from mock -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import patch else: from mock import patch diff --git a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_plot.py b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_plot.py index 282666d325f..3982bde7d88 100644 --- a/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_plot.py +++ b/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_plot.py @@ -25,7 +25,7 @@ # import from mock -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import patch else: from mock import patch diff --git a/packages/python/plotly/_plotly_utils/utils.py b/packages/python/plotly/_plotly_utils/utils.py index d0d43134a48..8df6fa5be6d 100644 --- a/packages/python/plotly/_plotly_utils/utils.py +++ b/packages/python/plotly/_plotly_utils/utils.py @@ -7,7 +7,7 @@ from _plotly_utils.basevalidators import ImageUriValidator -PY36_OR_LATER = sys.version_info.major == 3 and sys.version_info.minor >= 6 +PY36_OR_LATER = sys.version_info >= (3, 6) class PlotlyJSONEncoder(_json.JSONEncoder): diff --git a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_add_traces.py b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_add_traces.py index 43eaca6381c..2322b30efa9 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_add_traces.py +++ b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_add_traces.py @@ -3,7 +3,7 @@ import plotly.graph_objs as go -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import MagicMock else: from mock import MagicMock diff --git a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_batch_animate.py b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_batch_animate.py index e3bfd1d0385..e4209fc5476 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_batch_animate.py +++ b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_batch_animate.py @@ -3,7 +3,7 @@ import plotly.graph_objs as go -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import MagicMock else: from mock import MagicMock diff --git a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py index 81aae892228..a644cf65940 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py +++ b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py @@ -4,7 +4,7 @@ import plotly.graph_objs as go -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import MagicMock else: from mock import MagicMock diff --git a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_on_change.py b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_on_change.py index abd70a97706..5f2aeb610ff 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_on_change.py +++ b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_on_change.py @@ -4,7 +4,7 @@ import plotly.graph_objs as go -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import MagicMock else: from mock import MagicMock diff --git a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_relayout.py b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_relayout.py index 31bf548896e..66db5b78481 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_relayout.py +++ b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_relayout.py @@ -3,7 +3,7 @@ import plotly.graph_objs as go -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import MagicMock else: from mock import MagicMock diff --git a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_restyle.py b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_restyle.py index 7c15fe1c18e..6cbebb467c4 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_restyle.py +++ b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_restyle.py @@ -3,7 +3,7 @@ import plotly.graph_objs as go -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import MagicMock else: from mock import MagicMock diff --git a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_update.py b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_update.py index 701942873e2..d67e7826592 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_update.py +++ b/packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_update.py @@ -4,7 +4,7 @@ import plotly.graph_objs as go from plotly.basedatatypes import Undefined -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import MagicMock else: from mock import MagicMock diff --git a/packages/python/plotly/plotly/tests/test_core/test_optional_imports/test_optional_imports.py b/packages/python/plotly/plotly/tests/test_core/test_optional_imports/test_optional_imports.py index 4cf539dc705..8646840b4cc 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_optional_imports/test_optional_imports.py +++ b/packages/python/plotly/plotly/tests/test_core/test_optional_imports/test_optional_imports.py @@ -27,7 +27,7 @@ def test_get_module_import_exception(self): # Get module that raises an exception on import module_str = "plotly.tests.test_core." "test_optional_imports.exploding_module" - if sys.version_info.major == 3 and sys.version_info.minor >= 4: + if sys.version_info >= (3, 4): with self.assertLogs("_plotly_utils.optional_imports", level="ERROR") as cm: module = get_module(module_str) diff --git a/packages/python/plotly/plotly/tests/test_io/test_renderers.py b/packages/python/plotly/plotly/tests/test_io/test_renderers.py index ee71c04cf5b..692c4efc696 100644 --- a/packages/python/plotly/plotly/tests/test_io/test_renderers.py +++ b/packages/python/plotly/plotly/tests/test_io/test_renderers.py @@ -12,7 +12,7 @@ import plotly.io as pio from plotly.offline import get_plotlyjs -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): import unittest.mock as mock from unittest.mock import MagicMock else: diff --git a/packages/python/plotly/plotly/tests/test_io/test_to_from_json.py b/packages/python/plotly/plotly/tests/test_io/test_to_from_json.py index 800f51a73d0..25c0237d992 100644 --- a/packages/python/plotly/plotly/tests/test_io/test_to_from_json.py +++ b/packages/python/plotly/plotly/tests/test_io/test_to_from_json.py @@ -6,7 +6,7 @@ import sys import os -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import MagicMock import tempfile else: diff --git a/packages/python/plotly/plotly/tests/test_orca/test_image_renderers.py b/packages/python/plotly/plotly/tests/test_orca/test_image_renderers.py index 07f1490319e..df1e268d541 100644 --- a/packages/python/plotly/plotly/tests/test_orca/test_image_renderers.py +++ b/packages/python/plotly/plotly/tests/test_orca/test_image_renderers.py @@ -10,7 +10,7 @@ from plotly.offline.offline import _get_jconfig -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): import unittest.mock as mock else: import mock diff --git a/packages/python/plotly/plotly/tests/test_orca/test_to_image.py b/packages/python/plotly/plotly/tests/test_orca/test_to_image.py index 929d9f9fc69..cf1a1a2e322 100644 --- a/packages/python/plotly/plotly/tests/test_orca/test_to_image.py +++ b/packages/python/plotly/plotly/tests/test_orca/test_to_image.py @@ -7,7 +7,7 @@ import sys import pandas as pd -if sys.version_info.major == 3 and sys.version_info.minor >= 3: +if sys.version_info >= (3, 3): from unittest.mock import MagicMock else: from mock import MagicMock diff --git a/packages/python/plotly/setup.py b/packages/python/plotly/setup.py index d2e9832c171..2a4a08c5b13 100644 --- a/packages/python/plotly/setup.py +++ b/packages/python/plotly/setup.py @@ -161,7 +161,7 @@ def finalize_options(self): pass def run(self): - if sys.version_info.major != 3 or sys.version_info.minor < 6: + if sys.version_info < (3, 6): raise ImportError("Code generation must be executed with Python >= 3.6") from codegen import perform_codegen From 4a3e0ca4605fe64eb19a95f45902639b62da5bd4 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 16 Jan 2020 07:51:14 +0200 Subject: [PATCH 3/3] Fix for Python 3.10: don't compare to sys.version string --- packages/python/plotly/_plotly_utils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/_plotly_utils/utils.py b/packages/python/plotly/_plotly_utils/utils.py index 8df6fa5be6d..19c8a37c349 100644 --- a/packages/python/plotly/_plotly_utils/utils.py +++ b/packages/python/plotly/_plotly_utils/utils.py @@ -227,7 +227,7 @@ def iso_to_plotly_time_string(iso_string): def template_doc(**names): def _decorator(func): - if sys.version[:3] != "3.2": + if not sys.version_info[:2] == (3, 2): if func.__doc__ is not None: func.__doc__ = func.__doc__.format(**names) return func