Skip to content

refactor Volume class to use dataclass and dataclass_json#89

Closed
tamirse wants to merge 3 commits intofeature/add-missing-volume-fieldsfrom
refactor/volume-dataclass
Closed

refactor Volume class to use dataclass and dataclass_json#89
tamirse wants to merge 3 commits intofeature/add-missing-volume-fieldsfrom
refactor/volume-dataclass

Conversation

@tamirse
Copy link
Copy Markdown
Collaborator

@tamirse tamirse commented Mar 30, 2026

Replaces the manual __init__/property/create_from_dict pattern with @DataClass + @dataclass_json for consistency with the Instance class. Undefined.EXCLUDE silently drops unknown API fields; infer_missing defaults missing optional fields to None. Retains create_from_dict as a deprecated shim for backwards compatibility.

Replaces the manual __init__/property/create_from_dict pattern with
@DataClass + @dataclass_json for consistency with the Instance class.
Undefined.EXCLUDE silently drops unknown API fields; infer_missing
defaults missing optional fields to None. Retains create_from_dict as
a deprecated shim for backwards compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
.. deprecated:: Use :meth:`from_dict` instead.
"""
return stringify_class_object_properties(self)
return cls.from_dict(volume_dict, infer_missing=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

volume_dict = self._http_client.get(VOLUMES_ENDPOINT + f'/{id}').json()

return Volume.create_from_dict(volume_dict)
return Volume.from_dict(volume_dict, infer_missing=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here

tamirse and others added 2 commits March 30, 2026 13:34
All optional fields already have defaults on the dataclass, so
infer_missing is unnecessary. Removing it gives stricter validation:
a response missing a required field like id or name will raise
immediately instead of silently setting None.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tamirse tamirse closed this Mar 30, 2026
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