* Avoid exception if trying to delete missing "removed" key
`.pop(key)` throws an exception if that `key` is missing. Using a default value (in this case None) means we don't throw any errors when deleting a missing key. Which is what we want here, for safety. We just want to delete the key. We don't care if it's existing or not.
There are other places in the codebase that also use `.pop(key)`, but all of those first check the validity of the key before popping, so this was the only one that needed fixing.
* Improve performance by removing keys() calls
Every `.keys()` call create a new `[list...]` of all keys from the given dictionary. It's a total waste of performance, since we can already check if a key exists in a dictionary by just using `if "key" in the_dict`.
* Use more pythonic "not in" syntax
The syntax is supposed to be `if "thing" not in other_thing`. We already use this proper `not in` syntax everywhere else in the codebase. Just fixing this location.
The function was getting a bit convoluted to follow, and there was a maintenance burden of having to remember that "shell=True" should only be true if the argument is a single string to be passed exactly as-is to the shell. If it's a list, only the first value in the list would be ran as the shell command and the rest would be given as arguments to the shell itself.
Therefore, it's been refactored to automatically determine shell-mode based on whether "args" is a list or a string.
On Windows, we now generate a correctly escaped shell-string via "shlex". This ensures that we properly support spaces inside quoted launch arguments, by auto-escaping them on a per-argument basis.
The extra pylint hint is needed because the import is detected as unused on non-Windows machines.