RFC: Use mutable dictionaries for object properties #617
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related Issue(s):
Item.to_dict()
, seemingly from links #546Description:
This PR is intended to be a proof-of-concept for changing the JSON-serializable classes to maintain a mutable dictionary in a
fields
property instead of setting instance attributes. The current draft only implements this for theAsset
class, but if there is interest I will attempt to implement this for theLink
class next since we have seen performance issues in theto_dict
method there.Some possible advantages to this approach are:
preserve_dict=False
If we are able to implement this for all JSON serializable classes, then we may not need some of the
Union
types in ourPropertiesExtension
classes since those could utilize thefields
dictionary instead. This may also ease some of our circular imports since we might be able to avoid some blocks like:Item.set_collection
might no longer be necessary if we can handle them within the settersSome possible hiccups:
Item
class might be tricky since some of them are at the top level and some are in theproperties
.Asset.href
) since we are now accessing those as properties.The current behavior of the
extra_fields
attribute on some of the classes may be hard to replicate. Currently, this attribute is a mutable dictionary that only includes the fields not covered by specific attributes (e.g.Asset.href
), but also allows mutatation of the object (e.g.asset.extra_fields["some_field"] = "some_value"
will add the"some_field"
property to the Asset when serialized).PR Checklist:
pre-commit run --all-files
)scripts/test
)cc: @TomAugspurger @gjoseph92