Opened 4 years ago
Last modified 9 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: | todo |
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 (9)
comment:1 Changed 4 years ago by culler
comment:2 Changed 4 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 3 years ago by jdemeyer
- Milestone changed from sage-5.11 to sage-5.12
comment:4 Changed 2 years ago by vbraun_spam
- Milestone changed from sage-6.1 to sage-6.2
comment:5 Changed 2 years ago by vbraun_spam
- Milestone changed from sage-6.2 to sage-6.3
comment:6 Changed 22 months ago by vbraun_spam
- Milestone changed from sage-6.3 to sage-6.4
comment:7 Changed 9 months ago by jakobkroeker
fixed?
comment:8 Changed 9 months 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
True
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
True
Nonetheless, that does not make it a desirable behavior in Sage.
Anyway, as far as I can see, nothing has changed.
comment:9 Changed 9 months ago by jakobkroeker
- Stopgaps set to todo
An even better solution would be to raise a TypeError?, as would happen in Python 3.