teemtee / fmf

Flexible Metadata Format
GNU General Public License v2.0
22 stars 28 forks source link

Add type annotations to fmf code #185

Open happz opened 2 years ago

i386x commented 1 year ago

Following our discussion from this years' March: The main problem here is get method which in general can return any type (more precisely in case of fmf: atomic types like float, int, str, maybe datetime, and None and compound types list and dict over them and over themselves). In languages like C/C++ get method return type will be some kind of union wrapped inside a struct but in Python we are using Any.

One solution to get rid off Any can be the API change: Instead of get, provide get_field_a, get_field_b, etc. to provide access to particular fmf fields; such methods can be annotated much more easily. Furthermore, as fmf format is described using JSON schema, we can use the schema to generate these methods together with their annotations instead of doing boring manual work but this step requires additional tooling. I am also aware that this means a lot of changes in the existing tmt codebase and other tools which are using fmf.