Changes to PropertySet and PropertyList Python interface

Tags: #<Tag:0x00007f61a47bcc50>

(Tim Jenness) #1

I have recently made some changes to the PropertySet and PropertyList Python interface.

Following on from previous discussions that resulted in __iter__, __setitem__, and __contains__ support being added, I have recently added __getitem__ and update() and resurrected get().

This means you can now do (for PropertyList and PropertySet):

>>> ps = PropertySet()
>>> ps["int"] = 5
>>> assert ps["int"] == 5
>>> assert ps.get("notint") is None
>>> assert ps.get("notint", "default") == "default"
>>> ps.add("int", 6)
>>> assert ps["int"] == 6
>>> ps.getArray("int")
[5, 6]

get() is no longer deprecated and behaves like dict.get() with defaulting. One caveat is that get() and ps[] now use getScalar behind the scenes so they are guaranteed to return a single value even if an array is stored in the PropertySet. If you want multiple values you have to use getArray.

One final change is that None can now be stored in a PropertyList (this allows undefined FITS header values to be properly represented). This works for scalars but if multiple values are being stored in the same item they all have to be None or all have to be not-None.