'Check if List contains object without fields

I have an API response that can respond with an array like this:

[
    {
        "id": 1,
        "title": "Warning"
    },
    {
        "id": 2,
        "title": "Warning"
    }
]

sometimes it can respond just empty array

[]

in my case i created a class for this object. Something like this:

class Warning:
    def __init__(self, data: Dict):
        if bool(data):
            self.id: int = data["id"]
            self.title: str = data["title"]
        else:
            pass


if __name__ == '__main__':
    data = {
        "id": 123455,
        "title": "Warning"
    }
    empty_data = {}
    object1: List[Warning] = [Warning(data)]
    object2: List[Warning] = [Warning(empty_data)]
    if object1:
        print("we have a warnings")
    if object2:
        print("we don't have warnings")

I can't understand, how can I check if i get List of Object with empty fields like object2?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source