Skip to content

Commit 66c7847

Browse files
authored
Merge pull request #1726 from anders-kiaer/future_remove
Remove `future`, `__future__` and `py2/py3`
2 parents d21a365 + 825bf8a commit 66c7847

File tree

19 files changed

+21
-79
lines changed

19 files changed

+21
-79
lines changed

components/dash-core-components/dash_core_components_base/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function as _
2-
31
import json
42
import os as _os
53
import sys as _sys

components/dash-core-components/dash_core_components_base/express.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
import io
22
import ntpath
33
import base64
4-
from functools import partial
5-
6-
# Py2 StringIO.StringIO handles unicode but io.StringIO doesn't
7-
try:
8-
from StringIO import StringIO as _StringIO
9-
10-
py2 = True
11-
except ImportError:
12-
_StringIO = io.StringIO
13-
py2 = False
144

155
# region Utils for Download component
166

@@ -56,7 +46,7 @@ def send_string(src, filename, type=None, **kwargs):
5646
:param type: type of the file (optional, passed to Blob in the javascript layer)
5747
:return: dict of data frame content (NOT base64 encoded) and meta data used by the Download component
5848
"""
59-
content = src if isinstance(src, str) else _io_to_str(_StringIO(), src, **kwargs)
49+
content = src if isinstance(src, str) else _io_to_str(io.StringIO(), src, **kwargs)
6050
return dict(content=content, filename=filename, type=type, base64=False)
6151

6252

@@ -110,7 +100,7 @@ def send_data_frame(writer, filename, type=None, **kwargs):
110100
"to_parquet": send_bytes,
111101
"to_msgpack": send_bytes,
112102
"to_stata": send_bytes,
113-
"to_pickle": partial(send_bytes, compression=None) if py2 else send_bytes,
103+
"to_pickle": send_bytes,
114104
}
115105

116106
# endregion

components/dash-html-components/dash_html_components_base/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Vanilla HTML components for Dash"""
22

3-
from __future__ import print_function as _
43
from ._imports_ import * # noqa: E402, F401, F403
54
from ._imports_ import __all__ # noqa: E402
65

components/dash-table/dash_table_base/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function
2-
31
import os as _os
42
import sys as _sys
53
import json

dash/_utils.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
32
import shlex
43
import sys
54
import uuid
@@ -10,15 +9,10 @@
109
import io
1110
import json
1211
from functools import wraps
13-
from future import utils
1412
from . import exceptions
1513

1614
logger = logging.getLogger()
1715

18-
# py2/3 json.dumps-compatible strings - these are equivalent in py3, not in py2
19-
# note because we import unicode_literals u"" and "" are both unicode
20-
_strings = (type(""), type(utils.bytes_to_native_str(b"")))
21-
2216

2317
def to_json(value):
2418
# pylint: disable=import-outside-toplevel
@@ -109,7 +103,7 @@ def strip_relative_path(requests_pathname, path):
109103

110104
# pylint: disable=no-member
111105
def patch_collections_abc(member):
112-
return getattr(collections if utils.PY2 else collections.abc, member)
106+
return getattr(collections.abc, member)
113107

114108

115109
class AttributeDict(dict):

dash/_validate.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ._grouping import grouping_len, map_grouping
66
from .development.base_component import Component
77
from . import exceptions
8-
from ._utils import patch_collections_abc, _strings, stringify_id
8+
from ._utils import patch_collections_abc, stringify_id
99

1010

1111
def validate_callback(outputs, inputs, state, extra_args, types):
@@ -41,7 +41,7 @@ def validate_callback(outputs, inputs, state, extra_args, types):
4141

4242

4343
def validate_callback_arg(arg):
44-
if not isinstance(getattr(arg, "component_property", None), _strings):
44+
if not isinstance(getattr(arg, "component_property", None), str):
4545
raise exceptions.IncorrectTypeException(
4646
dedent(
4747
"""
@@ -61,7 +61,7 @@ def validate_callback_arg(arg):
6161
if isinstance(arg.component_id, dict):
6262
validate_id_dict(arg)
6363

64-
elif isinstance(arg.component_id, _strings):
64+
elif isinstance(arg.component_id, str):
6565
validate_id_string(arg)
6666

6767
else:
@@ -81,7 +81,7 @@ def validate_id_dict(arg):
8181
# Need to keep key type validation on the Python side, since
8282
# non-string keys will be converted to strings in json.dumps and may
8383
# cause unwanted collisions
84-
if not isinstance(k, _strings):
84+
if not isinstance(k, str):
8585
raise exceptions.IncorrectTypeException(
8686
dedent(
8787
"""
@@ -198,7 +198,7 @@ def validate_multi_return(outputs_list, output_value, callback_id):
198198

199199

200200
def fail_callback_output(output_value, output):
201-
valid = _strings + (dict, int, float, type(None), Component)
201+
valid = (str, dict, int, float, type(None), Component)
202202

203203
def _raise_invalid(bad_val, outer_val, path, index=None, toplevel=False):
204204
bad_type = type(bad_val).__name__

dash/dash.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function
2-
31
import os
42
import sys
53
import collections
@@ -13,8 +11,7 @@
1311
import mimetypes
1412
import hashlib
1513
import base64
16-
17-
from future.moves.urllib.parse import urlparse
14+
from urllib.parse import urlparse
1815

1916
import flask
2017
from flask_compress import Compress

dash/dash_table/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function
2-
31
import os as _os
42
import sys as _sys
53
import json

dash/dcc/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function as _
2-
31
import json
42
import os as _os
53
import sys as _sys

dash/dcc/express.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
import io
22
import ntpath
33
import base64
4-
from functools import partial
5-
6-
# Py2 StringIO.StringIO handles unicode but io.StringIO doesn't
7-
try:
8-
from StringIO import StringIO as _StringIO
9-
10-
py2 = True
11-
except ImportError:
12-
_StringIO = io.StringIO
13-
py2 = False
144

155
# region Utils for Download component
166

@@ -56,7 +46,7 @@ def send_string(src, filename, type=None, **kwargs):
5646
:param type: type of the file (optional, passed to Blob in the javascript layer)
5747
:return: dict of data frame content (NOT base64 encoded) and meta data used by the Download component
5848
"""
59-
content = src if isinstance(src, str) else _io_to_str(_StringIO(), src, **kwargs)
49+
content = src if isinstance(src, str) else _io_to_str(io.StringIO(), src, **kwargs)
6050
return dict(content=content, filename=filename, type=type, base64=False)
6151

6252

@@ -110,7 +100,7 @@ def send_data_frame(writer, filename, type=None, **kwargs):
110100
"to_parquet": send_bytes,
111101
"to_msgpack": send_bytes,
112102
"to_stata": send_bytes,
113-
"to_pickle": partial(send_bytes, compression=None) if py2 else send_bytes,
103+
"to_pickle": send_bytes,
114104
}
115105

116106
# endregion

0 commit comments

Comments
 (0)