Opened 3 years ago

Last modified 12 months 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:


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 (6)

comment:1 Changed 3 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 18 months ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:5 Changed 15 months ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:6 Changed 12 months ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4
Note: See TracTickets for help on using tickets.