Sublime Forum

API Bug: Settings with null does not return default value

#1

Hi there,

For my plugin, I’ve created a config file. In my plugin, I have the following line:

DEFAULT_TODO_PATH = os.path.expanduser(os.path.join('~', '.todomanager'))

This sets a default path and in the default config I want to have:

{ "todo_path": null }

When I load the settings, I want to be able to do this:

settings = sublime.load_settings('TodoManager.sublime-settings') todo_path = settings.get('todo_path', DEFAULT_TODO_PATH)

But no matter what, I always get None. Of course I can do a check here and manually set it, but it would be nice if the settings API detected this and used the default.

0 Likes

#2

Sublime is behaving correctly in my opinion. The setting has a valid key. The default value should be used when there isn’t one.

You have other options to determine if the value is null or an empty string (both with boolean value of False in python): todo_path = settings.get('todo_path') or DEFAULT_TODO_PATH

0 Likes

#3

It’s inline with Python semantics anyway:

[code]

dict(a=None).get('a', False)
‘None’[/code]

I guess it varies between languages?

0 Likes