-
-
Notifications
You must be signed in to change notification settings - Fork 544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support __richcmp__ in Python classes #23102
Comments
This comment has been minimized.
This comment has been minimized.
comment:2
What about using |
Branch: u/jdemeyer/ticket/23102 |
comment:5
Replying to @tscrim:
New commits:
|
Commit: |
Dependencies: #23103 |
This comment has been minimized.
This comment has been minimized.
comment:8
Note that from #22828, there is
in
that should also be moved to the common new place. |
comment:9
Replying to @fchapoton:
Makes sense. I created #23109 for that. |
comment:10
Typo in |
comment:11
Replying to @tscrim:
I just did that, see attachment: cmp-timing.py First of all, for a plain equality check (
Now, comparisons involving
As one might expect, the time is roughly linear in the number of Python method calls. |
Attachment: cmp-timing.py.gz Small script to test timing |
Reviewer: Travis Scrimshaw |
comment:12
Thank you for running those timings. That is more than enough to convince me. If tests pass, you can set a positive review on my behalf. Sleepy time for me now. :) |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Changed branch from u/jdemeyer/ticket/23102 to |
Changed commit from |
comment:16
This happened randomly:
|
comment:17
Confirmed. It seems that the category framework gets in the way. Commenting out this line fixes the problem
|
comment:36
As an aside, I wonder if there's ever been a proposal to actually support |
comment:37
A close reading of PEP-207 reveals:
which makes perfect sense. But, if as Sage demonstrates, there's a usecase for a single user-defined |
Commit: |
Changed branch from |
comment:39
I'll work on it right now. |
comment:41
Travis: you put back the wrong branch. This is the original branch, rebased to 8.0.beta11. |
comment:42
Ah, sorry; I had thought |
comment:43
Replying to @embray:
Good point. It didn't occur to me to use the C/API for this. Python doesn't expose this type anywhere AFAIK, but the C/API does. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:45
I think this addresses all Erik's concerns. |
Changed reviewer from Travis Scrimshaw to Travis Scrimshaw, Erik Bray |
comment:46
Replying to @jdemeyer:
You can get at it in Python, for example, with |
comment:47
is this ready to go ? |
comment:48
Erik? |
comment:49
Yep, perfect--thanks. |
Changed branch from u/jdemeyer/ticket/23102 to |
Sage has a lot of functionality to deal with "rich comparisons" using
__richcmp__
in Cython or_richcmp_
in Python or Cython for subclasses ofElement
. However, we are still missing rich comparison support for Python classes which are not subclasses fromElement
.A good example of this is
RealSet
insrc/sage/sets/real_set.py
. Currently, comparison is implemented using__cmp__
. Changing this to Python 3 comparisons would normally require 6 methods (__eq__
,__ne__
,__lt__
,__le__
,__gt__
,__ge__
). It would be convenient to support this with just one__richcmp__
method like in Cython.This ticket proposes:
Add a decorator
richcmp_method
which adds support for__richcmp__
to a Python class.Implement
RealSet.__richcmp__
using this.Depends on #23103
CC: @fchapoton @tscrim @embray
Component: python3
Author: Jeroen Demeyer
Branch/Commit:
4d1021b
Reviewer: Travis Scrimshaw, Erik Bray
Issue created by migration from https://trac.sagemath.org/ticket/23102
The text was updated successfully, but these errors were encountered: