Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Jul 21, 2023

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.

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 requested a review from apricote July 21, 2023 08:43
hcloud/core/domain.py Show resolved Hide resolved
hcloud/core/client.py Show resolved Hide resolved
hcloud/core/client.py Show resolved Hide resolved
@jooola jooola merged commit c89b5bd into hetznercloud:main Jul 21, 2023
5 checks passed
@jooola jooola deleted the typed_page_result branch July 21, 2023 15:30
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