Skip to content

Commit 98226d1

Browse files
rodrigcrvagg
authored andcommitted
gyp: replace basestring with str, but only on Python 3.
On Python 2, basestring is (unicode, str). On Python 3, basestring and unicode are gone, and there is only str.
1 parent 7535e44 commit 98226d1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

gyp/pylib/gyp/MSVSSettings.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from __future__ import print_function
1818

19+
from gyp import string_types
20+
1921
import sys
2022
import re
2123

@@ -108,11 +110,11 @@ class _String(_Type):
108110
"""A setting that's just a string."""
109111

110112
def ValidateMSVS(self, value):
111-
if not isinstance(value, basestring):
113+
if not isinstance(value, string_types):
112114
raise ValueError('expected string; got %r' % value)
113115

114116
def ValidateMSBuild(self, value):
115-
if not isinstance(value, basestring):
117+
if not isinstance(value, string_types):
116118
raise ValueError('expected string; got %r' % value)
117119

118120
def ConvertToMSBuild(self, value):
@@ -124,11 +126,11 @@ class _StringList(_Type):
124126
"""A settings that's a list of strings."""
125127

126128
def ValidateMSVS(self, value):
127-
if not isinstance(value, basestring) and not isinstance(value, list):
129+
if not isinstance(value, string_types) and not isinstance(value, list):
128130
raise ValueError('expected string list; got %r' % value)
129131

130132
def ValidateMSBuild(self, value):
131-
if not isinstance(value, basestring) and not isinstance(value, list):
133+
if not isinstance(value, string_types) and not isinstance(value, list):
132134
raise ValueError('expected string list; got %r' % value)
133135

134136
def ConvertToMSBuild(self, value):

gyp/pylib/gyp/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
import traceback
1717
from gyp.common import GypError
1818

19+
try:
20+
# Python 2
21+
string_types = basestring
22+
except NameError:
23+
# Python 3
24+
string_types = str
25+
1926
# Default debug modes for GYP
2027
debug = {}
2128

@@ -412,7 +419,7 @@ def gyp_main(args):
412419
for option, value in sorted(options.__dict__.items()):
413420
if option[0] == '_':
414421
continue
415-
if isinstance(value, basestring):
422+
if isinstance(value, string_types):
416423
DebugOutput(DEBUG_GENERAL, " %s: '%s'", option, value)
417424
else:
418425
DebugOutput(DEBUG_GENERAL, " %s: %s", option, value)

0 commit comments

Comments
 (0)