Opened 3 years ago

Last modified 3 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:

Description

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

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 2 years ago by tscrim

This is a python issue:

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

I believe this should be fixed in python 3.0:
http://docs.python.org/release/3.0.1/whatsnew/3.0.html#ordering-comparisons

comment:3 Changed 15 months ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:4 Changed 9 months ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:5 Changed 6 months ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:6 Changed 3 months ago by vbraun_spam

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