Skip to content

HERD.add_ref: default key to a scalar attribute's value to remove redundant argument #1509

Description

@rly

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

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions