Home Download Buy Blog Forum Support

API Bug: Settings with null does not return default value

API Bug: Settings with null does not return default value

Postby tanepiper on Fri Jan 13, 2012 9:13 pm

Hi there,

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

Code: Select all
DEFAULT_TODO_PATH = os.path.expanduser(os.path.join('~', '.todomanager'))


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

Code: Select all
{
  "todo_path": null
}


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

Code: Select all
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.
tanepiper
 
Posts: 68
Joined: Sun Nov 06, 2011 6:40 am

Re: API Bug: Settings with null does not return default value

Postby sublimator on Sat Jan 14, 2012 1:23 am

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`
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: API Bug: Settings with null does not return default value

Postby sublimator on Sat Jan 14, 2012 1:27 am

It's inline with Python semantics anyway:
Code: Select all
>>> `dict(a=None).get('a', False)`
'None'


I guess it varies between languages?
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 5 guests