reqif icon indicating copy to clipboard operation
reqif copied to clipboard

Support conversion from python types to strings in `unparse_attribute_values`

Open torsknod-the-caridian opened this issue 11 months ago • 5 comments

I just stumbled upon this. Using the package would be simpler if unparse_attribute_values would automatically convert Python data types to strings according to the ReqIF specification. Might be that I provide a patch for at least some data types in March 2025.

torsknod-the-caridian avatar Feb 11 '25 12:02 torsknod-the-caridian

@torsknod-the-caridian thanks for reporting this! I checked the unparse_attribute_values function and could not understand immediately what you are referring to. Could you explain a little more what you would like to be done?

stanislaw avatar Feb 11 '25 14:02 stanislaw

@stanislaw Sure, e.g. https://github.com/strictdoc-project/reqif/blob/44ca50873a5c95857456c04077c55430a61944f3/reqif/parsers/attribute_value_parser.py#L270-L271 has an assert to only allow strings. It would be great if it would also take bool and automatically convert it to a proper string.

The sample applies to most other datatypes, which are not strings.

A bit to the background: I am converting another custom format into reqif with your package and thus generating the whole thing from scratch. Having to do all the type conversions in my code, makes it obviously harder to read. And for sure I am writing code, which others probably write in a similar way.

torsknod-the-caridian avatar Feb 12 '25 07:02 torsknod-the-caridian

I think I understand now. The interesting thing is that I haven't encountered this before with all real-world ReqIFs that I could collect over time.

Could you make an example of a value that would not be string-based?

In the example above, at line 271, are you saying the object could be a bool value? If yes, then how would this work with a corresponding ReqIF file which only has HTML string attributes, for example, <ATTRIBUTE-VALUE-BOOLEAN THE-VALUE="true">?

convert Python data types to strings according to the ReqIF specification.

Could you provide a quote a specific part of the spec to let me know which kind of conversion is missing?

Thanks for providing a note on what you are actually doing. I am all in for simplifying the API, but I want to keep it correspond to what is in the XML files. Right now, the types are declared

        value: Union[str, List[str]],

which is what is seen with XML. I need an example of where this is done differently by the XML.

stanislaw avatar Feb 12 '25 09:02 stanislaw

The thing is that in the ReqIF they are string based, but when creating one from scratch and unparsing it, it gets inconvenient.

In https://github.com/strictdoc-project/reqif/pull/176 I (already) extended one of your integration tests with at least a part.

torsknod2 avatar Feb 13 '25 20:02 torsknod2

What you are showing in #176 looks good. Please proceed with implementing it as your time allows.

stanislaw avatar Feb 18 '25 09:02 stanislaw