Skip to content

Commit 3d971fb

Browse files
committed
Allow passing False instead of None for optional flag-boolean parameters
Previously, passing anything that was not None would result in the boolean flag being set to True, even when passing False. This will make it simpler to deal with optional flag-boolean values in the raw API.
1 parent 4698f71 commit 3d971fb

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

compiler/api/compiler.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,19 @@ def start(format: bool = False):
399399
write_types = read_types = "" if c.has_flags else "# No flags\n "
400400

401401
for arg_name, arg_type in c.args:
402-
flag = FLAGS_RE_2.findall(arg_type)
402+
flag = FLAGS_RE_2.match(arg_type)
403403

404404
if arg_name == "flags" and arg_type == "#":
405405
write_flags = []
406406

407407
for i in c.args:
408-
flag = FLAGS_RE.match(i[1])
408+
flag = FLAGS_RE_2.match(i[1])
409+
409410
if flag:
410-
write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} is not None else 0")
411+
if flag.group(2) == "true":
412+
write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} else 0")
413+
else:
414+
write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} is not None else 0")
411415

412416
write_flags = "\n ".join([
413417
"flags = 0",
@@ -421,7 +425,7 @@ def start(format: bool = False):
421425
continue
422426

423427
if flag:
424-
index, flag_type = flag[0]
428+
index, flag_type = flag.groups()
425429

426430
if flag_type == "true":
427431
read_types += "\n "

0 commit comments

Comments
 (0)