)]}'
{
  "commit": "e8e8d6ab22f39938607f31d457d4d359c130f078",
  "tree": "1f2a877780cd4f8ee799f9ab8e33634af33d8753",
  "parents": [
    "2448bc5853c8191d8b50250433084683887d0067"
  ],
  "author": {
    "name": "Michael Carlstrom",
    "email": "rmc@carlstrom.com",
    "time": "Mon Feb 16 23:00:01 2026 -0800"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Mon Feb 16 23:00:01 2026 -0800"
  },
  "message": "Expand float and complex strict mode to allow ints and ints/float (for PEP 484 compatibility). (#5879)\n\n* init\n\nSigned-off-by: Michael Carlstrom \u003crmc@carlstrom.com\u003e\n\n* Add constexpr to is_floating_point check\n\nThis is known at compile time so it can be constexpr\n\n* Allow noconvert float to accept int\n\n* Update noconvert documentation\n\n* Allow noconvert complex to accept int and float\n\n* Add complex strict test\n\n* style: pre-commit fixes\n\n* Update unit tests so int, becomes double.\n\n* style: pre-commit fixes\n\n* remove if (constexpr)\n\nSigned-off-by: Michael Carlstrom \u003crmc@carlstrom.com\u003e\n\n* fix spelling error\n\n* bump order in #else\n\n* Switch order in c++11 only section\n\nSigned-off-by: Michael Carlstrom \u003crmc@carlstrom.com\u003e\n\n* ci: trigger build\n\n* ci: trigger build\n\n* Allow casting from float to int\n\nThe int type caster allows anything that implements __int__ with explicit exception of the python float. I can\u0027t see any reason for this.\nThis modifies the int casting behaviour to accept a float.\nIf the argument is marked as noconvert() it will only accept int.\n\n* tests for py::float into int\n\n* Update complex_cast tests\n\n* Add SupportsIndex to int and float\n\n* style: pre-commit fixes\n\n* fix assert\n\n* Update docs to mention other conversions\n\n* fix pypy __index__ problems\n\n* style: pre-commit fixes\n\n* extract out PyLong_AsLong __index__ deprecation\n\nSigned-off-by: Michael Carlstrom \u003crmc@carlstrom.com\u003e\n\n* style: pre-commit fixes\n\n* Add back env.deprecated_call\n\nSigned-off-by: Michael Carlstrom \u003crmc@carlstrom.com\u003e\n\n* remove note\n\nSigned-off-by: Michael Carlstrom \u003crmc@carlstrom.com\u003e\n\n* remove untrue comment\n\nSigned-off-by: Michael Carlstrom \u003crmc@carlstrom.com\u003e\n\n* fix noconvert_args\n\nSigned-off-by: Michael Carlstrom \u003crmc@carlstrom.com\u003e\n\n* resolve error\n\nSigned-off-by: Michael Carlstrom \u003crmc@carlstrom.com\u003e\n\n* Add comment\n\nSigned-off-by: Michael Carlstrom \u003crmc@carlstrom.com\u003e\n\n* [skip ci]\n\ntests: Add overload resolution test for float/int breaking change\n\nAdd test_overload_resolution_float_int() to explicitly test the breaking\nchange where int arguments now match float overloads when registered first.\n\nThe existing tests verify conversion behavior (int -\u003e float, int/float -\u003e complex)\nbut do not test overload resolution when both float and int overloads exist.\nThis test fills that gap by:\n\n- Testing that float overload registered before int overload matches int(42)\n- Testing strict mode (noconvert) overload resolution breaking change\n- Testing complex overload resolution with int/float/complex overloads\n- Documenting the breaking change explicitly\n\nThis complements existing tests which verify \u0027can it convert?\u0027 by testing\n\u0027which overload wins when multiple can convert?\u0027\n\n* Add test to verify that custom __index__ objects (not PyLong) work correctly with complex conversion. These should be consistent across CPython, PyPy, and GraalPy.\n\n* Improve comment clarity for PyPy __index__ handling\n\nReplace cryptic \u0027So: PYBIND11_INDEX_CHECK(src.ptr())\u0027 comment with\nclearer explanation of the logic:\n\n- Explains that we need to call PyNumber_Index explicitly on PyPy\n  for non-PyLong objects\n- Clarifies the relationship to the outer condition: when convert\n  is false, we only reach this point if PYBIND11_INDEX_CHECK passed\n  above\n\nThis makes the code more maintainable and easier to understand\nduring review.\n\n* Undo inconsequential change to regex in test_enum.py\n\nDuring merge, HEAD\u0027s regex pattern was kept, but master\u0027s version is preferred.\nThe order of ` ` and `\\|` in the character class is arbitrary. Keep master\u0027s order\n(already fixed in PR #5891; sorry I missed looking back here when working on 5891).\n\n* test_methods_and_attributes.py: Restore existing `m.overload_order(1.1)` call and clearly explain the behavior change.\n\n* Reject float → int conversion even in convert mode\n\nEnabling implicit float → int conversion in convert mode causes\nsilent truncation (e.g., 1.9 → 1). This is dangerous because:\n\n1. It\u0027s implicit - users don\u0027t expect truncation when calling functions\n2. It\u0027s silent - no warning or error\n3. It can hide bugs - precision loss is hard to detect\n\nThis change restores the explicit rejection of PyFloat_Check for integer\ncasters, even in convert mode. This is more in line with Python\u0027s behavior\nwhere int(1.9) must be explicit.\n\nNote that the int → float conversion in noconvert mode is preserved,\nas that\u0027s a safe widening conversion.\n\n* Revert test changes that sidestepped implicit float→int conversion\n\nThis reverts all test modifications that were made to accommodate\nimplicit float→int conversion in convert mode. With the production\ncode change that explicitly rejects float→int conversion even in\nconvert mode, these test workarounds are no longer needed.\n\nChanges reverted:\n- test_builtin_casters.py: Restored cant_convert(3.14159) and\n  np.float32 conversion with deprecated_call wrapper\n- test_custom_type_casters.py: Restored TypeError expectation for\n  m.ints_preferred(4.0)\n- test_methods_and_attributes.py: Restored TypeError expectation\n  for m.overload_order(1.1)\n- test_stl.py: Restored float literals (2.0) that were replaced with\n  strings to avoid conversion\n- test_factory_constructors.py: Restored original constructor calls\n  that were modified to avoid float→int conversion\n\nAlso removes the unused avoid_PyLong_AsLong_deprecation fixture\nand related TypeVar imports, as all uses were removed.\n\n* Replace env.deprecated_call() with pytest.deprecated_call()\n\nThe env.deprecated_call() function was removed, but two test cases\nstill reference it. Replace with pytest.deprecated_call(), which is\nthe standard pytest context manager for handling deprecation warnings.\n\nSince we already require pytest\u003e\u003d6 (see tests/requirements.txt), the\ncompatibility function is obsolete and pytest.deprecated_call() is\navailable.\n\n* Update test expectations for swapped NoisyAlloc overloads\n\nPR 5879 swapped the order of NoisyAlloc constructor overloads:\n- (int i, double) is now placement new (comes first)\n- (double d, double) is now factory pointer (comes second)\n\nThis swap is necessary because pybind11 tries overloads in order\nuntil one matches. With int → float conversion now allowed:\n\n- create_and_destroy(4, 0.5): Without the swap, (double d, double)\n  would match first (since int → double conversion is allowed),\n  bypassing the more specific (int i, double) overload. With the\n  swap, (int i, double) matches first (exact match), which is\n  correct.\n\n- create_and_destroy(3.5, 4.5): (int i, double) fails (float → int\n  is rejected), then (double d, double) matches, which is correct.\n\nThe swap ensures exact int matches are preferred over double matches\nwhen an int is provided, which is the expected overload resolution\nbehavior.\n\nUpdate the test expectations to match the new overload resolution\norder.\n\n* Resolve clang-tidy error:\n\n/__w/pybind11/pybind11/include/pybind11/cast.h:253:46: error: repeated branch body in conditional chain [bugprone-branch-clone,-warnings-as-errors]\n  253 |         } else if (PyFloat_Check(src.ptr())) {\n      |                                              ^\n/__w/pybind11/pybind11/include/pybind11/cast.h:258:10: note: end of the original\n  258 |         } else if (convert || PYBIND11_LONG_CHECK(src.ptr()) || PYBIND11_INDEX_CHECK(src.ptr())) {\n      |          ^\n/__w/pybind11/pybind11/include/pybind11/cast.h:283:16: note: clone 1 starts here\n  283 |         } else {\n      |                ^\n\n* Add test coverage for __index__ and __int__ edge cases: incorrectly returning float\n\nThese tests ensure that:\n- Invalid return types (floats) are properly rejected\n- The fallback from __index__ to __int__ works correctly in convert mode\n- noconvert mode correctly prevents fallback when __index__ fails\n\n* Minor comment-only changes: add PR number, for easy future reference\n\n* Ensure we are not leaking a Python error is something is wrong elsewhere (e.g. UB, or bug in Python beta testing).\n\nSee also: https://github.com/pybind/pybind11/pull/5879#issuecomment-3521099331\n\n* [skip ci] Bump PYBIND11_INTERNALS_VERSION to 12 (for PRs 5879, 5887, 5960)\n\n---------\n\nSigned-off-by: Michael Carlstrom \u003crmc@carlstrom.com\u003e\nCo-authored-by: gentlegiantJGC \u003cgentlegiantJGC@users.noreply.github.com\u003e\nCo-authored-by: pre-commit-ci[bot] \u003c66853113+pre-commit-ci[bot]@users.noreply.github.com\u003e\nCo-authored-by: Ralf W. Grosse-Kunstleve \u003crgrossekunst@nvidia.com\u003e",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "c647ae0f0af269f2708b431c3c4abbd581f1a0f5",
      "old_mode": 33188,
      "old_path": "docs/advanced/functions.rst",
      "new_id": "76602709bf08e3ce87b36c9fe668b2cd602aab17",
      "new_mode": 33188,
      "new_path": "docs/advanced/functions.rst"
    },
    {
      "type": "modify",
      "old_id": "f5a94da2063fdd4e77532a6a111abd91b8bfe3ca",
      "old_mode": 33188,
      "old_path": "include/pybind11/cast.h",
      "new_id": "1c4973b7488ae6d66d31d69d0a42eeddb9e7dbec",
      "new_mode": 33188,
      "new_path": "include/pybind11/cast.h"
    },
    {
      "type": "modify",
      "old_id": "0b6f49365d888adb956c007a2807d43b76ec7a94",
      "old_mode": 33188,
      "old_path": "include/pybind11/complex.h",
      "new_id": "8f285d778fc61342780701f2e5fac2c6ed8000c8",
      "new_mode": 33188,
      "new_path": "include/pybind11/complex.h"
    },
    {
      "type": "modify",
      "old_id": "b681529325f82c1ac61d6d2bd0187248c6f639e2",
      "old_mode": 33188,
      "old_path": "include/pybind11/detail/internals.h",
      "new_id": "41585cffbab7d80017257e3e24f176cce00ed35c",
      "new_mode": 33188,
      "new_path": "include/pybind11/detail/internals.h"
    },
    {
      "type": "modify",
      "old_id": "6cde727ad8988f4500011c2ddb201d5572cf9c1f",
      "old_mode": 33188,
      "old_path": "tests/test_builtin_casters.cpp",
      "new_id": "40803fbf8ae4328577e08a842a0800578148f7f7",
      "new_mode": 33188,
      "new_path": "tests/test_builtin_casters.cpp"
    },
    {
      "type": "modify",
      "old_id": "23c191cec2d6b2f6cc9a763a291f5ff8dcf4894f",
      "old_mode": 33188,
      "old_path": "tests/test_builtin_casters.py",
      "new_id": "b232c087e00b28db43db44edbeb5010d0d2f7d11",
      "new_mode": 33188,
      "new_path": "tests/test_builtin_casters.py"
    },
    {
      "type": "modify",
      "old_id": "6ed1c564f065bff82654775a59156d83b138e61a",
      "old_mode": 33188,
      "old_path": "tests/test_custom_type_casters.py",
      "new_id": "0680e50504665aebbae440c3e594f5746375af3e",
      "new_mode": 33188,
      "new_path": "tests/test_custom_type_casters.py"
    },
    {
      "type": "modify",
      "old_id": "c96a3a31fbe7190e82800f10745bb3afcc761cbb",
      "old_mode": 33188,
      "old_path": "tests/test_factory_constructors.cpp",
      "new_id": "33a484945a4377d4552056cc80d91f26a2b9869f",
      "new_mode": 33188,
      "new_path": "tests/test_factory_constructors.cpp"
    },
    {
      "type": "modify",
      "old_id": "c6ae98c7fb3815a3ccbafdf1b95b2d5e75f733b3",
      "old_mode": 33188,
      "old_path": "tests/test_factory_constructors.py",
      "new_id": "cdf16ec85872e1e28d05ebfc2f2c21b8b3ae8f7c",
      "new_mode": 33188,
      "new_path": "tests/test_factory_constructors.py"
    },
    {
      "type": "modify",
      "old_id": "e324c8bdd45b1a2cd5240dbfc4b7bda37610bb7c",
      "old_mode": 33188,
      "old_path": "tests/test_methods_and_attributes.cpp",
      "new_id": "f5fb02d121dbb2576b1ae16dd45bfe6ec97ae440",
      "new_mode": 33188,
      "new_path": "tests/test_methods_and_attributes.cpp"
    },
    {
      "type": "modify",
      "old_id": "6084d517df066c38c771ab34879caf19866d6eab",
      "old_mode": 33188,
      "old_path": "tests/test_stl.cpp",
      "new_id": "8bddbb1f38d9be5677138a21c8dd8aca695360ae",
      "new_mode": 33188,
      "new_path": "tests/test_stl.cpp"
    }
  ]
}
