Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: term.Literal.__add__ #451

Closed
wants to merge 1 commit into from
Closed

Bugfix: term.Literal.__add__ #451

wants to merge 1 commit into from

Conversation

pinbe
Copy link

@pinbe pinbe commented Jan 29, 2015

As long as Literal(1) is internaly casted by int, Literal(1) + Literal(1) may return Literal(2) instead of Literal('11').

…+ Literal(1) may return Literal(2) instead of Literal('11').
@gromgull
Copy link
Member

That is the intended behaviour. Literal comparisons and operations are done in value space to make it easy to implement the SPARQL engine. See https://rdflib.readthedocs.org/en/latest/upgrade3to4.html#datatyped-literals

@gromgull gromgull closed this Jan 29, 2015
@gromgull gromgull reopened this Jan 29, 2015
@gromgull
Copy link
Member

Wait - I may have been too hasty :)

@pinbe
Copy link
Author

pinbe commented Jan 29, 2015

Le 29 janv. 2015 à 15:08, Gunnar Aastrand Grimnes notifications@github.com a écrit :

Wait - I may have been too hasty :)

Thank you your reply. I was preparing a more detailed explanation, just below :-) just bellow.

Regards.
Benoît Pin.


Thank for your reply: You confirms that comparisons and operations should be done in the value space.
Actually, this information also confirm the Literal.add method is buggy.
The bug report was probably too short.
Let me explain longer:

Here's two literals that are integer values

>>> one = Literal(1)
>>> two = Literal(2)
>>> print one.datatype, two.datatype
http://www.w3.org/2001/XMLSchema#integer http://www.w3.org/2001/XMLSchema#integer

Now, let's do the sum with the current rdflib version

>>> print one + two
12

This buggy result denotes that the sum has been made in the lexical space.

After applying the proposed fix, you will obtain the correct result in the value space.

>>> print one + two
3
>>> print (one + two).datatype
http://www.w3.org/2001/XMLSchema#integer

@joernhees joernhees added the bug Something isn't working label Aug 11, 2015
@gromgull gromgull added this to the rdflib 5.0.0 milestone Jan 12, 2017
@nicholascar nicholascar mentioned this pull request Mar 19, 2020
@nicholascar
Copy link
Member

nicholascar commented Mar 23, 2020

Replaced by PR #978 which is updated with commits since this PR and also new tests for move addition value and type combinations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants