Literal.toPython() support for xsd:hexBinary by bcogrel · Pull Request #388 · RDFLib/rdflib (original) (raw)

My point was to distinguish a regular string from a hexstring with the xsd:hexBinary datatype.

In this implementation I put specific rules first, before generic rules. The distinction between specific and generic rules is based on the datatype. Please note that the ordering of these rules is important.

We could use the more compressed structure you propose (and change _castPythonToLiteral() accordingly) if we consider that no the function _castPythonToLiteral() should never return a default datatype for a regular string.

Indeed, the rule (basestring, (None, _XSD_STRING)) would not be generic anymore while in with my approach ((basestring, None), (None, _XSD_STRING)) is still generic.

I think it is better to keep the distinction between the incoming and outcoming datatypes.