RDFLib/rdflib — Issue #164: toPython() returns Literal instead of string/unicode for typed string literals
Author: gjhiggins
Created: 2012-02-20 08:34:11+00:00
State: open

bernhard...@gmail.com, 2011-08-08T13:17:27.000Z

What steps will reproduce the problem?
>>> from rdflib.term import Literal
>>> l=Literal('foobar')
>>> l.toPython().__class__

>>> from rdflib.namespace import XSD
>>> l2=Literal('foobar', datatype=XSD.string)
>>> l2.toPython().__class__

What is the expected output? What do you see instead?
Expected output would be a string or unicode object.

What version of the product are you using? On what operating system?
rdflib revision 37d3cbfff340

Please provide any additional information below.

Comment 1 by gromgull
I propose a fix to this in http://code.google.com/p/rdflib/source/detail?r=6fc727b16a3d40627b0f534b8e62e91a864281fb

I messed up the google code issue integration syntax as usual, so copy paste here:

This is a simple fix - does it break anything for anyone? How
did you come across this bug anyway Bernard?

Comment 2 by bernhard...@gmail.com
The fix is straightforward and works for me. I came across this since we build forms around RDF graphs, for which we need to convert all literals to python objects.

Comment 3 by gromgull
Ok!

I'll give the sleeping/lurking hordes some days to look at this and tell me if there is any reason why toPython should ever return a Literal object before I'll merge

Comment 4 by lindstr...@gmail.com
This sleeper spontaneously finds the fix good and sound. ;)

Comment 5 by ahmedba...@gmail.com
I still encountered this bug with rdflib 3.1.0.
Has the fix not been committed yet?