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

fix sparql path order on python3 #525

Merged
merged 3 commits into from
Sep 23, 2015

Conversation

joernhees
Copy link
Member

see #492

@joernhees joernhees added bug Something isn't working in-resolution SPARQL labels Sep 23, 2015
@joernhees joernhees self-assigned this Sep 23, 2015
@joernhees joernhees added this to the rdflib 4.2.2 milestone Sep 23, 2015
joernhees added a commit that referenced this pull request Sep 23, 2015
@joernhees joernhees merged commit c9ebcaf into RDFLib:master Sep 23, 2015
@joernhees joernhees deleted the fix_sparql_path_order branch September 23, 2015 16:38
@gromgull
Copy link
Member

this would have been an excellent opportunity to implement eq as well, it will work now, but things will be equal on id(object), not on two Paths of the same type with the same arguments :)

@joernhees
Copy link
Member Author

hehe, i admit, i didn't think about this for a long time... i considered using functools.total_ordering on the Path class, but then thought that each of the repr actually return the internal's str not their repr. i decided to pretend as little as possible that we do any meaningful comparison of Path objects and just solve one problem at a time... we need < for py3 sorting, nothing more...

also otherwise:

In [1]: from rdflib.paths import Path, InvPath

In [2]: repr(Path())
Out[2]: '<rdflib.paths.Path instance at 0x10db2ed88>'

In [3]: repr(InvPath(Path()))
Out[3]: 'Path(~<rdflib.paths.Path instance at 0x10db93440>)'

In [4]: repr(InvPath(InvPath(Path())))
Out[4]: 'Path(~Path(~<rdflib.paths.Path instance at 0x10db935f0>))'

(good old semantic or syntactic equivalence discussion... i'd have used object's < if there was one in py3)

but if you want i just add __eq__ and also use functools.total_ordering... not that hard ^^

@joernhees
Copy link
Member Author

from functools import total_ordering
@total_ordering
class Path(object):
    def eval(self, graph, subj=None, obj=None):
        raise NotImplementedError()

    def __eq__(self, other):
        if not isinstance(other, Path):
            raise TypeError('incomparable types: %s() == %s()' % (
                repr(self), repr(other)))
        return repr(self) == repr(other)

    def __lt__(self, other):
        if not isinstance(other, Path):
            raise TypeError('unorderable types: %s() < %s()' % (
                repr(self), repr(other)))
        return repr(self) < repr(other)

?

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

Successfully merging this pull request may close these issues.

2 participants