Browse files

Py3: types.StringTypes disappeared so can't use

The doc in Py2 says that types.StringTypes is the portable
way to check for string types, but it was removed in Py3 for
some reason...
  • Loading branch information...
robnagler committed Dec 1, 2017
1 parent ce14cdd commit 813ea851adf38788d203d6caa955c22b0c4337ef
Showing with 12 additions and 3 deletions.
  1. +12 −3 pykern/
@@ -147,13 +147,22 @@ def dev():
import os
import re
import sys
import types
# These modules have very limited imports to avoid loops
from pykern import pkcollections
from pykern import pkinspect
from pykern import pkrunpy
#: Python version independent value of string instance check
# pykern uses pksetup in so requirements.txt is not yet evaluated so can't use six
# or any other external dependencies. The "types" modules in Python 2 had a StringTypes, which
# would have been great if it hadn't been removed and changed completely in Python 3.
STRING_TYPES = basestring
except NameError:
#: Name of the module (required) for a package
BASE_MODULE = '{}.base_pkconfig'
@@ -418,7 +427,7 @@ def parse_bool(value):
return False
if isinstance(value, bool):
return value
if not isinstance(value, types.StringType):
if not isinstance(value, STRING_TYPES):
return bool(value)
v = value.lower()
if v in ('t', 'true', 'y', 'yes', '1'):
@@ -720,6 +729,6 @@ def _load_path_parser(value):
if not value:
return []
if isinstance(value, types.StringTypes):
if isinstance(value, STRING_TYPES):
return value.split(LOAD_PATH_SEP)
return list(value)

0 comments on commit 813ea85

Please sign in to comment.