Skip to content

Commit 14e8d7f

Browse files
authored
Prevent crash when comparing ill-typed numeric types. (#2949)
1 parent 717ef40 commit 14e8d7f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

rdflib/term.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,15 @@ def __gt__(self, other: Any) -> bool:
11071107
if other is None:
11081108
return True # Everything is greater than None
11091109
if isinstance(other, Literal):
1110+
# Fast path for comapring numeric literals
1111+
# that are not ill-typed and don't have a None value
11101112
if (
1111-
self.datatype in _NUMERIC_LITERAL_TYPES
1112-
and other.datatype in _NUMERIC_LITERAL_TYPES
1113+
(
1114+
self.datatype in _NUMERIC_LITERAL_TYPES
1115+
and other.datatype in _NUMERIC_LITERAL_TYPES
1116+
)
1117+
and ((not self.ill_typed) and (not other.ill_typed))
1118+
and (self.value is not None and other.value is not None)
11131119
):
11141120
return self.value > other.value
11151121

0 commit comments

Comments
 (0)