Skip to content

Commit 7f6713f

Browse files
hugovkemmanuelle
authored andcommitted
Fix for Python 4 (#2078)
* Fix for Python 4: replace unsafe six.PY3 with PY2 * Fix for Python 4: do not compare sys.version_info.minor to integer * Fix for Python 3.10: don't compare to sys.version string
1 parent fc226f7 commit 7f6713f

File tree

20 files changed

+40
-39
lines changed

20 files changed

+40
-39
lines changed

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_api/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sys
99

1010
# import from mock
11-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
11+
if sys.version_info >= (3, 3):
1212
from unittest.mock import patch
1313
else:
1414
from mock import patch

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_figure/test_get_figure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_get_figure_raw(self):
9999

100100

101101
class TestBytesVStrings(PlotlyTestCase):
102-
@skipIf(not six.PY3, "Decoding and missing escapes only seen in PY3")
102+
@skipIf(six.PY2, "Decoding and missing escapes only seen in PY3")
103103
def test_proper_escaping(self):
104104
un = "PlotlyImageTest"
105105
ak = "786r5mecv0"

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_get_requests/test_get_requests.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def test_user_does_not_exist(self):
3636
hd["plotly-apikey"] = api_key
3737
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
3838
response = requests.get(server + resource, headers=hd)
39-
if six.PY3:
40-
content = _json.loads(response.content.decode("unicode_escape"))
41-
else:
39+
if six.PY2:
4240
content = _json.loads(response.content)
41+
else:
42+
content = _json.loads(response.content.decode("unicode_escape"))
4343
error_message = (
4444
"Aw, snap! We don't have an account for {0}. Want to "
4545
"try again? Sign in is not case sensitive.".format(username)
@@ -58,10 +58,10 @@ def test_file_does_not_exist(self):
5858
hd["plotly-apikey"] = api_key
5959
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
6060
response = requests.get(server + resource, headers=hd)
61-
if six.PY3:
62-
content = _json.loads(response.content.decode("unicode_escape"))
63-
else:
61+
if six.PY2:
6462
content = _json.loads(response.content)
63+
else:
64+
content = _json.loads(response.content.decode("unicode_escape"))
6565
error_message = (
6666
"Aw, snap! It looks like this file does " "not exist. Want to try again?"
6767
)
@@ -96,10 +96,10 @@ def test_private_permission_defined(self):
9696
hd["plotly-apikey"] = api_key
9797
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
9898
response = requests.get(server + resource, headers=hd)
99-
if six.PY3:
100-
content = _json.loads(response.content.decode("unicode_escape"))
101-
else:
99+
if six.PY2:
102100
content = _json.loads(response.content)
101+
else:
102+
content = _json.loads(response.content.decode("unicode_escape"))
103103
self.assertEqual(response.status_code, 403)
104104

105105
# Private File that is shared
@@ -115,10 +115,10 @@ def test_missing_headers(self):
115115
hd = copy.copy(default_headers)
116116
del hd[header]
117117
response = requests.get(server + resource, headers=hd)
118-
if six.PY3:
119-
content = _json.loads(response.content.decode("unicode_escape"))
120-
else:
118+
if six.PY2:
121119
content = _json.loads(response.content)
120+
else:
121+
content = _json.loads(response.content.decode("unicode_escape"))
122122
self.assertEqual(response.status_code, 422)
123123

124124
@attr("slow")
@@ -132,10 +132,10 @@ def test_valid_request(self):
132132
hd["plotly-apikey"] = api_key
133133
resource = "/apigetfile/{0}/{1}/".format(file_owner, file_id)
134134
response = requests.get(server + resource, headers=hd)
135-
if six.PY3:
136-
content = _json.loads(response.content.decode("unicode_escape"))
137-
else:
135+
if six.PY2:
138136
content = _json.loads(response.content)
137+
else:
138+
content = _json.loads(response.content.decode("unicode_escape"))
139139
self.assertEqual(response.status_code, 200)
140140
# content = _json.loads(res.content)
141141
# response_payload = content['payload']

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_credentials.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import sys
1010

1111
# import from mock
12-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
12+
if sys.version_info >= (3, 3):
1313
from unittest.mock import patch
1414
else:
1515
from mock import patch

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_plotly/test_plot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
# import from mock
28-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
28+
if sys.version_info >= (3, 3):
2929
from unittest.mock import patch
3030
else:
3131
from mock import patch

packages/python/plotly/_plotly_utils/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from _plotly_utils.basevalidators import ImageUriValidator
88

99

10-
PY36_OR_LATER = sys.version_info.major == 3 and sys.version_info.minor >= 6
10+
PY36_OR_LATER = sys.version_info >= (3, 6)
1111

1212

1313
class PlotlyJSONEncoder(_json.JSONEncoder):
@@ -227,7 +227,7 @@ def iso_to_plotly_time_string(iso_string):
227227

228228
def template_doc(**names):
229229
def _decorator(func):
230-
if sys.version[:3] != "3.2":
230+
if not sys.version_info[:2] == (3, 2):
231231
if func.__doc__ is not None:
232232
func.__doc__ = func.__doc__.format(**names)
233233
return func

packages/python/plotly/plotly/basedatatypes.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -4458,11 +4458,7 @@ def __dir__(self):
44584458
Custom __dir__ that handles dynamic subplot properties
44594459
"""
44604460
# Include any active subplot values
4461-
if six.PY3:
4462-
return list(super(BaseLayoutHierarchyType, self).__dir__()) + sorted(
4463-
self._subplotid_props
4464-
)
4465-
else:
4461+
if six.PY2:
44664462

44674463
def get_attrs(obj):
44684464
import types
@@ -4493,6 +4489,11 @@ def dir2(obj):
44934489
return list(attrs)
44944490

44954491
return dir2(self) + sorted(self._subplotid_props)
4492+
else:
4493+
4494+
return list(super(BaseLayoutHierarchyType, self).__dir__()) + sorted(
4495+
self._subplotid_props
4496+
)
44964497

44974498

44984499
class BaseTraceHierarchyType(BasePlotlyType):

packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_add_traces.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import plotly.graph_objs as go
55

6-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
6+
if sys.version_info >= (3, 3):
77
from unittest.mock import MagicMock
88
else:
99
from mock import MagicMock

packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_batch_animate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import plotly.graph_objs as go
55

6-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
6+
if sys.version_info >= (3, 3):
77
from unittest.mock import MagicMock
88
else:
99
from mock import MagicMock

packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import plotly.graph_objs as go
66

7-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
7+
if sys.version_info >= (3, 3):
88
from unittest.mock import MagicMock
99
else:
1010
from mock import MagicMock

packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_on_change.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import plotly.graph_objs as go
66

7-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
7+
if sys.version_info >= (3, 3):
88
from unittest.mock import MagicMock
99
else:
1010
from mock import MagicMock

packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_relayout.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import plotly.graph_objs as go
55

6-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
6+
if sys.version_info >= (3, 3):
77
from unittest.mock import MagicMock
88
else:
99
from mock import MagicMock

packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_restyle.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import plotly.graph_objs as go
55

6-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
6+
if sys.version_info >= (3, 3):
77
from unittest.mock import MagicMock
88
else:
99
from mock import MagicMock

packages/python/plotly/plotly/tests/test_core/test_figure_messages/test_plotly_update.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import plotly.graph_objs as go
55
from plotly.basedatatypes import Undefined
66

7-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
7+
if sys.version_info >= (3, 3):
88
from unittest.mock import MagicMock
99
else:
1010
from mock import MagicMock

packages/python/plotly/plotly/tests/test_core/test_optional_imports/test_optional_imports.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_get_module_import_exception(self):
2727
# Get module that raises an exception on import
2828
module_str = "plotly.tests.test_core." "test_optional_imports.exploding_module"
2929

30-
if sys.version_info.major == 3 and sys.version_info.minor >= 4:
30+
if sys.version_info >= (3, 4):
3131
with self.assertLogs("_plotly_utils.optional_imports", level="ERROR") as cm:
3232
module = get_module(module_str)
3333

packages/python/plotly/plotly/tests/test_io/test_renderers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import plotly.io as pio
1313
from plotly.offline import get_plotlyjs
1414

15-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
15+
if sys.version_info >= (3, 3):
1616
import unittest.mock as mock
1717
from unittest.mock import MagicMock
1818
else:

packages/python/plotly/plotly/tests/test_io/test_to_from_json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
import os
88

9-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
9+
if sys.version_info >= (3, 3):
1010
from unittest.mock import MagicMock
1111
import tempfile
1212
else:

packages/python/plotly/plotly/tests/test_orca/test_image_renderers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from plotly.offline.offline import _get_jconfig
1212

13-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
13+
if sys.version_info >= (3, 3):
1414
import unittest.mock as mock
1515
else:
1616
import mock

packages/python/plotly/plotly/tests/test_orca/test_to_image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88
import pandas as pd
99

10-
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
10+
if sys.version_info >= (3, 3):
1111
from unittest.mock import MagicMock
1212
else:
1313
from mock import MagicMock

packages/python/plotly/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def finalize_options(self):
161161
pass
162162

163163
def run(self):
164-
if sys.version_info.major != 3 or sys.version_info.minor < 6:
164+
if sys.version_info < (3, 6):
165165
raise ImportError("Code generation must be executed with Python >= 3.6")
166166

167167
from codegen import perform_codegen

0 commit comments

Comments
 (0)