Skip to content

Commit cf2cfe9

Browse files
committed
ruff --ignore=SIM108
1 parent 8245d1f commit cf2cfe9

File tree

7 files changed

+58
-16
lines changed

7 files changed

+58
-16
lines changed

tools/building.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,10 @@ def eval_ctors(js_file, wasm_file, debug_info):
425425
if kept_ctors:
426426
args += ['--kept-exports=' + ','.join(kept_ctors)]
427427
else:
428-
ctor = '_start' if settings.EXPECT_MAIN else '_initialize'
428+
if settings.EXPECT_MAIN:
429+
ctor = '_start'
430+
else:
431+
ctor = '_initialize'
429432
args = ['--ctors=' + ctor, '--kept-exports=' + ctor]
430433
if settings.EVAL_CTORS == 2:
431434
args += ['--ignore-external-input']

tools/emscripten.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,10 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat
346346

347347
for em_js_func, raw in metadata.em_js_funcs.items():
348348
c_sig = raw.split('<::>')[0].strip('()')
349-
c_sig = [] if (c_sig or 'void') == 'void' else c_sig.split(',')
349+
if not c_sig or c_sig == 'void':
350+
c_sig = []
351+
else:
352+
c_sig = c_sig.split(',')
350353
if em_js_func in import_map:
351354
imp = import_map[em_js_func]
352355
assert imp.kind == webassembly.ExternType.FUNC
@@ -643,8 +646,11 @@ def create_tsd_exported_runtime_methods(metadata):
643646
tsc_output_file = in_temp('jsdoc.d.ts')
644647
utils.write_file(js_doc_file, js_doc)
645648
tsc = shutil.which('tsc')
646-
# Use the full path from the which command so windows can find tsc.
647-
tsc = [tsc] if tsc else shared.get_npm_cmd('tsc')
649+
if tsc:
650+
# Use the full path from the which command so windows can find tsc.
651+
tsc = [tsc]
652+
else:
653+
tsc = shared.get_npm_cmd('tsc')
648654
cmd = tsc + ['--outFile', tsc_output_file, '--declaration', '--emitDeclarationOnly', '--allowJs', js_doc_file]
649655
shared.check_call(cmd, cwd=path_from_root())
650656
return utils.read_file(tsc_output_file)
@@ -752,7 +758,10 @@ def create_em_js(metadata):
752758
assert separator in raw
753759
args, body = raw.split(separator, 1)
754760
args = args[1:-1]
755-
args = [] if args == 'void' else args.split(',')
761+
if args == 'void':
762+
args = []
763+
else:
764+
args = args.split(',')
756765
arg_names = [arg.split()[-1].replace('*', '') for arg in args if arg]
757766
args = ','.join(arg_names)
758767
func = f'function {name}({args}) {body}'

tools/maint/gen_struct_info.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ def generate_cmd(js_file_path, src_file_path, cflags):
242242
# Compile the program.
243243
show('Compiling generated code...')
244244

245-
compiler = shared.EMXX if any('libcxxabi' in f for f in cflags) else shared.EMCC
245+
if any('libcxxabi' in f for f in cflags):
246+
compiler = shared.EMXX
247+
else:
248+
compiler = shared.EMCC
246249

247250
node_flags = building.get_emcc_node_flags(shared.check_node_version())
248251

tools/minimal_runtime_shell.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ def generate_minimal_runtime_load_statement(target_basename):
159159
else:
160160
script_load = "script(url).then(() => URL.revokeObjectURL(url));"
161161

162-
save_js = f'{settings.EXPORT_NAME}.js = ' if settings.WASM_WORKERS else ''
162+
if settings.WASM_WORKERS:
163+
save_js = f'{settings.EXPORT_NAME}.js = '
164+
else:
165+
save_js = ''
163166

164167
files_to_load[0] = f"binary('{target_basename}.js')"
165168
if not settings.MODULARIZE:

tools/system_libs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,10 @@ def build_objects(self, build_dir):
502502
case_insensitive = is_case_insensitive(build_dir)
503503
for src in self.get_files():
504504
ext = shared.suffix(src)
505-
cmd = shared.EMCC if ext in {'.s', '.S', '.c'} else shared.EMXX
505+
if ext in {'.s', '.S', '.c'}:
506+
cmd = shared.EMCC
507+
else:
508+
cmd = shared.EMXX
506509
cmd = [cmd, '-c']
507510
if ext == '.s':
508511
# .s files are processed directly by the assembler. In this case we can't pass

tools/webassembly.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,10 @@ def get_segments(self):
486486
num_segments = self.read_uleb()
487487
for _ in range(num_segments):
488488
flags = self.read_uleb()
489-
init = None if flags & SEG_PASSIVE else self.read_init()
489+
if (flags & SEG_PASSIVE):
490+
init = None
491+
else:
492+
init = self.read_init()
490493
size = self.read_uleb()
491494
offset = self.tell()
492495
segments.append(DataSegment(flags, init, offset, size))

tools/webidl_binder.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,10 @@ def render_function(class_name, func_name, sigs, return_type, non_pointer,
438438
args = [(all_args[i].identifier.name if isinstance(all_args[i], WebIDL.IDLArgument) else ('arg%d' % i)) for i in range(max_args)]
439439
if not constructor and not is_static:
440440
body = ' var self = this.ptr;\n'
441-
pre_arg = ['BigInt(self)'] if options.wasm64 else ['self']
441+
if options.wasm64:
442+
pre_arg = ['BigInt(self)']
443+
else:
444+
pre_arg = ['self']
442445
else:
443446
body = ''
444447
pre_arg = []
@@ -457,10 +460,16 @@ def is_ptr_arg(i):
457460
compatible_arg = isinstance(arg, Dummy) or (isinstance(arg, WebIDL.IDLArgument) and arg.optional is False)
458461
# note: null has typeof object, but is ok to leave as is, since we are calling into asm code where null|0 = 0
459462
if not legacy_mode and compatible_arg:
460-
arg_name = arg.identifier.name if isinstance(arg, WebIDL.IDLArgument) else ''
463+
if isinstance(arg, WebIDL.IDLArgument):
464+
arg_name = arg.identifier.name
465+
else:
466+
arg_name = ''
461467
# Format assert fail message
462468
check_msg = "[CHECK FAILED] %s::%s(%s:%s): " % (class_name, func_name, js_arg, arg_name)
463-
inner = arg.type.inner if isinstance(arg.type, WebIDL.IDLWrapperType) else ''
469+
if isinstance(arg.type, WebIDL.IDLWrapperType):
470+
inner = arg.type.inner
471+
else:
472+
inner = ""
464473

465474
# Print type info in comments.
466475
body += " /* %s <%s> [%s] */\n" % (js_arg, arg.type.name, inner)
@@ -539,7 +548,10 @@ def make_call_args(i):
539548

540549
for i in range(min_args, max_args):
541550
c_names[i] = f'emscripten_bind_{bindings_name}_{i}'
542-
after_call = '' if 'return ' in call_prefix else f'; {cache}return'
551+
if 'return ' in call_prefix:
552+
after_call = ''
553+
else:
554+
after_call = '; ' + cache + 'return'
543555
args_for_call = make_call_args(i)
544556
body += ' if (%s === undefined) { %s_%s(%s)%s%s }\n' % (args[i], call_prefix, c_names[i],
545557
args_for_call,
@@ -551,7 +563,10 @@ def make_call_args(i):
551563
if cache:
552564
body += f' {cache}\n'
553565

554-
declare_name = f' {func_name}' if constructor else ''
566+
if constructor:
567+
declare_name = ' ' + func_name
568+
else:
569+
declare_name = ''
555570
mid_js.append(r'''function%s(%s) {
556571
%s
557572
};
@@ -586,8 +601,11 @@ def make_call_args(i):
586601
else:
587602
if not bind_to:
588603
bind_to = func_name
589-
call = f'{bind_to}({call_args})'
590-
call = f'{c_class_name}::{call}' if is_static else f'self->{call}'
604+
call = bind_to + '(' + call_args + ')'
605+
if is_static:
606+
call = c_class_name + '::' + call
607+
else:
608+
call = 'self->' + call
591609

592610
if operator:
593611
cast_self = 'self'

0 commit comments

Comments
 (0)