Skip to content

Fix for Python 4 #2078

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

Merged
merged 3 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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?"
)
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/python/plotly/_plotly_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions packages/python/plotly/plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/python/plotly/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down