mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
* Accept `__index__` objects for integer arguments CPython converts these nine arguments with `__index__`, RustPython required an exact `int`. Uses the existing `ArgSize`/`ArgPrimitiveIndex` converters at each call site rather than widening the blanket `int` conversion, so argument paths CPython keeps strict (ctypes pointers, thread handles) are unaffected, and the range check happens while the argument is bound rather than in the method body. Also widens `maxsplit` before adding one. `sys.maxsize` was already reachable there with a plain `int` and overflowed in a debug build. Assisted-by: Claude Code:claude-opus-5 * Add snippet for `__index__` argument conversion Expectations verified against CPython 3.14. Assisted-by: Claude Code:claude-opus-5 * Call __index__ in primitive integer conversion; add ArgStrictInt The TryFromObject impls for isize, usize and the fixed-width integer types now take an int (or subclass) as-is and otherwise call __index__, instead of accepting only int instances. ArgStrictInt<T> keeps the old int-only conversion. The ctypes address and handle arguments (from_address, PyObj_FromPtr, dlsym, dlclose, call_function, call_cdeclfunction, non-Windows FreeLibrary) use it. _thread._make_thread_handle checks for an int itself and raises "ident must be an integer". Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Accept __index__ where arguments were bound as int objects chr, bin, math.factorial, zlib.crc32/adler32, binascii.crc32/crc_hqx, the start/stop of sequence index(), the select event mask and a __len__ result took an int object directly and rejected other objects with __index__. They now go through __index__. math.ldexp still accepts only an int for its exponent and raises "Expected an int as second argument to ldexp." otherwise. Extend protocol_index_argument.py with the newly accepted calls, an int subclass whose __index__ is not called, and the sites that still reject __index__. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 * Replace ArgPrimitiveIndex and ArgSize with PySsize/PySize aliases The primitive integer conversions call __index__ themselves, so ArgPrimitiveIndex<T> and its alias ArgSize behaved the same as T. They are removed. Arguments that used ArgSize or ArgPrimitiveIndex<isize> now take PySsize (= isize), ArgPrimitiveIndex<usize> takes PySize (= usize), and the other ArgPrimitiveIndex<T> take T. Those with a literal fallback take it as a `default`; those where a missing argument is a distinct state stay OptionalArg. list.insert is a #[pymethod] again instead of going through a wrapper. Assisted-by: Claude:claude-opus-5-5 Assisted-by: Grok:grok-4.7 --------- Co-authored-by: Roshan Ramani <roshanramani.dev@gmail.com>
Test snippets
This directory contains two sets of test snippets which can be run in Python.
The snippets/ directory contains functional tests, and the benchmarks/
directory contains snippets for use in benchmarking RustPython's performance.
Setup
Our testing depends on pytest, which you can install using pip.
Running
Simply run pytest -v in this directory, and the tests should run (and hopefully
pass). If it hangs for a long time, that's because it's building RustPython in
release mode, which should take less time than it would to run every test
snippet with RustPython compiled in debug mode.