Ticket #12683 (new defect)

Opened 14 months ago

Last modified 12 months ago

Inappropriate comparison of method

Reported by: culler Owned by: AlexGhitza
Priority: major Milestone: sage-5.10
Component: basic arithmetic Keywords: rich comparison
Cc: Work issues:
Report Upstream: N/A Reviewers:
Authors: Merged in:
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

comment:1 Changed 14 months ago by culler

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

comment:2 Changed 12 months 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

Note: See TracTickets for help on using tickets.