From 9a9a71bb5ad45c54a29a230d4af8834c1ddc8d30 Mon Sep 17 00:00:00 2001 From: dwalter_altair Date: Tue, 14 Oct 2025 20:33:48 -0500 Subject: [PATCH 1/6] Allow SupportsInt and SupportsFloat argument typing to be disabled --- include/pybind11/cast.h | 6 ++++-- include/pybind11/detail/common.h | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index f6e4aed1b9..9ce242b67c 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -348,8 +348,10 @@ struct type_caster::value && !is_std_char_t } PYBIND11_TYPE_CASTER(T, - io_name::value>( - "typing.SupportsInt", "int", "typing.SupportsFloat", "float")); + io_name::value>(PYBIND11_TYPE_ARGUMENT_INT, + "int", + PYBIND11_TYPE_ARGUMENT_FLOAT, + "float")); }; template diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 16952c5829..5df5ac7524 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -298,6 +298,14 @@ # define PYBIND11_TYPE_GUARD_TYPE_HINT "typing_extensions.TypeGuard" #endif +#ifndef PYBIND11_DISABLE_NUMERIC_SUPPORTS_HINT +# define PYBIND11_TYPE_ARGUMENT_FLOAT "typing.SupportsFloat" +# define PYBIND11_TYPE_ARGUMENT_INT "typing.SupportsInt" +#else +# define PYBIND11_TYPE_ARGUMENT_FLOAT "float" +# define PYBIND11_TYPE_ARGUMENT_INT "int" +#endif + // #define PYBIND11_STR_LEGACY_PERMISSIVE // If DEFINED, pybind11::str can hold PyUnicodeObject or PyBytesObject // (probably surprising and never documented, but this was the @@ -1293,7 +1301,8 @@ template #if defined(_MSC_VER) && _MSC_VER < 1920 // MSVC 2017 constexpr #endif - inline void silence_unused_warnings(Args &&...) { + inline void + silence_unused_warnings(Args &&...) { } // MSVC warning C4100: Unreferenced formal parameter From a81ec404f0941b5f9135674dd00bcf6aac64951c Mon Sep 17 00:00:00 2001 From: dwalter_altair Date: Fri, 17 Oct 2025 09:36:57 -0500 Subject: [PATCH 2/6] fix formatting that was accidentally lost --- include/pybind11/detail/common.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 5df5ac7524..b2e6b87031 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -1301,8 +1301,7 @@ template #if defined(_MSC_VER) && _MSC_VER < 1920 // MSVC 2017 constexpr #endif - inline void - silence_unused_warnings(Args &&...) { + inline void silence_unused_warnings(Args &&...) { } // MSVC warning C4100: Unreferenced formal parameter From ccda846c3e9dae145bf06572f3686363aa493ac8 Mon Sep 17 00:00:00 2001 From: dwalter_altair Date: Sat, 18 Oct 2025 17:25:11 -0500 Subject: [PATCH 3/6] rename macros names to include TYPE_HINT --- include/pybind11/cast.h | 4 ++-- include/pybind11/detail/common.h | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index b835367a7d..338542060a 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -348,9 +348,9 @@ struct type_caster::value && !is_std_char_t } PYBIND11_TYPE_CASTER(T, - io_name::value>(PYBIND11_TYPE_ARGUMENT_INT, + io_name::value>(PYBIND11_INT_ARGUMENT_TYPE_HINT, "int", - PYBIND11_TYPE_ARGUMENT_FLOAT, + PYBIND11_FLOAT_ARGUMENT_TYPE_HINT, "float")); }; diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index b2e6b87031..0ab615b372 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -298,12 +298,12 @@ # define PYBIND11_TYPE_GUARD_TYPE_HINT "typing_extensions.TypeGuard" #endif -#ifndef PYBIND11_DISABLE_NUMERIC_SUPPORTS_HINT -# define PYBIND11_TYPE_ARGUMENT_FLOAT "typing.SupportsFloat" -# define PYBIND11_TYPE_ARGUMENT_INT "typing.SupportsInt" +#ifndef PYBIND11_DISABLE_SUPPORTS_TYPE_HINTS +# define PYBIND11_FLOAT_ARGUMENT_TYPE_HINT "typing.SupportsFloat" +# define PYBIND11_INT_ARGUMENT_TYPE_HINT "typing.SupportsInt" #else -# define PYBIND11_TYPE_ARGUMENT_FLOAT "float" -# define PYBIND11_TYPE_ARGUMENT_INT "int" +# define PYBIND11_FLOAT_ARGUMENT_TYPE_HINT "float" +# define PYBIND11_INT_ARGUMENT_TYPE_HINT "int" #endif // #define PYBIND11_STR_LEGACY_PERMISSIVE From aa56278d64d3196d60e5d75a85569db9ec81aeed Mon Sep 17 00:00:00 2001 From: dwalter_altair Date: Sat, 18 Oct 2025 18:10:52 -0500 Subject: [PATCH 4/6] add define to ci.yml file for testing --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15f031ad6c..24f7fbaa9e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -214,6 +214,7 @@ jobs: -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=14 + -DPYBIND11_DISABLE_SUPPORTS_TYPE_HINTS -DPYBIND11_INTERNALS_VERSION=10000000 # Checks to makes sure defining `_` is allowed From a27b95432206bc4a1564b58cf7354190026505a6 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sat, 18 Oct 2025 21:01:04 -0700 Subject: [PATCH 5/6] Add =1 to make cmake happy: -DPYBIND11_DISABLE_SUPPORTS_TYPE_HINTS=1 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24f7fbaa9e..69164b6823 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -214,7 +214,7 @@ jobs: -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=14 - -DPYBIND11_DISABLE_SUPPORTS_TYPE_HINTS + -DPYBIND11_DISABLE_SUPPORTS_TYPE_HINTS=1 -DPYBIND11_INTERNALS_VERSION=10000000 # Checks to makes sure defining `_` is allowed From a7dad4c005a726aca44c53b6b2a5009352fcfcae Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sat, 18 Oct 2025 22:47:31 -0700 Subject: [PATCH 6/6] Pass "-DPYBIND11_DISABLE_SUPPORTS_TYPE_HINTS" via -DCMAKE_CXX_FLAGS --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69164b6823..fc29cfb970 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -214,7 +214,7 @@ jobs: -DDOWNLOAD_CATCH=ON -DDOWNLOAD_EIGEN=ON -DCMAKE_CXX_STANDARD=14 - -DPYBIND11_DISABLE_SUPPORTS_TYPE_HINTS=1 + -DCMAKE_CXX_FLAGS="-DPYBIND11_DISABLE_SUPPORTS_TYPE_HINTS" -DPYBIND11_INTERNALS_VERSION=10000000 # Checks to makes sure defining `_` is allowed