-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
internalChanges only affect the internal APIChanges only affect the internal API
Description
The linked data of each model defined in dandischema.models
is currently stored with the private attribute _ldmeta
, such as https://github.com/dandi/dandi-schema/blob/6d6c7b18addc40bbbbe8311d4a3f8a37e832cc3d/dandischema/models.py#L645C5-L645C34. We can instead store the linked data of each model in a class variable instead.
Specifically, instead of the following
_ldmeta = {"nskey": "schema"}
we can have
ldmeta: ClassVar[dict] = {"nskey": "schema"}. # Using an identifier without an underscore
Doing so has several benefits.
- Semantically, a class variable relates to the containing class/model while a private attribute relates to a instance of the class. Thus, a class variable is more in line with the fact that the link data relates to the model not to an instance of a model.
- We don't have to use an identifier that starts with an underscore. (We can use just
ldmeta
or evenlinked_data
) - The assigned value will not be implicitly coerced into another type.
Currently the initial assigned value of a_ldmeta
attribute is coerced into apydantic.fields.ModelPrivateAttr
, as depicted below.As a result, to access the initial assigned value is rather cumbersome as https://github.com/dandi/dandi-schema/blob/6d6c7b18addc40bbbbe8311d4a3f8a37e832cc3d/dandischema/metadata.py#L75C12-L75C49.from dandischema.models import BaseType type(BaseType._ldmeta) <class 'pydantic.fields.ModelPrivateAttr'>
Please let me know if I should proceed with this proposed change with a PR.
Metadata
Metadata
Assignees
Labels
internalChanges only affect the internal APIChanges only affect the internal API