diff --git a/rdflib/plugins/serializers/turtle.py b/rdflib/plugins/serializers/turtle.py index d28c5bc87..a26df04a6 100644 --- a/rdflib/plugins/serializers/turtle.py +++ b/rdflib/plugins/serializers/turtle.py @@ -6,7 +6,6 @@ from __future__ import annotations from collections import defaultdict -from functools import cmp_to_key from typing import ( IO, TYPE_CHECKING, @@ -32,34 +31,6 @@ __all__ = ["RecursiveSerializer", "TurtleSerializer"] -def _object_comparator(a: Node, b: Node) -> int: - """ - for nice clean output we sort the objects of triples, - some of them are literals, - these are sorted according to the sort order of the underlying python objects - in py3 not all things are comparable. - This falls back on comparing string representations when not. - """ - - try: - # type error: Unsupported left operand type for > ("Node") - if a > b: # type: ignore[operator] - return 1 - # type error: Unsupported left operand type for < ("Node") - if a < b: # type: ignore[operator] - return -1 - return 0 - - except TypeError: - # type error: Incompatible types in assignment (expression has type "str", variable has type "Node") [assignment] - a = str(a) # type: ignore[assignment] - # type error: Incompatible types in assignment (expression has type "str", variable has type "Node") - b = str(b) # type: ignore[assignment] - # type error: Unsupported left operand type for > ("Node") [operator] - # type error: Unsupported left operand type for < ("Node") - return (a > b) - (a < b) # type: ignore[operator] - - class RecursiveSerializer(Serializer): topClasses = [RDFS.Class] predicateOrder = [RDF.type, RDFS.label] @@ -168,7 +139,7 @@ def sortProperties( Sort the lists of values. Return a sorted list of properties.""" # Sort object lists for prop, objects in properties.items(): - objects.sort(key=cmp_to_key(_object_comparator)) + objects.sort() # Make sorted list of properties propList: List[_PredicateType] = []