Skip to content

refactor: use typed namedtuples for the get_list page result #251

Merged
jooola merged 7 commits intohetznercloud:mainfrom
jooola:typed_page_result
Jul 21, 2023
Merged

refactor: use typed namedtuples for the get_list page result #251
jooola merged 7 commits intohetznercloud:mainfrom
jooola:typed_page_result

Conversation

@jooola
Copy link
Member

@jooola jooola commented Jul 20, 2023

This is a nice refactor that remove some magic from the get_list methods.

The get_list function returns a named tuple that always has the following structure (result, meta). Since this is a tuple, we can unpack it without using the named attributes, and remove the results_list_attribute_name attributes used to access the data inside the tuple.

  • Use predefined NamedTuples classes instead of dynamic (magic) namedtuples for the get_list PageResult. This will greatly improve the library typing definition.
  • Remove unused functions and attributes after the refactor. This cleans up and simplify the code.

jooola added 6 commits July 20, 2023 17:02
The `get_list` function returns a named tuple that always has the following structure  `(result, meta)`. Since this is a tuple, we can unpack it without using the named attributes. This allows us to remove the `results_list_attribute_name` used to access the data in the tuple.
Unpack the page result tuple instead of accessing the data by attr name.
@jooola jooola force-pushed the typed_page_result branch from c00c6f1 to 7c5485b Compare July 20, 2023 16:18
@jooola jooola requested a review from apricote July 21, 2023 08:43
@jooola jooola merged commit c89b5bd into hetznercloud:main Jul 21, 2023
@jooola jooola deleted the typed_page_result branch July 21, 2023 15:30
jooola added a commit that referenced this pull request May 7, 2025
The API specification now describe all meta/pagination fields as
required, this PR updates the library to reflect that.

Related #251
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