Skip to content

More Python3 lint fixes #32967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions unittests/Reflection/RemoteMirrorInterop/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
#
# Invoke by passing the various Swift build directories as parameters.

from __future__ import print_function

import itertools
import os
import subprocess
import sys

args = sys.argv[1:]
if len(args) == 0:
print >> sys.stderr, "Usage:", sys.argv[0], "swift-build-dirs..."
print >> sys.stderr, ("Note: pass paths to the swift-macosx-x86_64"
" directories, or /usr to test the OS.")
print("Usage:", sys.argv[0], "swift-build-dirs...", file=sys.stderr)
print(("Note: pass paths to the swift-macosx-x86_64"
" directories, or /usr to test the OS."), file=sys.stderr)
sys.exit(1)

absoluteArgs = [os.path.abspath(arg) for arg in args]
Expand Down Expand Up @@ -63,8 +65,8 @@ def libPath(path):
dylibPath = os.path.join('/tmp', 'libtest' + str(i) + '.dylib')
callArgs.append(dylibPath)
callArgs += list(localMirrorlibs)
print ' '.join(callArgs)
print(' '.join(callArgs))
subprocess.call(callArgs)
print 'DONE'
print ''
print localMirrorlibs
print('DONE')
print('')
print(localMirrorlibs)
27 changes: 16 additions & 11 deletions utils/api_checker/sdk-module-lists/infer-imports.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python -u

from __future__ import print_function

import os
import sys

Expand Down Expand Up @@ -63,14 +65,17 @@ def get_frameworks(sdk_path, swift_frameworks_only):

if not os.path.exists(header_dir_path):
if os.path.exists(module_dir_path):
print >>sys.stderr, header_dir_path, \
" non-existent while 'Modules' exists"
print(header_dir_path,
" non-existent while 'Modules' exists",
file=sys.stderr)
if os.path.exists(old_modulemap_path):
print >>sys.stderr, header_dir_path, \
" non-existent while 'module.map' exists"
print(header_dir_path,
" non-existent while 'module.map' exists",
file=sys.stderr)
if os.path.exists(old_modulemap_private_path):
print >>sys.stderr, header_dir_path, \
" non-existent while 'module_private.map' exists"
print(header_dir_path,
" non-existent while 'module_private.map' exists",
file=sys.stderr)
continue

if should_exclude_framework(frameworks_path + '/' + frame):
Expand Down Expand Up @@ -110,14 +115,14 @@ def should_exclude_framework(frame_path):
def print_clang_imports(frames, use_hash):
for name in frames:
if use_hash:
print "#import <" + name + "/" + name + ".h>"
print("#import <" + name + "/" + name + ".h>")
else:
print "@import " + name + ";"
print("@import " + name + ";")


def print_swift_imports(frames):
for name in frames:
print "import " + name
print("import " + name)


def main():
Expand Down Expand Up @@ -161,14 +166,14 @@ def main():
frames = get_frameworks(opts.sdk, opts.swift_frameworks_only)
if opts.v:
for name in frames:
print >>sys.stderr, 'Including: ', name
print('Including: ', name, file=sys.stderr)
if opts.out_mode == "clang-import":
print_clang_imports(frames, opts.use_hash)
elif opts.out_mode == "swift-import":
print_swift_imports(frames)
elif opts.out_mode == "list":
for name in frames:
print name
print(name)
else:
parser.error(
"output mode not found: 'clang-import'/'swift-import'/'list'")
Expand Down
6 changes: 3 additions & 3 deletions utils/build_swift/tests/build_swift/test_driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def _parse_args(self, args):
try:
return migration.parse_args(self.parser, args)
except (SystemExit, ValueError) as e:
raise ParserError('failed to parse arguments: {}'.format(
raise ParserError('failed to parse arguments: {} {}'.format(
six.text_type(args), e))

def _check_impl_args(self, namespace):
Expand All @@ -353,7 +353,7 @@ def _check_impl_args(self, namespace):
constants.BUILD_SCRIPT_IMPL_PATH,
namespace.build_script_impl_args)
except (SystemExit, ValueError) as e:
raise ParserError('failed to parse impl arguments: {}'.format(
raise ParserError('failed to parse impl arguments: {} {}'.format(
six.text_type(namespace.build_script_impl_args), e))

def parse_args_and_unknown_args(self, args, namespace=None):
Expand All @@ -369,7 +369,7 @@ def parse_args_and_unknown_args(self, args, namespace=None):
migration._process_disambiguation_arguments(
namespace, unknown_args))
except (SystemExit, argparse.ArgumentError) as e:
raise ParserError('failed to parse arguments: {}'.format(
raise ParserError('failed to parse arguments: {} {}'.format(
six.text_type(args), e))

return namespace, unknown_args
Expand Down
19 changes: 10 additions & 9 deletions utils/lldb/lldbCheckExpect.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Expected value : 98
Actual value : ...
'''
from __future__ import print_function


def unwrap(s):
Expand Down Expand Up @@ -55,7 +56,7 @@ def unwrap(s):
def on_check_expect(frame, bp_loc, session):
parent_frame = frame.get_parent_frame()
parent_name = parent_frame.GetFunctionName()
print "Evaluating check-expect in", parent_name
print("Evaluating check-expect in", parent_name)

# Note: If we fail to stringify the arguments in the check-expect frame,
# the standard library has probably not been compiled with debug info.
Expand All @@ -69,25 +70,25 @@ def on_check_expect(frame, bp_loc, session):
expr_result = parent_frame.FindVariable(var_name).GetObjectDescription()
eval_result = unwrap(str(expr_result))

print " Checked variable:", var_name
print " Expected value :", expected_value
print " Actual value :", eval_result
print(" Checked variable:", var_name)
print(" Expected value :", expected_value)
print(" Actual value :", eval_result)

if eval_result == expected_value:
# Do not stop execution.
return False

print "Found a possible expression evaluation failure."
print("Found a possible expression evaluation failure.")

for i, (c1, c2) in enumerate(zip(expected_value, eval_result)):
if c1 == c2:
continue
print " -> Character difference at index", i
print " -> Expected", c1, "but found", c2
print(" -> Character difference at index", i)
print(" -> Expected", c1, "but found", c2)
break
else:
print " -> Expected string has length", len(expected_value)
print " -> Actual string has length", len(eval_result)
print(" -> Expected string has length", len(expected_value))
print(" -> Actual string has length", len(eval_result))
return True


Expand Down
3 changes: 2 additions & 1 deletion utils/lldb/lldbToolBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
This will also import LLVM data formatters as well, assuming that llvm is next
to the swift checkout.
"""
from __future__ import print_function

import argparse
import os
Expand Down Expand Up @@ -108,7 +109,7 @@ def sequence(debugger, command, exec_ctx, result, internal_dict):
ret = lldb.SBCommandReturnObject()
interpreter.HandleCommand(subcommand, exec_ctx, ret)
if ret.GetOutput():
print >>result, ret.GetOutput().strip()
print(ret.GetOutput().strip(), file=result)

if not ret.Succeeded():
result.SetError(ret.GetError())
Expand Down
6 changes: 3 additions & 3 deletions utils/scale-test
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def Nelder_Mead_simplex(objective, params, bounds, epsilon=1.0e-6):
locs = [tuple(random.uniform(*b) for b in bounds)
for _ in range(ndim + 1)]
SimplexPoint = namedtuple("SimplexPoint", ["loc", "val"])
simplex = [SimplexPoint(loc=l, val=f(l)) for l in locs]
simplex = [SimplexPoint(loc=loc, val=f(loc)) for loc in locs]

# Algorithm parameters
alpha = 1.0
Expand Down Expand Up @@ -337,8 +337,8 @@ def Nelder_Mead_simplex(objective, params, bounds, epsilon=1.0e-6):

# 6. Shrink
simplex = (simplex[:1] +
[SimplexPoint(loc=l, val=f(l))
for l in [tup_add(xb, tup_mul(sigma, tup_sub(p.loc, xb)))
[SimplexPoint(loc=L, val=f(L))
for L in [tup_add(xb, tup_mul(sigma, tup_sub(p.loc, xb)))
for p in simplex[1:]]])


Expand Down
9 changes: 6 additions & 3 deletions utils/swift-api-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ def print_command(cmd, outfile=""):
# Dump the API for the given module.


def dump_module_api((cmd, extra_dump_args, output_dir, module, quiet,
verbose)):
def dump_module_api_star(pack):
dump_module_api(*pack)


def dump_module_api(cmd, extra_dump_args, output_dir, module, quiet, verbose):
# Collect the submodules
submodules = collect_submodules(cmd, module)

Expand Down Expand Up @@ -341,7 +344,7 @@ def main():

# Execute the API dumps
pool = multiprocessing.Pool(processes=args.jobs)
pool.map(dump_module_api, jobs)
pool.map(dump_module_api_star, jobs)

# Remove the .swift file we fed into swift-ide-test
subprocess.call(['rm', '-f', source_filename])
Expand Down
6 changes: 3 additions & 3 deletions utils/type-layout-fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
def randomTypeList(depth):
count = random.randint(0, maxMembers)
result = "("
for i in xrange(count):
for i in range(count):
if i > 0:
result += ", "
result += randomTypeReference(depth + 1)
Expand Down Expand Up @@ -81,7 +81,7 @@ def leaf():

def defineRandomFields(depth, basename):
numMembers = random.randint(0, maxMembers)
for i in xrange(numMembers):
for i in range(numMembers):
print(" var " + basename + str(i) + ": " +
randomTypeReference(depth + 1))

Expand Down Expand Up @@ -141,7 +141,7 @@ def enum():
print("enum " + name + " {")

numCases = random.randint(0, maxMembers)
for i in xrange(numCases):
for i in range(numCases):
print(" case x" + str(i) + randomTypeList(depth + 1))

print("}")
Expand Down