Uploaded image for project: 'Request For Comments'
  1. Request For Comments
  2. RFC-596

Add getitem to PropertySet and PropertyList

    Details

    • Type: RFC
    • Status: Implemented
    • Resolution: Done
    • Component/s: DM
    • Labels:
      None

      Description

      In RFC-434 we deprecated PropertySet.get() and replaced it with getScalar and getArray. Whilst this seems safer for many users, it means that a PropertySet can't ever behave like a Python dict. This is a real annoyance with astro_metadata_translator since that accepts any dict-like headers (including those from Astropy) and I have to have special workarounds all over it to convert PropertyList to dict.

      Can I please add PropertySet.__getitem__ which behaves like get() and allows me to say ps["KEY"]? (there is a __setitem__ already for assignment using normal dict syntax). The toDict and toOrderedDict methods already use the Pythonic approach of returning a list or scalar depending on the contents of the PropertyList.

      Ideally I'd like to add back a get() that looks like a dict get and allows defaulting, but I imagine that is a harder sell.

      This __getitem__ proposal is adding to the API and not changing any existing API.

        Attachments

          Issue Links

            Activity

            tjenness Tim Jenness created issue -
            tjenness Tim Jenness made changes -
            Field Original Value New Value
            Link This issue relates to RFC-434 [ RFC-434 ]
            ktl Kian-Tat Lim made changes -
            Description In RFC-434 we deprecated {{PropertySet.get()}} and replaced it with {{getScalar}} and {{getArray}}. Whilst this seems safer for many users, it means that a {{PropertySet}} can't ever behave like a Python {{dict}}. This is a real annoyance with {{astro_metadata_translator}} since that accepts any dict-like headers (including those from Astropy) and I have to have special workarounds all over it to convert {{PropertyList}} to {{dict}}.

            Can I please add {{PropertySet.__getitem__}} which behaves like {{get()}} and allows me to say {{ps["KEY"]}}? (there is a {{__setitem__}} already for assignment using normal dict syntax). The {{toDict}} and {{toOrderedDict}} methods already use the Pythonic approach of returning a list or scalar depending on the contents of the PropertyList.

            Ideally I'd like to add back a {{get()}} that looks like a dict get and allows defaulting, but I imagine that is a harder sell.

            This {{__getitem__}} proposal is adding to the API and not changing any existing API.
            In RFC-434 we deprecated {{PropertySet.get()}} and replaced it with {{getScalar}} and {{getArray}}. Whilst this seems safer for many users, it means that a {{PropertySet}} can't ever behave like a Python {{dict}}. This is a real annoyance with {{astro_metadata_translator}} since that accepts any dict-like headers (including those from Astropy) and I have to have special workarounds all over it to convert {{PropertyList}} to {{dict}}.

            Can I please add {{PropertySet.\_\_getitem\_\_}} which behaves like {{get()}} and allows me to say {{ps["KEY"]}}? (there is a {{\_\_setitem\_\_}} already for assignment using normal dict syntax). The {{toDict}} and {{toOrderedDict}} methods already use the Pythonic approach of returning a list or scalar depending on the contents of the PropertyList.

            Ideally I'd like to add back a {{get()}} that looks like a dict get and allows defaulting, but I imagine that is a harder sell.

            This {{\_\_getitem\_\_}} proposal is adding to the API and not changing any existing API.
            gcomoretto Gabriele Comoretto made changes -
            Remote Link This issue links to "Page (Confluence)" [ 20562 ]
            tjenness Tim Jenness made changes -
            Planned End 15/May/19 9:40 PM 19/May/19 9:40 PM
            tjenness Tim Jenness made changes -
            Status Proposed [ 10805 ] Flagged [ 10606 ]
            gcomoretto Gabriele Comoretto made changes -
            Remote Link This issue links to "Page (Confluence)" [ 20612 ]
            tjenness Tim Jenness made changes -
            Status Flagged [ 10606 ] Adopted [ 10806 ]
            tjenness Tim Jenness made changes -
            Link This issue is triggering DM-19873 [ DM-19873 ]
            tjenness Tim Jenness made changes -
            Resolution Done [ 10000 ]
            Status Adopted [ 10806 ] Implemented [ 11105 ]
            gcomoretto Gabriele Comoretto made changes -
            Remote Link This issue links to "Page (Confluence)" [ 20725 ]

              People

              • Assignee:
                tjenness Tim Jenness
                Reporter:
                tjenness Tim Jenness
                Watchers:
                Jim Bosch, John Parejko, John Swinbank, Kian-Tat Lim, Krzysztof Findeisen, Robert Lupton, Russell Owen, Tim Jenness
              • Votes:
                1 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Planned End:

                  Summary Panel