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

Overdue restoration of functools total_order decorator. #1528

Merged
merged 3 commits into from Dec 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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