From caba1c8f76667919c4748c4cf5aec180691a5f1f Mon Sep 17 00:00:00 2001 From: Ashley Sommer Date: Wed, 23 Oct 2024 19:42:41 +1000 Subject: [PATCH] Prevent crash when comparing ill-typed numeric types. --- rdflib/term.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rdflib/term.py b/rdflib/term.py index bdc0e9732..9503d7779 100644 --- a/rdflib/term.py +++ b/rdflib/term.py @@ -1107,9 +1107,15 @@ def __gt__(self, other: Any) -> bool: if other is None: return True # Everything is greater than None if isinstance(other, Literal): + # Fast path for comapring numeric literals + # that are not ill-typed and don't have a None value if ( - self.datatype in _NUMERIC_LITERAL_TYPES - and other.datatype in _NUMERIC_LITERAL_TYPES + ( + self.datatype in _NUMERIC_LITERAL_TYPES + and other.datatype in _NUMERIC_LITERAL_TYPES + ) + and ((not self.ill_typed) and (not other.ill_typed)) + and (self.value is not None and other.value is not None) ): return self.value > other.value