When calling this function in a python script, the context's
space_data can be None, making this condition raise an AttributeError.
This is the case when the running the script through '-P' argument
One solution could be for the user to call this helper with a custom
context with a stub space_data but from the user's perspective it is not
obvious that this is required just by watching at the
documentation or function signature.
All other functions which are using the space_data in this file first
check for the space_data existence before testing it's type. So adding
it here add some consistency.
Fixes T72338.