Skip to content

MANT: Replace PyObject_Compare with PyObject_RichCompareBool #6265

Closed

Description

@jaimefrio

See #6236 (comment). Since our oldest supported Python version is 2.6, there is no longer a need for separate compilation paths for Python 2.x and 3.x, for Python object comparison, since both provide PyObject_RichCompareBool. It may also be a good idea to get rid of the Pyobject_Cmp function, defined for Python 3.x in npy_3kcompat.h, which was recently discovered to be broken by @pv, see #6229 (comment).

I'll try to put a PR together for this shortly, unless someone else wants the glory for themselves.

Activity

  1. yashmehrotra commented on Aug 29, 2015

    @yashmehrotra
    Contributor

    @jaimefrio Hi Jaime, I would like to work on this bug. Can you help me get started ? Apart from removing the PyObject_Cmp, what all things must be done ?

  2. jaimefrio commented on Aug 29, 2015

    @jaimefrio
    MemberAuthor

    I'm having trouble with GitHub finding your user name when trying to do the assignment. But please, consider it assigned and go do it!

  3. yashmehrotra commented on Aug 29, 2015

    @yashmehrotra
    Contributor

    @jaimefrio Could you help me a bit with this. I understood that the PyObject_Cmp must be removed from npy_3kcompat.h. Are there any other changes that I have to look out for ? Also, can you direct me to where I have to make the changes for compilation paths.
    Sorry for taking your time but frankly saying, this codebase is very big compared to what I used to work with. Thanks.

  4. jaimefrio commented on Aug 29, 2015

    @jaimefrio
    MemberAuthor

    Removing PyObject_Cmp entirely may require exercising some care, as it may be used by third parties that use NumPy. A quick search of github for npy_3kcompat.h gives thousands of hits, but only a handful of those seems to also be using PyObject_Cmp, and those appear to all be clones of the main repository. In any case, sending an e-mail to the list would be in order, outlining the options:

    • Remove the function completely now, or
    • Fix it, add a deprecation warning, and schedule it for removal in 1.12.

    But that can be done later in a follow up PR. The more relevant part of this would be to remove all uses of PyObject_Cmp and PyObject_Compare from the code base. A quick search shows only a handful of occurrences of PyObject_Compare, all of which happen inside the #else part of an #if defined(NPY_PY3K) block. There may be subtleties, but we basically want to remove the preprocessor instructions and leave the Py3K block only.

    The one exception is the block holding the single use of PyObject_Cmp in our code base. That would have to be rewritten in terms of PyObject_RichCompareBool.

    Does this make sense?

  5. yashmehrotra commented on Aug 29, 2015

    @yashmehrotra
    Contributor

    @jaimefrio Yup. Thanks a lot. Getting started with it right now.

  6. yashmehrotra commented on Sep 2, 2015

    @yashmehrotra
    Contributor

    @jaimefrio Any updates on this issue ?

  7. jaimefrio commented on Sep 2, 2015

    @jaimefrio
    MemberAuthor

    Do you follow the mailing list? There was some discussion there on what the right thing to do is, and there is not much of a consensus. Not sure how to go about this...

  8. shoyer commented on Sep 2, 2015

    @shoyer
    Member

    I agree that raising an exception for now is probably the right way to handle this edge case. It's the least likely to lock us in to any undesired behavior in the future.

  9. seberg commented on Sep 3, 2015

    @seberg
    Member

    +1, its true, we may be able to get the 90% version, but if there is no difficulty with avoiding the 10% error margin for the moment, lets just do that :).

  10. yashmehrotra commented on Sep 3, 2015

    @yashmehrotra
    Contributor

    @jaimefrio In the discussion from the mailing-list and the discussion here, I guess raising an exception is the way to go, what do you think ?
    Also, if you think we should raise an exception, should I go forward with it ?

  11. added a commit that references this issue on Sep 28, 2015
    f43d691
  12. added a commit that references this issue on Mar 22, 2016
    5a0a03a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions