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

Surprising literal comparisons #161

Closed
jesper-friis opened this issue Jan 2, 2024 · 1 comment · Fixed by #164
Closed

Surprising literal comparisons #161

jesper-friis opened this issue Jan 2, 2024 · 1 comment · Fixed by #164

Comments

@jesper-friis
Copy link
Contributor

jesper-friis commented Jan 2, 2024

The following comparisons between a Literal and another object may be surprising:

In [7]: Literal("abc", datatype=XSD.string) == "abc"
Out[7]: True

In [10]: Literal(1, datatype=XSD.int) == 1
Out[10]: False
 
In [11]: Literal(1, datatype=XSD.int) == "1"
Out[11]: True

This is an unintended consequence of Literal being a subclass of str.

A suggestion is to add an __eq__() method to Literal that uses tripper.utils.parse_literal() to convert all non-literal objects to a Literal and then require that value, lang and datatype all must be equal for equality to be true.

@jesper-friis
Copy link
Contributor Author

Adding __eq__() (and __hash__()) to Literal causes failures in mapping due to the changed comparison logics.

Updating mappings to the new behaviour of literal comparisons may require little more effort. Are there also some third party libraries that depends on tripper that we will break?

jesper-friis added a commit that referenced this issue Jan 2, 2024
@jesper-friis jesper-friis linked a pull request Jan 3, 2024 that will close this issue
9 tasks
jesper-friis added a commit that referenced this issue Jan 26, 2024
# Description:
Improved literal equality comparisons. They now compare as expected. 

Note, this PR builds on top of PR #163

Closes #161 

## Type of change:
<!-- Put an `x` in the box that applies. -->
- [ ] Bug fix and code cleanup.
- [x] New feature.
- [ ] Documentation update.
- [ ] Testing.
jesper-friis added a commit that referenced this issue Feb 13, 2024
# Description:
Closes #160 

Also added `fallback_backend` option to `Triplestore.parse()` and
`Triplestore.serialize()` to allow calling parse() and serialize() with
the collection backend (using rdflib under the hood).

**Note** that this PR builds on top of PR #161 

**Note** also that this PR utilises DLite PR
SINTEF/dlite#755. It is probably a good idea to
merge that PR and create a new release of DLite before merging this PR
to master.

## Type of change:
<!-- Put an `x` in the box that applies. -->
- [x] Bug fix and code cleanup.
- [x] New feature.
- [ ] Documentation update.
- [ ] Testing.

## Checklist for the reviewer:
<!-- Put an `x` in the boxes that apply. These can be filled by reviewer
after the PR is created. -->

This checklist should be used as a help for the reviewer.

- [ ] Is the change limited to one issue?
- [ ] Does this PR close the issue?
- [ ] Is the code easy to read and understand?
- [ ] Do all new feature have an accompanying new test?
- [ ] Has the documentation been updated as necessary?
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 a pull request may close this issue.

1 participant