From 3d971fb577779ea6e4de24c09da582dab95ae82c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 25 Dec 2020 12:08:48 +0100 Subject: [PATCH] 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. --- compiler/api/compiler.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index acaf9731..6b14334d 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -399,15 +399,19 @@ def start(format: bool = False): write_types = read_types = "" if c.has_flags else "# No flags\n " for arg_name, arg_type in c.args: - flag = FLAGS_RE_2.findall(arg_type) + flag = FLAGS_RE_2.match(arg_type) if arg_name == "flags" and arg_type == "#": write_flags = [] for i in c.args: - flag = FLAGS_RE.match(i[1]) + flag = FLAGS_RE_2.match(i[1]) + if flag: - write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} is not None else 0") + if flag.group(2) == "true": + write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} else 0") + else: + write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} is not None else 0") write_flags = "\n ".join([ "flags = 0", @@ -421,7 +425,7 @@ def start(format: bool = False): continue if flag: - index, flag_type = flag[0] + index, flag_type = flag.groups() if flag_type == "true": read_types += "\n "