Open denisri opened 1 year ago
I already noticed (and forgot) problems using this syntax. I now believe that the syntax is wrong since the affectation should contain a value not a type. The right syntax should be:
class SulciLabling(Controller):
labeled_graph: field(type_=File, write=True, doc='output labeled graph')
I am in favor of raising an error when the value set on a controller attribute is a Field
. What do you think ?
I agree to raise an error when doing wrong things. Do you (we) have control over this class attribute assignment to check it ?
In Controller
subclasses yes, via a Metaclass that parse the class definition.
In pydantic Controller, we can declare a class field this way:
However the
field()
function, in this case, is called without atype_
argument, and metadata are not initialized properly:see:
path_type
isNone
, not'file'
If we use:then the metadata are:
A solution is to double-specify the type in the class field declaration:
but it needs to say things twice, is error prone, and it was not designed to be this way. I don't know (or don't remember) how class fields are assigned in the 1st form:
field()
returns aField
instance without atype
set, then it seems to be modified when assigned to the typed class variablelabeled_graph
, but I don't know where and if we can do anything there to fix things ?The consequence of this bug is that, in capsul, tests done in fields like:
if field.path_type
are sometimes wrong and unreliable.