Skip to content
Open
6 changes: 4 additions & 2 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,10 @@ struct type_caster<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_t
}

PYBIND11_TYPE_CASTER(T,
io_name<std::is_integral<T>::value>(
"typing.SupportsInt", "int", "typing.SupportsFloat", "float"));
io_name<std::is_integral<T>::value>(PYBIND11_TYPE_ARGUMENT_INT,
"int",
PYBIND11_TYPE_ARGUMENT_FLOAT,
"float"));
};

template <typename T>
Expand Down
8 changes: 8 additions & 0 deletions include/pybind11/detail/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@
# define PYBIND11_TYPE_GUARD_TYPE_HINT "typing_extensions.TypeGuard"
#endif

#ifndef PYBIND11_DISABLE_NUMERIC_SUPPORTS_HINT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming suggestions:

PYBIND11_DISABLE_SUPPORTS_TYPE_HINTS
PYBIND11_ARG_TYPE_HINT_FLOAT
PYBIND11_ARG_TYPE_HINT_INT

(the main idea is to consistently have "type hint" in all macros)

Note sure about PYBIND11_DISABLE_NUMERIC_SUPPORTS_TYPE_HINTS, or PYBIND11_DISABLE_ARITHMETIC_SUPPORTS_TYPE_HINTS, or similar. Do we want "numeric" or "arithmetic" in name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I looked at the other type hint macros and they all end in TYPE_HINT, and this seemed like a nice pattern.

PYBIND11_DISABLE_SUPPORTS_TYPE_HINTS
PYBIND11_FLOAT_ARGUMENT_TYPE_HINT
PYBIND11_INT_ARGUMENT_TYPE_HINT

I will test my changes, make the ci.yml change and submit again.

# 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
Expand Down
Loading