Skip to content

Commit 14ca5b6

Browse files
committed
remove all to_string
1 parent fa490a6 commit 14ca5b6

File tree

4 files changed

+6
-47
lines changed

4 files changed

+6
-47
lines changed

llvm/utils/lit/lit/builtin_commands/diff.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import sys
99

1010
import util
11-
from util import to_string
1211

1312

1413
class DiffFlags:
@@ -67,10 +66,9 @@ def compareTwoBinaryFiles(flags, filepaths, filelines):
6766
filepaths[1].encode(),
6867
n=flags.num_context_lines,
6968
)
70-
diffs = [diff.decode(errors="backslashreplace") for diff in diffs]
7169

7270
for diff in diffs:
73-
sys.stdout.write(to_string(diff))
71+
sys.stdout.write(diff.decode(errors="backslashreplace"))
7472
exitCode = 1
7573
return exitCode
7674

@@ -117,7 +115,7 @@ def compose2(f, g):
117115
filepaths[1],
118116
n=flags.num_context_lines,
119117
):
120-
sys.stdout.write(to_string(diff))
118+
sys.stdout.write(diff)
121119
exitCode = 1
122120
return exitCode
123121

llvm/utils/lit/lit/formats/googletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_num_tests(self, path, litConfig, localConfig):
4343
return None
4444
return sum(
4545
map(
46-
lambda line: lit.util.to_string(line).startswith(" "),
46+
lambda line: line.decode("utf-8", errors="replace").startswith(" "),
4747
out.splitlines(False),
4848
)
4949
)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _find_git_windows_unix_tools(self, tools_needed):
223223
continue
224224

225225
# We found it, stop enumerating.
226-
return lit.util.to_string(candidate_path)
226+
return candidate_path
227227
except:
228228
continue
229229

@@ -284,8 +284,8 @@ def get_process_output(self, command):
284284
env=self.config.environment,
285285
)
286286
stdout, stderr = cmd.communicate()
287-
stdout = lit.util.to_string(stdout)
288-
stderr = lit.util.to_string(stderr)
287+
stdout = stdout.decode("utf-8", errors="replace")
288+
stderr = stderr.decode("utf-8", errors="replace")
289289
return (stdout, stderr)
290290
except OSError:
291291
self.lit_config.fatal("Could not run process %s" % command)

llvm/utils/lit/lit/util.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,45 +50,6 @@ def to_bytes(s):
5050
return s.encode("utf-8")
5151

5252

53-
def to_string(b):
54-
"""Return the parameter as type 'str', possibly encoding it.
55-
56-
In Python2, the 'str' type is the same as 'bytes'. In Python3, the
57-
'str' type is (essentially) Python2's 'unicode' type, and 'bytes' is
58-
distinct.
59-
60-
"""
61-
if isinstance(b, str):
62-
# In Python2, this branch is taken for types 'str' and 'bytes'.
63-
# In Python3, this branch is taken only for 'str'.
64-
return b
65-
if isinstance(b, bytes):
66-
# In Python2, this branch is never taken ('bytes' is handled as 'str').
67-
# In Python3, this is true only for 'bytes'.
68-
try:
69-
return b.decode("utf-8")
70-
except UnicodeDecodeError:
71-
# If the value is not valid Unicode, return the default
72-
# repr-line encoding.
73-
return str(b)
74-
75-
# By this point, here's what we *don't* have:
76-
#
77-
# - In Python2:
78-
# - 'str' or 'bytes' (1st branch above)
79-
# - In Python3:
80-
# - 'str' (1st branch above)
81-
# - 'bytes' (2nd branch above)
82-
#
83-
# The last type we might expect is the Python2 'unicode' type. There is no
84-
# 'unicode' type in Python3 (all the Python3 cases were already handled). In
85-
# order to get a 'str' object, we need to encode the 'unicode' object.
86-
try:
87-
return b.encode("utf-8")
88-
except AttributeError:
89-
raise TypeError("not sure how to convert %s to %s" % (type(b), str))
90-
91-
9253
def usable_core_count():
9354
"""Return the number of cores the current process can use, if supported.
9455
Otherwise, return the total number of cores (like `os.cpu_count()`).

0 commit comments

Comments
 (0)