Skip to content

Consider Adding dataclass Support for Various Response Models? #8

@engineerjoe440

Description

@engineerjoe440

As I've been using this library, I've bitten myself a couple times expecting a specific response type that I was not given. I wonder if it would make sense to use Python dataclasses to help constrain response data-structures into a predictable format, making it easier to program against the Lychee API.

What do you think?

Example

@dataclass
class PhotoData:
    some_attribute: str
    another_attr: int

...

    def get_photo(self, photo_id) -> dict:
        """Get information about a photo."""
        data = {'photoID': photo_id}
        response = self._session.post('Photo::get', json=data)
        response.raise_for_status() # Raises an error if an unexpected HTTP response is returned
        return PhotoData(**response.json())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions