Glyphs.boolDefault returns wrong values


I’m on Glyphs 3.0.5 (3117), and I’m getting an unexpected result when calling Glyphs.boolDefaults.

When the default I am calling for is “truthy”, boolDefaults returns False.

boolDefaults only returns True if the default is literally True, not just “truthy” as is expected.

Try the code below in the macro window.

# Should be False if it doesn't exist/returns None
assert Glyphs.boolDefaults[""] == False # Passes

# Should be True if it is set/is Truthy
Glyphs.defaults[""] = "baz"
assert bool(Glyphs.defaults[""]) == True # Passes
assert Glyphs.boolDefaults[""] == True # Fails

# Only returns True if value is literally "True"
Glyphs.defaults[""] = True
assert Glyphs.boolDefaults[""] == True # Passes


Traceback (most recent call last):
  File "<macro panel>", line 8

As I understand it from the Python API documentation, it should return True on anything that is “truthy”:

Glyphs.boolDefaults returns True whatever Cocoa thinks is true, not what python considers so. It calls NSUserDefaults.standardUserDefaults().boolForKey_(key) and returns that as is. It could do bool(NSUserDefaults.standardUserDefaults().objectForKey_(key)). Not sure what is better. For me, looking from the ObjectiveC side, the first makes more sense :wink:

(you know that you can get to the details on how things are implemented here: ?)

Thanks! And thanks for the link, I will use it in the future.

Maybe it should be more explicit in the documentation, though :slight_smile: Since it’s the Python API, I assumed it would use Python rules for what is True.