returns_list

astrodata.returns_list(fn)[source]

Ensure a function returns a list.

Decorator to ensure that descriptors returning a list (of one value per extension) only returns single values when operating on single slices; and vice versa.

This is a common case, and you can use the decorator to simplify the logic of your descriptors.

Parameters:

fn (Callable) – The method to be decorated

Returns:

A function

Return type:

Callable

Example

from astrodata import (
    AstroData,
    astro_data_descriptor,
    returns_list,
    NDAstroData
)

class MyAstroData(AstroData):
    @astro_data_descriptor
    @returns_list
    def my_descriptor(self):
        return 1

# Create an instance of the class with slices
ad = MyAstroData([NDAstroData([1, 2, 3]), NDAstroData([4, 5, 6])])

# This will print [1, 1] to stdout
print(ad.my_descriptor())