Opened 4 years ago

Last modified 7 weeks ago

#12683 new defect

Inappropriate comparison of method

Reported by: culler Owned by: AlexGhitza
Priority: major Milestone: sage-6.4
Component: basic arithmetic Keywords: rich comparison
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps: todo


sage: z = 3+4j
sage: z.real < 0

It is very easy to encounter this when importing working python scripts into Sage. But it can be a bear to fix since there is no indication of any problem, other than wrong answers.

There is no meaningful sense in which the method z.real should be considered less than the number 0. So this comparison should return NotImplemented?. In fact, I would suggest that every comparison between a method and any other object should return NotImplemented?.

Change History (9)

comment:1 Changed 4 years ago by culler

An even better solution would be to raise a TypeError?, as would happen in Python 3.

comment:2 Changed 3 years ago by tscrim

This is a python issue:

sage: class bla: 
....:     def f(self): pass
sage: x = bla()
sage: x.f < int(0)

I believe this should be fixed in python 3.0:

comment:3 Changed 2 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:4 Changed 21 months ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:5 Changed 18 months ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:6 Changed 14 months ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:7 Changed 7 weeks ago by jakobkroeker


comment:8 Changed 7 weeks ago by culler

The original behavior still persists in sage 6.8, although the value of the comparison has been reversed:

sage: z = 3-4j
sage: z.imag > 0

Also, it is still true that the behavior is inherited from python. In python 2.7.9 one has:

class bla:

... def f(self):
... pass

x = bla()
x.f > 0


Nonetheless, that does not make it a desirable behavior in Sage.

Anyway, as far as I can see, nothing has changed.

comment:9 Changed 7 weeks ago by jakobkroeker

  • Stopgaps set to todo
Note: See TracTickets for help on using tickets.