pyjnius icon indicating copy to clipboard operation
pyjnius copied to clipboard

Remove python long to support Cython >= 3.1.x

Open cmacdonald opened this issue 5 months ago • 3 comments

In https://github.com/kivy/pyjnius/pull/753#issuecomment-2969400311 it was suggested by @da-woods that the fix for #753 was sub-optimal:

ctypes.c_long probably isn't the right fix. isinstance(x, long) was testing for the Python 2 long type (which no longer exists in Python 3 - Python 3 just has one integer type that covers both large and small integers).

This PR:

  • removes ctypes.c_long
  • when scoring method signatures, it better tests argument value ranges for compatibility for both short and integer types
  • adds some more test cases
  • adds a debug kwarg for method and constructor invocation that displays the scores of the different methods that are being scored in calculate_scores(). This may be useful when use of the signature kwarg is necessary.

Example output:

>>> clz = autoclass("org.jnius.SignatureTest$IntOrLong")
>>> obj = clz(0, debug=True) # could be int or long
[(20, '(I)V', 'V', ('I',), (0,)), (20, '(J)V', 'V', ('J',), (0,))]
Selected (J)V for invocation

(ie. constructors (I)V and (J)V both got score of 20, jnius selected (J)V.

cmacdonald avatar Jun 16 '25 23:06 cmacdonald

All failures are Pypy 3.8, which Cython 3.1 may not support?

cmacdonald avatar Jun 17 '25 09:06 cmacdonald

All failures are Pypy 3.8, which Cython 3.1 may not support?

I don't remember if it does or not off the top of my head, but I don't think anything in this change should need Cython 3.1. On earlier versions of Cython, long didn't do a lot except on Python 2.

da-woods avatar Jun 17 '25 11:06 da-woods

All failures are Pypy 3.8, which Cython 3.1 may not support?

We already looked at this in #752: see https://github.com/kivy/pyjnius/pull/753#issuecomment-2889148812

cmacdonald avatar Jun 17 '25 13:06 cmacdonald

  • This PR is required for https://github.com/kivy/python-for-android/pull/3180.

CC: @misl6

T-Dynamos avatar Jul 26 '25 14:07 T-Dynamos

Hi @cmacdonald, I've just pushed some changes that should fix the CI/CD pipeline, can you please rebase on top of master?

misl6 avatar Jul 27 '25 10:07 misl6

rebased!

cmacdonald avatar Jul 27 '25 11:07 cmacdonald

@T-Dynamos + @cmacdonald , I guess we're only missing Python 3.13 support (and maybe Cython < 3) removal to process a release?

misl6 avatar Jul 27 '25 11:07 misl6

@misl6 Yes, I believe this is ready for release. I've also tested this PR on Android.

T-Dynamos avatar Jul 27 '25 11:07 T-Dynamos