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

there is no use-case of comparing a Literal with None (I think) #1155

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

FlorianLudwig
Copy link
Contributor

This is somewhat of a question: What is the use-case of comparing a Literate instance to None? I didn't find any, so I removed the checks from the comparing functions and all tests still passed.

@FlorianLudwig FlorianLudwig changed the title there is no use-case of comparing a Literal with None there is no use-case of comparing a Literal with None (I think) Aug 31, 2020
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 75.487% when pulling 99a8a0f on FlorianLudwig:comparing_literal_with_none into 652d2e6 on RDFLib:master.

Copy link
Member

@white-gecko white-gecko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my eyes this is ok. The instance check will return False for None and thus we will end at NotImplemented or False in the case of equals, which is good. As we are heading towards a major release breaking changes are ok.

@nicholascar
Copy link
Member

@ashleysommer and I talked about this sort of thing at our last meeting a couple of weeks back. Ashley, what did we decide here?

@ashleysommer
Copy link
Contributor

We discussed the merits of storing None vs False when parsing an invalid xsd:boolean literal. Technically both are wrong, but we need to choose one or the other (or throw an exception), and all literals must follow consistent rules.

However, that is not related to this Issue/PR.

The only thing I can see this is a maybe problem here is the possibility of breaking Literal Total Ordering. Given that feature is only concerned with comparing Literals with Literals, this change is probably fine.

As @white-gecko said, this is a breaking change. Users with code which expects Literal(1) > None to evaluate to True will now get a NotImplemented object/type returned. That will be a weird bug to hunt down for those poor people. Would it be better to actually throw a NotImplementedError() instead?

@FlorianLudwig
Copy link
Contributor Author

FlorianLudwig commented Sep 9, 2020

I would expect a TypeError raised, to be honest. NotImplemented is returned as it is checked within the sparql evaluation code to throw a SPARQLError, See:

https://github.com/RDFLib/rdflib/blob/master/rdflib/plugins/sparql/operators.py#L857

Interestingly raising a TypeError would actually lead to the same result.

@FlorianLudwig
Copy link
Contributor Author

FlorianLudwig commented Sep 9, 2020

On a somewhat related note, I have yet to understand when SPAQRL is supposed to throw an error and when silently just return an empty literal. For example DAY(xsd:Date) results in an empty string and I would have expected a TypeError as DAY() only accepts xsd:DateTime.

Pointers on the expected behaviour are welcome as I would like to do some refactoring on the sparql evaluation :) [with this MR being the first step]

@white-gecko
Copy link
Member

In case of DAY() the spec states

This function corresponds to fn:day-from-dateTime.

In the "XPath and XQuery Functions and Operators 3.1" Recommendation there is a statement about errors: https://www.w3.org/TR/xpath-functions/#errors-and-diagnostics also some functions have Error Conditions specified. I assume if no Error Conditions are specified, the function returns no errors.

Also for the operators I think to be sure it is necessary to dive into the XPath specs: https://www.w3.org/TR/sparql11-query/#OperatorMapping

Copy link
Contributor

@ashleysommer ashleysommer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to throw TypeError() when trying to compare Literal to None? Seems like that is the correct solution.

@@ -1041,7 +1037,8 @@ def __eq__(self, other):
"""
if self is other:
return True
if other is None:

if other is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats going on with the indentation here? This line is offset by two spaces?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants