fix sparql path order on python3 by joernhees · Pull Request #525 · RDFLib/rdflib (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation3 Commits3 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

joernhees

joernhees added a commit that referenced this pull request

Sep 23, 2015

@joernhees

fix sparql path order on python3

@gromgull

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

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

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)

?

This was referenced

Mar 16, 2017

2 participants

@joernhees @gromgull