Fix parser bug and add test by bovlb · Pull Request #2943 · RDFLib/rdflib (original) (raw)

The issue is that the terms are not always strings. The __eq__ method on CompValue successfully returns False in this case, but the __contains__ method on str apparently raises a type error, although I can’t find any documentation of this behaviour. Compare with the similar test on line 72.

Edit: The test we're running afoul of is here.

Edit 2: This is likely because __contains__ on str is defined in terms of substrings, rather then the usual container membership. The functionality we want here is, however, container membership. A simpler fix might have been to make the string into a simpler container:

if i + 1 < l_ and terms[i + 1] not in list(".,;"):

or simply avoid representing lists as strings in the first place:

if i + 1 < l_ and terms[i + 1] not in [".", ",", ";"]:

Edit 3: I changed to the last version with a brief comment. (Sadly it is four lines longer after black formatting.)