Is `typ` a str or list of strings?
ruamel.yaml is a YAML 1.2 parser/emitter for Python
Brought to you by:
anthon
The following code based on the example:
yaml = YAML(typ=["rt", "string"])
results in the following mypy error:
Argument "typ" to "YAML" has incompatible type "List[str]"; expected "Optional[str]"
Looking at https://sourceforge.net/u/jspricke/ruamel-yaml/ci/default/tree/main.py#l55
It appears to be typed hinted as Optional[Text]
However at https://sourceforge.net/u/jspricke/ruamel-yaml/ci/default/tree/main.py#l66
self.typ = ['rt'] if typ is None else (typ if isinstance(typ, list) else [typ])
It's always initialised as a list of typ.
In most the code that operates on typ it uses in which can work on either a list or a string.
So assuming that support for either a single string containing the different types, or list of strings of the types is intended, then perhaps the type hint should be Optional[List[Text] | Text] ?
Or should the type hint just be Optional[List[Text]]?
It should be
Optional[List[Text] | Text].Although internally a list of strings is presumed, for convenience you can provide just a string argument that is converted to a list of strings.
Thanks for confirming @anthon. I've updated the commit in my MR: https://sourceforge.net/p/ruamel-yaml/code/merge-requests/7/
Fixed in 0.17.23, I had to change
typtoOptional[Union[List[Text], Text]]as theUnion Operator from PEP 604 was not introduced until Python 3.10.