diff --git a/product/Formulator/FormToXML.py b/product/Formulator/FormToXML.py
index ef879a12ae129088bca95eac600aa5fa06d59af9..18e7802481cb9ba89d5576c00890377b60a884e1 100644
--- a/product/Formulator/FormToXML.py
+++ b/product/Formulator/FormToXML.py
@@ -77,10 +77,11 @@ def formToXML(form, prologue=1):
           delegated_list.sort()
           [SubElement(delegated_list_element, delegated) for delegated in delegated_list]
 
-    if form.unicode_mode:
-      xml = etree.tostring(form_as_xml, encoding='utf-8',
-                                    xml_declaration=True, pretty_print=True)
-    else:
-      xml = etree.tostring(form_as_xml, encoding=form.stored_encoding,
-                                    xml_declaration=True, pretty_print=True)
-    return bytes2str(xml)
+    encoding = 'utf-8' if form.unicode_mode else form.stored_encoding
+    xml = etree.tostring(
+      form_as_xml,
+      encoding=encoding,
+      xml_declaration=True,
+      pretty_print=True,
+    )
+    return bytes2str(xml, encoding=encoding)