From ab3b721a540f2279267235ee21767b7f705699a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tin=20Tvrtkovi=C4=87?= Date: Thu, 7 Jun 2018 21:02:35 +0200 Subject: [PATCH] Python: fix default bool value. (#4773) * Python: fix default bool value. * Small style tweak. --- src/idl_gen_python.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/idl_gen_python.cpp b/src/idl_gen_python.cpp index ba7dd5624..419270c46 100644 --- a/src/idl_gen_python.cpp +++ b/src/idl_gen_python.cpp @@ -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.