Closed lheagy closed 5 years ago
Hey @lheagy - I think this might be slightly off track. An Instance
of properties.Array
will expect it to be a Property
instance, not actually an array. I think what you are looking for is something like:
class HasLocations(properties.HasProperties):
locations = properties.List(
'List of arrays',
properties.Array(''),
min_length=1,
max_length=2,
)
Then you can do this:
properties.List
has a coerce
attribute that gives even more flexibility, like this:
That totally bypasses Instance
and sounds like it fits your use case? If this isn't quite what you are looking for, please follow up! There is a bit more you can do with Instance
if necessary, but it would probably look more like properties.Instance('', NumpyArraySubclass)
or something...
Many thanks for the clarification @fwkoch!! This is what I needed :)
Would including a
coerce
on anInstance
property be of interest? I have an example where I am creating aList
property ofArray
values, and would like to allow the user to simply input a list of numpy arrays, and we cast them toproperties.Array
. Right now, doing so causes a validation error.The only mechanism from the outside that I would see to remedy this is to subclass
properties.Instance
? (other ideas appreciated!), which seems like a bit of overkill.Would something like the following seem suitable?