)]}'
{
  "commit": "a98ea67f4ebaee0c4746173d80bd6e84a76abcc3",
  "tree": "bb5c83d9214106053e130d5145d1d9f6f8d47557",
  "parents": [
    "4ad3a3c5d1aaa618200bf54e9a253f59bbc4a6ab"
  ],
  "author": {
    "name": "Jahongir Qurbonov",
    "email": "109198731+Jahongir-Qurbonov@users.noreply.github.com",
    "time": "Fri Nov 20 19:34:55 2026 +0500"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Fri Nov 20 15:34:55 2026 +0100"
  },
  "message": "[mypyc] Call __index__ when converting objects to u32 and u64 (#22484)\n\nConverting an object to `u32` or `u64` didn\u0027t call `__index__`, unlike\nevery other native int type. The unboxing slow paths\n`CPyLong_AsUInt32_()` and `CPyLong_AsUInt64_()` use\n`PyLong_AsUnsignedLong()` and `PyLong_AsUnsignedLongLong()`, which only\naccept int objects, while the helpers for `u8`, `u16` and the signed\ntypes use `PyLong_AsLongAndOverflow()`, which calls `__index__`.\n\nThis shows up in three places:\n\n```python\nfrom typing import Any\nfrom mypy_extensions import u16, u64\nimport librt.strings\n\nclass Index:\n    def __init__(self, n: int) -\u003e None:\n        self.n \u003d n\n    def __index__(self) -\u003e int:\n        return self.n\n\ndef take_u16(x: u16) -\u003e u16: return x\ndef take_u64(x: u64) -\u003e u64: return x\n\ndef coerce_u64(o: Any) -\u003e u64:\n    x: u64 \u003d o\n    return x\n```\n\n| | `u8`, `u16`, `i64` etc. | `u32`, `u64` before | `u32`, `u64` after |\n|---|---|---|---|\n| `take_u64(Index(5))` called from Python | `5` | `TypeError: u64 object\nexpected; got Index` | `5` |\n| `coerce_u64(Index(5))` | `5` | `TypeError: an integer is required` |\n`5` |\n| `coerce_u64(1.0)` | `TypeError: \u0027float\u0027 object cannot be interpreted\nas an integer` | `TypeError: an integer is required` | same as `u16` |\n| `librt.strings.write_u64_le(w, Index(5))` | writes `5` | `TypeError:\nan integer is required` | writes `5` |\n\nNow the slow paths convert a non-int object with `PyNumber_Index()`\nfirst. The fast path (a one-digit int) isn\u0027t changed, and an int still\ngoes straight to `PyLong_AsUnsigned*()`, so the only extra cost on the\nslow path for ints is an incref/decref. Negative and too large values\n(also when returned by `__index__`) still raise `ValueError: int too\nlarge or small to convert to u64`, and the overlapping error value 239\nis handled as before.\n\nTests: `testU32BasicOps` and `testU64BasicOps` now unbox objects with\n`__index__` (including 239 and the maximum value, and -1 and too large\nvalues, which raise `ValueError`), through both an implicit coercion and\na call from Python, and check the errors for a float.\n`testLibrtStringsI8AndUnsigned_librt` writes `Index` objects with all\n`write_u16/u32/u64_le/be` functions and checks the same errors. The\nthree tests fail without the change to `int_ops.c`.",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "36548e8adb4bfb17a63aa680c96c37cdb16bf5c8",
      "old_mode": 33188,
      "old_path": "mypyc/lib-rt/int_ops.c",
      "new_id": "5bd602039ddd59ef637046c98b4389bb8aa2d0ef",
      "new_mode": 33188,
      "new_path": "mypyc/lib-rt/int_ops.c"
    },
    {
      "type": "modify",
      "old_id": "e48f506011409f5fa2e9fcf14425e2a8cadb041f",
      "old_mode": 33188,
      "old_path": "mypyc/test-data/run-librt-strings.test",
      "new_id": "0e703ee5c3617a73035d735cce0611d67a540720",
      "new_mode": 33188,
      "new_path": "mypyc/test-data/run-librt-strings.test"
    },
    {
      "type": "modify",
      "old_id": "847fcdae7316d570bed8834963a261c3b1a861e1",
      "old_mode": 33188,
      "old_path": "mypyc/test-data/run-u32.test",
      "new_id": "026d6fee311ca8b89b43e78f774fe6739c214c11",
      "new_mode": 33188,
      "new_path": "mypyc/test-data/run-u32.test"
    },
    {
      "type": "modify",
      "old_id": "abb918a35afd86cb69d10f70ef99c1d6da2595a7",
      "old_mode": 33188,
      "old_path": "mypyc/test-data/run-u64.test",
      "new_id": "d94a95241e24139015535aab52482a1eba744fe1",
      "new_mode": 33188,
      "new_path": "mypyc/test-data/run-u64.test"
    }
  ]
}
