In Python PropertySet.get(name) will return a scalar if there is only one element, and an array if there is more than one element. Similarly for PropertyList. I think this encourages unsafe code. When expecting a scalar it is far too easy to expect there will only be one element and not check. Similarly, when expecting an array, one may be surprised to get a scalar if the array happens to only have one element.
I suggest we add two methods to PropertySet and PropertyList in Python:
- getScalar(name): return the last value of the array, like C++ get<T>
- getArray(name): return the data as an array, even if it only has one element. This is like C++ getArray<T>.
I further suggest that we deprecate get and use these new methods for all new code. It avoids obvious bugs and makes the intent clearer. Here are some before and after examples:
Note that the safe old style examples use the flag asArray. This is an optional argument to get that I didn't know existed until today. It is undocumented. I'm curious how many folks even knew about it, and are confident they know what it does.