Skip to content

feat: use dataclass instead of plain dict for responses#17

Open
jrester wants to merge 1 commit intomondbaron:mainfrom
jrester:structured-data
Open

feat: use dataclass instead of plain dict for responses#17
jrester wants to merge 1 commit intomondbaron:mainfrom
jrester:structured-data

Conversation

@jrester
Copy link
Contributor

@jrester jrester commented Oct 4, 2025

This is a proposal to change the responses of all API calls to use dataclass instead of plain dict. In my opinion this makes it easier to work with the API in third party applications and libraries since the responses are now typed. Additionally, it enables the relative accessors for departure time and makes it easier to de-duplicate response objects (e.g., lines), because dict is not hashable but a frozen dataclass is.

For backwards compatibility I kept the dict style key access for all response objects. This means that station["id"] is still valid and existing code should not break completely.

This is already based on #15, but I wanted to split this into a separate MR since this is a quite significant change. It also includes the changes from #16.

What do you think about the proposal?

Copy link
Owner

@mondbaron mondbaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the proposal. As this is a breaking change, I won't immediatly merge it. For now I rebased on merged #15 and #16, some tests I introduced in earlier PR are failing.

If we introduce a breaking change in returned data format, I'd be in favor of keeping all old tests, and adding new for the new dataformat. An additional paramter can be added to request a dataclass result. If we want to default this behavior in future releases, I'd suggest to add a future deprecation warning, when this parameter is not set by the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants