Motivation
In HERD.add_ref, the key argument almost always duplicates the value being annotated:
add_ref(container=subject, key=subject.species, entity_id=..., entity_uri=...) # tutorial form
add_ref(container=subject, attribute="strain", key="C57BL/6J", entity_id=..., entity_uri=...) # issue 652 form
When attribute names a scalar attribute, the key is just the value at that attribute, so requiring it is redundant.
Proposal
When attribute is provided and resolves to a scalar value, default key to that value (getattr(container, attribute)) if key is not given. This turns the example into:
add_ref(container=subject, attribute="strain", entity_id="RRID:IMSR_JAX:000664",
entity_uri="https://www.jax.org/strain/000664")
Scope / edge cases
- Only applies when the resolved attribute value is a scalar (e.g. a string). Column/array attributes (such as a
DynamicTable column like the electrodes location) have no single value, so key must remain required there; attempting to default it should raise a clear error rather than guess.
key remains accepted explicitly and takes precedence when provided, so this is backward compatible.
- The behavior when no
attribute is given is unchanged (key still required).
Context
Code of Conduct
Motivation
In
HERD.add_ref, thekeyargument almost always duplicates the value being annotated:When
attributenames a scalar attribute, thekeyis just the value at that attribute, so requiring it is redundant.Proposal
When
attributeis provided and resolves to a scalar value, defaultkeyto that value (getattr(container, attribute)) ifkeyis not given. This turns the example into:Scope / edge cases
DynamicTablecolumn like the electrodeslocation) have no single value, sokeymust remain required there; attempting to default it should raise a clear error rather than guess.keyremains accepted explicitly and takes precedence when provided, so this is backward compatible.attributeis given is unchanged (keystill required).Context
Code of Conduct