diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15f031ad6c..fc29cfb970 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 + -DCMAKE_CXX_FLAGS="-DPYBIND11_DISABLE_SUPPORTS_TYPE_HINTS" -DPYBIND11_INTERNALS_VERSION=10000000 # Checks to makes sure defining `_` is allowed diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 4708101d80..338542060a 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_INT_ARGUMENT_TYPE_HINT, + "int", + PYBIND11_FLOAT_ARGUMENT_TYPE_HINT, + "float")); }; template diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 16952c5829..0ab615b372 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_SUPPORTS_TYPE_HINTS +# define PYBIND11_FLOAT_ARGUMENT_TYPE_HINT "typing.SupportsFloat" +# define PYBIND11_INT_ARGUMENT_TYPE_HINT "typing.SupportsInt" +#else +# define PYBIND11_FLOAT_ARGUMENT_TYPE_HINT "float" +# define PYBIND11_INT_ARGUMENT_TYPE_HINT "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