| 274 | # Test that sorted() uses __lt__ (not __gt__) for comparisons. |
| 275 | # Track which comparison method is actually called during sort. |
| 276 | class TrackComparison: |
| 277 | lt_calls = 0 |
| 278 | gt_calls = 0 |
| 279 | |
| 280 | def __init__(self, value): |
| 281 | self.value = value |
| 282 | |
| 283 | def __lt__(self, other): |
| 284 | TrackComparison.lt_calls += 1 |
| 285 | return self.value < other.value |
| 286 | |
| 287 | def __gt__(self, other): |
| 288 | TrackComparison.gt_calls += 1 |
| 289 | return self.value > other.value |
| 290 | |
| 291 | |
| 292 | # Reset and test sorted() |