Opened 14 years ago

Closed 13 years ago

Last modified 5 years ago

#3936 closed defect (invalid)

Throw exceptions on nonsensical comparisons?

Reported by: nbruin Owned by: tbd
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: algebra Keywords:
Cc: jakobkroeker Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

It is impossible to have Python's universal comparison and have mathematically sound meaning to comparison. Transitivity and/or other properties have to cave at some point.

One example:

sage: L=[int(0),None,1,int(2),3]
sage: L.sort()
sage: L
[1, None, 0, 2, 3]
sage: L[0]<L[2]
False

Would it be at all feasible to throw exceptions on non-sensical comparisons, such as 1 > None ? ** instead of ^ seems pretty mild compared to this.

Change History (4)

comment:1 Changed 14 years ago by robertwb

What about 1 == None or 1 != None, should those throw errors as well? (They use the same code).

comment:2 Changed 13 years ago by craigcitro

  • Resolution set to invalid
  • Status changed from new to closed

As Rob points out, there's really no way to do this cleanly. In particular, though, how often do you end up accidentally comparing an integer to something like None? It seems much better to have an occasional result that seems strange at first than to break Python conventions, and run into more serious problems because of it.

I'm closing this as invalid.

comment:3 Changed 13 years ago by mabshoff

  • Milestone changed from sage-3.4.1 to sage-duplicate/invalid/wontfix

comment:4 Changed 5 years ago by jakobkroeker

  • Cc jakobkroeker added
  • Report Upstream set to N/A
Note: See TracTickets for help on using tickets.