OpenAssetIO / OpenAssetIO-TraitGen

A code generation tool that produces OpenAssetIO Traits and Specifications from a simple YAML description.
Apache License 2.0
6 stars 3 forks source link

Python numeric trait properties can be set to the wrong type #34

Closed feltech closed 1 month ago

feltech commented 1 year ago

What

Python int trait properties can easily be set to bool values without realising. The internal std::variant would then store the value as a bool, potentially causing problems accessing the value from C++.

ACs

feltech commented 1 month ago

We already have the following code in place

        if not isinstance({{ VarName }}, {{ VarType }}):
            raise TypeError("{{ property.id }} must be a '{{ VarType }}'.")
        self.__data.setTraitProperty(self.kId, "{{ property.id }}", {{ VarName }}

I confirmed this works fine to ensure you can't set a float trait property with an int value.

However, it is possible to set a bool value on an int property. Perhaps the description in the issue had the wrong type?

I'll update the description.