Skip to content

Commit

Permalink
Merge pull request #1528 from gjhiggins/restore-total-ordering-to-paths
Browse files Browse the repository at this point in the history
Overdue restoration of functools total_order decorator.
  • Loading branch information
nicholascar authored Dec 28, 2021
2 parents a863a72 + 51affda commit b1f2ac1
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions rdflib/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
"""


from functools import total_ordering
from rdflib.term import URIRef, Node
from typing import Union, Callable

Expand All @@ -192,6 +193,7 @@
ZeroOrOne = "?"


@total_ordering
class Path(object):

__or__: Callable[["Path", Union["URIRef", "Path"]], "AlternativePath"]
Expand All @@ -203,35 +205,13 @@ class Path(object):
def eval(self, graph, subj=None, obj=None):
raise NotImplementedError()

def __hash__(self):
return hash(repr(self))

def __eq__(self, other):
return repr(self) == repr(other)

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

def __le__(self, other):
if not isinstance(other, (Path, Node)):
raise TypeError(
"unorderable types: %s() < %s()" % (repr(self), repr(other))
)
return repr(self) <= repr(other)

def __ne__(self, other):
return not self == other

def __gt__(self, other):
return not self <= other

def __ge__(self, other):
return not self < other


class InvPath(Path):
def __init__(self, arg):
Expand Down

0 comments on commit b1f2ac1

Please sign in to comment.