Skip to content

FunctionalProperty constraints are in the public api but are not validated. #275

@julianstirling

Description

@julianstirling

Since finding out I can do:

    @lt.setting
    def microscope_id(self) -> UUID:
        """A unique identifier for this microscope."""
        if self._microscope_id is None:
            self._microscope_id = str(uuid4())
        return UUID(self._microscope_id)

    @microscope_id.setter
    def _set_microscope_id(self, uuid: UUID) -> None:
        self._microscope_id = str(uuid)

    microscope_id.readonly = True

I am realising I can set the other attributes of the descriptor including constraints such as:

    @lt.setting
    def microscope_id(self) -> UUID:
        """A unique identifier for this microscope."""
        if self._microscope_id is None:
            self._microscope_id = str(uuid4())
        return UUID(self._microscope_id)

    @microscope_id.setter
    def _set_microscope_id(self, uuid: UUID) -> None:
        self._microscope_id = str(uuid)

    microscope_id.constraints = {"min_length": 1}

This propagates through to the thing_descriptions. I think if BaseProperty made constraints a @builtins.propertythen it could either validate it with the setter. Or create aset_constraints` so that this is possible:

    @lt.setting
    def microscope_id(self) -> UUID:
        """A unique identifier for this microscope."""
        if self._microscope_id is None:
            self._microscope_id = str(uuid4())
        return UUID(self._microscope_id)

    @microscope_id.setter
    def _set_microscope_id(self, uuid: UUID) -> None:
        self._microscope_id = str(uuid)

    microscope_id.set_constraints(min_length=1)

which feels like nicer syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions