Skip to content

Commit 95fc948

Browse files
[lit] Remove Python 2 string support (#157979)
There are some code paths within lit that still check what string types are supported with the aim of being compatible with Python 2 and 3. Given LLVM's minimum Python version is 3.8 and we do not have any upstream testing for Python 2, I think we can safely drop this.
1 parent 653ed06 commit 95fc948

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -899,14 +899,8 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
899899

900900
# Replace uses of /dev/null with temporary files.
901901
if kAvoidDevNull:
902-
# In Python 2.x, basestring is the base class for all string (including unicode)
903-
# In Python 3.x, basestring no longer exist and str is always unicode
904-
try:
905-
str_type = basestring
906-
except NameError:
907-
str_type = str
908902
for i, arg in enumerate(args):
909-
if isinstance(arg, str_type) and kDevNull in arg:
903+
if isinstance(arg, str) and kDevNull in arg:
910904
f = tempfile.NamedTemporaryFile(delete=False)
911905
f.close()
912906
named_temp_files.append(f.name)

llvm/utils/lit/lit/llvm/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def with_environment(self, variable, value, append_path=False):
233233
# For paths, we should be able to take a list of them and process
234234
# all of them.
235235
paths_to_add = value
236-
if lit.util.is_string(paths_to_add):
236+
if isinstance(paths_to_add, str):
237237
paths_to_add = [paths_to_add]
238238

239239
def norm(x):
@@ -262,7 +262,7 @@ def norm(x):
262262
self.config.environment[variable] = value
263263

264264
def with_system_environment(self, variables, append_path=False):
265-
if lit.util.is_string(variables):
265+
if isinstance(variables, str):
266266
variables = [variables]
267267
for v in variables:
268268
value = os.environ.get(v)
@@ -404,7 +404,7 @@ def add_tool_substitutions(self, tools, search_dirs=None):
404404
if not search_dirs:
405405
search_dirs = [self.config.llvm_tools_dir]
406406

407-
if lit.util.is_string(search_dirs):
407+
if isinstance(search_dirs, str):
408408
search_dirs = [search_dirs]
409409

410410
tools = [x if isinstance(x, ToolSubst) else ToolSubst(x) for x in tools]

llvm/utils/lit/lit/util.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,14 @@
1313
import threading
1414

1515

16-
def is_string(value):
17-
try:
18-
# Python 2 and Python 3 are different here.
19-
return isinstance(value, basestring)
20-
except NameError:
21-
return isinstance(value, str)
22-
23-
2416
def pythonize_bool(value):
2517
if value is None:
2618
return False
2719
if type(value) is bool:
2820
return value
2921
if isinstance(value, numbers.Number):
3022
return value != 0
31-
if is_string(value):
23+
if isinstance(value, str):
3224
if value.lower() in ("1", "true", "on", "yes"):
3325
return True
3426
if value.lower() in ("", "0", "false", "off", "no"):

0 commit comments

Comments
 (0)