Skip to content

Commit aa0d115

Browse files
committed
Use := where possible
1 parent fa99a79 commit aa0d115

18 files changed

Lines changed: 25 additions & 50 deletions

File tree

‎bfg9000/backends/msbuild/syntax.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ def basename(path):
263263
name = i['name']
264264
c = func(name, i['options'])
265265

266-
prefix = prefixes[basename(name.path)]
267-
if prefix:
266+
if prefix := prefixes[basename(name.path)]:
268267
# If this prefix is shared with another file, strip it out to
269268
# create a unique directory to store this object file.
270269
suffix = path.Path(name.path.relpath(prefix)).stripext('.obj')

‎bfg9000/builtins/compile.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ def _get_flags(backend, rule, build_inputs, buildfile):
289289
buildfile
290290
)
291291
cmd_kwargs['flags'] = cflags
292-
flags = rule.flags(gopts)
293-
if flags:
292+
if flags := rule.flags(gopts):
294293
variables[cflags] = [global_cflags] + flags
295294

296295
return variables, cmd_kwargs

‎bfg9000/builtins/copy_file.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def __init__(self, context, output, file, *, mode='copy', extra_deps=None,
2929

3030
@staticmethod
3131
def convert_args(context, name, file, kwargs):
32-
directory = kwargs.pop('directory', None)
33-
if directory:
32+
if directory := kwargs.pop('directory', None):
3433
directory = buildpath(context, directory, strict=True)
3534
file = context['auto_file'](file)
3635

‎bfg9000/builtins/link.py‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ def _get_linkers(self, env, langs):
125125
yielded = False
126126
for i in langs:
127127
try:
128-
linker = env.builder(i).linker(self.mode)
129-
if linker:
128+
if linker := env.builder(i).linker(self.mode):
130129
yielded = True
131130
yield linker
132131
except ToolNotFoundError:
@@ -420,8 +419,7 @@ def _get_flags(backend, rule, build_inputs, buildfile):
420419
buildfile
421420
)
422421
cmd_kwargs['flags'] = ldflags
423-
flags = rule.flags(gopts)
424-
if flags:
422+
if flags := rule.flags(gopts):
425423
variables[ldflags] = [global_ldflags] + flags
426424

427425
if hasattr(linker, 'libs_var'):
@@ -431,8 +429,7 @@ def _get_flags(backend, rule, build_inputs, buildfile):
431429
buildfile
432430
)
433431
cmd_kwargs['libs'] = ldlibs
434-
lib_flags = rule.lib_flags(gopts)
435-
if lib_flags:
432+
if lib_flags := rule.lib_flags(gopts):
436433
variables[ldlibs] = [global_ldlibs] + lib_flags
437434

438435
if hasattr(rule, 'manifest'):

‎bfg9000/environment.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ def run_arguments(self, args, lang=None):
230230

231231
if lang is None:
232232
lang = first(getattr(args[0], 'lang', None), default=None)
233-
runner = self._runner(lang)
234-
if runner:
233+
if runner := self._runner(lang):
235234
return runner.run_arguments(args[0]) + args[1:]
236235

237236
if not isinstance(args[0], Executable):

‎bfg9000/options.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ def __repr__(self):
102102
def recurse(cls, libs):
103103
def do_recurse(result, libs):
104104
for i in libs:
105-
forward_opts = getattr(i, 'forward_opts', None)
106-
if forward_opts:
105+
if forward_opts := getattr(i, 'forward_opts', None):
107106
result.update(forward_opts)
108107
do_recurse(result, forward_opts.libs)
109108

@@ -121,8 +120,7 @@ def _get_ns_annotations(attrs):
121120

122121
if sys.version_info >= (3, 14):
123122
import annotationlib
124-
annotate = annotationlib.get_annotate_from_class_namespace(attrs)
125-
if annotate:
123+
if annotate := annotationlib.get_annotate_from_class_namespace(attrs):
126124
return annotationlib.call_annotate_function(
127125
annotate, format=annotationlib.Format.FORWARDREF
128126
)

‎bfg9000/packages.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class Package:
2424
is_package = True
2525

2626
def __init__(self, name, submodules=None, *, format, deps=None):
27-
submodules = _listify(submodules)
28-
if submodules:
27+
if submodules := _listify(submodules):
2928
name = '{}[{}]'.format(name, ','.join(submodules))
3029

3130
self.name = name

‎bfg9000/shell/__init__.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ def __str__(self):
3333
.format(cmd, self.returncode))
3434

3535
if self.stderr:
36-
stderr = self.stderr.strip()
37-
if stderr:
36+
if stderr := self.stderr.strip():
3837
msg += ':\n' + textwrap.indent(stderr, ' ' * 2)
3938
return msg
4039

@@ -76,8 +75,7 @@ def which(names, path=default_sentinel, pathext=default_sentinel, *,
7675
if pathext is default_sentinel:
7776
pathext = ['']
7877
if platform_info().has_path_ext:
79-
extstr = env.get('PATHEXT')
80-
if extstr:
78+
if extstr := env.get('PATHEXT'):
8179
pathext.extend(split_paths(extstr))
8280

8381
for name in names:

‎bfg9000/tools/c_family.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ def c_family_builder(env, lang):
9898
fallback = _fallback_posix_builder
9999

100100
langinfo = known_langs[lang]
101-
cmd = env.getvar(langinfo.var('compiler'))
102-
if cmd:
101+
if cmd := env.getvar(langinfo.var('compiler')):
103102
return choose_builder(env, langinfo, _builders, candidates=cmd,
104103
fallback_builder=fallback)
105104

‎bfg9000/tools/cc/__init__.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def __init__(self, env, langinfo, command, found, version_output):
3232
# Try to infer the appropriate -fuse-ld option from the LD environment
3333
# variable.
3434
link_command = command[:]
35-
ld_command = env.getvar(ldinfo.var('linker'))
36-
if ld_command:
35+
if ld_command := env.getvar(ldinfo.var('linker')):
3736
tail = os.path.splitext(ld_command)[1][1:]
3837
if tail in ['bfd', 'gold']:
3938
log.info('setting `-fuse-ld={}` for `{}`'

0 commit comments

Comments
 (0)