Skip to content

Commit ae64033

Browse files
committed
Just use six.string_types for string compatibility
1 parent 7617945 commit ae64033

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

_plotly_utils/basevalidators.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
# Optional imports
1313
# ----------------
1414
import sys
15-
16-
from _plotly_utils.compat import str_types
15+
from six import string_types
1716

1817
np = None
1918
pd = None
@@ -350,7 +349,7 @@ def __init__(self,
350349
# ----------------------------
351350
# Look for regular expressions
352351
for v in self.values:
353-
if v and isinstance(v, str_types) and v[0] == '/' and v[-1] == '/':
352+
if v and isinstance(v, string_types) and v[0] == '/' and v[-1] == '/':
354353
# String is a regex with leading and trailing '/' character
355354
regex_str = v[1:-1]
356355
self.val_regexs.append(re.compile(regex_str))
@@ -388,7 +387,7 @@ def perform_replacemenet(self, v):
388387
"""
389388
Return v with any applicable regex replacements applied
390389
"""
391-
if isinstance(v, str_types):
390+
if isinstance(v, string_types):
392391
for repl_args in self.regex_replacements:
393392
if repl_args:
394393
v = re.sub(repl_args[0], repl_args[1], v)
@@ -443,7 +442,7 @@ def in_values(self, e):
443442
"""
444443
Return whether a value matches one of the enumeration options
445444
"""
446-
is_str = isinstance(e, str_types)
445+
is_str = isinstance(e, string_types)
447446
for v, regex in zip(self.values, self.val_regexs):
448447
if is_str and regex:
449448
in_values = fullmatch(regex, e) is not None
@@ -822,7 +821,7 @@ def validate_coerce(self, v):
822821

823822
# If strict, make sure all elements are strings.
824823
if self.strict:
825-
invalid_els = [e for e in v if not isinstance(e, str_types)]
824+
invalid_els = [e for e in v if not isinstance(e, string_types)]
826825
if invalid_els:
827826
self.raise_invalid_elements(invalid_els)
828827

@@ -863,10 +862,10 @@ def validate_coerce(self, v):
863862

864863
else:
865864
if self.strict:
866-
if not isinstance(v, str_types):
865+
if not isinstance(v, string_types):
867866
self.raise_invalid_val(v)
868867
else:
869-
if not isinstance(v, str_types + (int, float)):
868+
if not isinstance(v, string_types + (int, float)):
870869
self.raise_invalid_val(v)
871870

872871
# Convert value to a string
@@ -1082,7 +1081,7 @@ def perform_validate_coerce(v, allow_number=None):
10821081
if isinstance(v, numbers.Number) and allow_number:
10831082
# If allow_numbers then any number is ok
10841083
return v
1085-
elif not isinstance(v, str_types):
1084+
elif not isinstance(v, string_types):
10861085
# If not allow_numbers then value must be a string
10871086
return None
10881087
else:
@@ -1204,7 +1203,7 @@ def validate_coerce(self, v):
12041203
pass
12051204
if v is None:
12061205
v_valid = True
1207-
elif isinstance(v, str_types):
1206+
elif isinstance(v, string_types):
12081207
v_match = [
12091208
el for el in ColorscaleValidator.named_colorscales
12101209
if el.lower() == v.lower()
@@ -1219,7 +1218,7 @@ def validate_coerce(self, v):
12191218
len(e) != 2 or
12201219
not isinstance(e[0], numbers.Number) or
12211220
not (0 <= e[0] <= 1) or
1222-
not isinstance(e[1], str_types) or
1221+
not isinstance(e[1], string_types) or
12231222
ColorValidator.perform_validate_coerce(e[1]) is None)]
12241223

12251224
if len(invalid_els) == 0:
@@ -1338,7 +1337,7 @@ def description(self):
13381337
def validate_coerce(self, v):
13391338
if v is None:
13401339
pass
1341-
elif not isinstance(v, str_types):
1340+
elif not isinstance(v, string_types):
13421341
self.raise_invalid_val(v)
13431342
else:
13441343
# match = re.fullmatch(self.regex, v)
@@ -1420,7 +1419,7 @@ def description(self):
14201419
return desc
14211420

14221421
def vc_scalar(self, v):
1423-
if not isinstance(v, str_types):
1422+
if not isinstance(v, string_types):
14241423
return None
14251424

14261425
# To be generous we accept flags separated on plus ('+'),
@@ -1661,7 +1660,7 @@ def description(self):
16611660
def validate_coerce(self, v):
16621661
if v is None:
16631662
pass
1664-
elif isinstance(v, str_types):
1663+
elif isinstance(v, string_types):
16651664
# Future possibilities:
16661665
# - Detect filesystem system paths and convert to URI
16671666
# - Validate either url or data uri

_plotly_utils/compat.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)