gjhiggins/rdflib — Issue #127: Literal.__str__ does not behave like unicode
Author: gjhiggins
Created: 2011-10-19 01:27:59+00:00
State: open

Originally filed by pierre.a...@gmail.com on 2010-05-18T13:29:40

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.