I encountered a vicious bug, where a plug‑in behaved differently depending on it being reloaded or initially loaded.
Say one have this at the top level of a test plug‑in (that is, executed when the module is loaded):
PREFERENCES = sublime.load_settings("Preferences.sublime-settings")
print(PREFERENCES.has("color_scheme"))
print(PREFERENCES.get("color_scheme", "foo"))
What is it expected to print to the console?
Actually for me and it is loaded as ST starts up, it prints False
and None
, but if the plug‑in is reloaded it prints True
and <some-color-scheme>
.
Is this the expected behavior or is it me not understanding how it should behave?
May be that’s just the plug‑in which is loaded before the setting. But if I repeat the second and third line in the run
method of a plug‑in, I still get the same. However, if I also repeate the first line in run
, I get the expected result.
API Reference (sublimetext.com) says:
So this should not change anything, if PREFERENCES
is initialized while the module loads or when run
is executed, this should be the same object, and its methods should return the same when run
is executed.
Then, there is something about get
:
But in the third line, is does not return "foo"
, it returns None
.
I feel lost, and wonder if these two unexpected behaviors (unexpected to me), are two bugs or if it’s me who doing something wrong.
I just fixed my plug‑in about it: it was working fine while I was developing it, because I was constantly triggering a reload while editing it, but it stopped working as expected as soon as I only used normally as just loaded with ST, not reloaded later.