Python: fix default bool value. (#4773)
authorTin Tvrtković <tinchester@gmail.com>
Thu, 7 Jun 2018 19:02:35 +0000 (21:02 +0200)
committerWouter van Oortmerssen <aardappel@gmail.com>
Thu, 7 Jun 2018 19:02:35 +0000 (12:02 -0700)
* Python: fix default bool value.

* Small style tweak.

src/idl_gen_python.cpp

index ba7dd56..419270c 100644 (file)
@@ -147,8 +147,13 @@ static void GetScalarFieldOfTable(const StructDef &struct_def,
     getter = "bool(" + getter + ")";
   }
   code += Indent + Indent + Indent + "return " + getter + "\n";
-  auto defaultValue = (is_bool ? "False" : field.value.constant);
-  code += Indent + Indent + "return " + defaultValue + "\n\n";
+  std::string default_value;
+  if (is_bool) {
+    default_value = field.value.constant == "0" ? "False" : "True";
+  } else {
+    default_value = field.value.constant;
+  }
+  code += Indent + Indent + "return " + default_value + "\n\n";
 }
 
 // Get a struct by initializing an existing struct.