RDFLib/rdflib — Issue #120: Literal.__str__ does not behave like unicode
Author: gjhiggins
Created: 2012-02-20 08:33:12+00:00
State: open

pierre.a...@gmail.com, 2010-05-18T13:29:40.000Z

Literal is a subclass of unicode.
However, its __str__ method has not the same semantics as unicode's,
because it uses the "unicode-escape" codec instead of the default system
codec.

>>> from rdflib import Literal
>>> str(unicode('a\n'))
'a\n'
>>> str(Literal('a\n'))
'a\\n'
>>> str(unicode(Literal('a\n')))
'a\n'

This might be a feature, but breaks expectations: I tend to use Literals as
any other unicode strings (slicing, startswith, etc...), so having to
manage them specially only for str conversion seems a misfeature.

Comment 1 by eike...@gmail.com
Pierre, thank you for reporting this issue.

I know there are some unresolvable issues that arise from the choice of having Literal subclass unicode. I'm not
sure if this is one of the unresolvable ones or not. We should take a look to see if we can fix this issue without
breaking other bits. I'll work on a patch now to see what all fixing this will entail.

Comment 2 by eik...@gmail.com
This issue was closed by revision r1876.

Comment 3 by eike...@gmail.com
Unless this breaks bits for which we do not yet have a test case. We are good to go; the fix was fairly straight
forward. If there are broken bits as a result of this change we'll need a test case for it.

Comment 4 by eik...@gmail.com
This issue was closed by revision a37a1cf8a191.