From 440c71345a88f32ccad06d662fb30272f9253f07 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 25 Oct 2018 15:36:08 +0100 Subject: [PATCH] UFOReader: have readInfo return a dict but keep current behavior whereby caller can pass an Info object. The readInfo method was the only one that takes an output argument, all the others just return some raw data. I like to fully construct my classes in their __init__ method. E.g. Info(**reader.readInfo()) --- Lib/fontTools/ufoLib/__init__.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Lib/fontTools/ufoLib/__init__.py b/Lib/fontTools/ufoLib/__init__.py index d9a57c5d5..d50e280f4 100755 --- a/Lib/fontTools/ufoLib/__init__.py +++ b/Lib/fontTools/ufoLib/__init__.py @@ -466,7 +466,7 @@ class UFOReader(_UFOBaseIO): raise UFOLibError("fontinfo.plist is not properly formatted.") return data - def readInfo(self, info, validate=None): + def readInfo(self, info=None, validate=None): """ Read fontinfo.plist. It requires an object that allows setting attributes with names that follow the fontinfo.plist @@ -509,12 +509,17 @@ class UFOReader(_UFOBaseIO): # validate data if validate: infoDataToSet = validateInfoVersion3Data(infoDataToSet) - # populate the object - for attr, value in list(infoDataToSet.items()): - try: - setattr(info, attr, value) - except AttributeError: - raise UFOLibError("The supplied info object does not support setting a necessary attribute (%s)." % attr) + if info is not None: + # populate the object + for attr, value in infoDataToSet.items(): + try: + setattr(info, attr, value) + except AttributeError: + raise UFOLibError( + "The supplied info object does not support setting a " + "necessary attribute (%s)." % attr + ) + return infoDataToSet # kerning.plist