Disable numeric supports type hinting - fixes issue #5767
Description
Allow suppression of the SupportsInt and SupportsFloat type hints:
See https://github.com/pybind/pybind11/issues/5767
Suggested changelog entry:
Allow suppression of the SupportsInt and SupportsFloat type hints by defining PYBIND11_DISABLE_NUMERIC_SUPPORTS_HINT
@gentlegiantJGC @timohl @InvincibleRMC for visibility
I don't think the testing in the CI works as expected.
I tested locally with this diff:
diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h
index 0ab615b3..3275693e 100644
--- a/include/pybind11/detail/common.h
+++ b/include/pybind11/detail/common.h
@@ -298,6 +298,7 @@
# define PYBIND11_TYPE_GUARD_TYPE_HINT "typing_extensions.TypeGuard"
#endif
+#define PYBIND11_DISABLE_SUPPORTS_TYPE_HINTS
#ifndef PYBIND11_DISABLE_SUPPORTS_TYPE_HINTS
# define PYBIND11_FLOAT_ARGUMENT_TYPE_HINT "typing.SupportsFloat"
# define PYBIND11_INT_ARGUMENT_TYPE_HINT "typing.SupportsInt"
We need to adjust a bunch of tests:
======================================================================== short test summary info =========================================================================
SKIPPED [1] test_multiple_interpreters.py:127: Requires 3.14.0b3+
SKIPPED [1] test_multiple_interpreters.py:61: interpreters module needs to support legacy config
SKIPPED [1] test_stl.py:168: no <experimental/optional>
FAILED test_builtin_casters.py::test_int_convert - assert --- actual / +++ expected
FAILED test_builtin_casters.py::test_float_convert - assert --- actual / +++ expected
FAILED test_class.py::test_qualname - assert --- actual / +++ expected
FAILED test_builtin_casters.py::test_tuple - assert --- actual / +++ expected
FAILED test_custom_type_casters.py::test_noconvert_args - assert --- actual / +++ expected
FAILED test_callbacks.py::test_function_signatures - assert --- actual / +++ expected
FAILED test_docstring_options.py::test_docstring_options - AssertionError: assert False
FAILED test_kwargs_and_defaults.py::test_function_signatures - assert --- actual / +++ expected
FAILED test_methods_and_attributes.py::test_no_mixed_overloads - AssertionError: assert 'overloading ...float) -> str' == 'overloading ...Float) -> str'
FAILED test_numpy_dtypes.py::test_signature - assert --- actual / +++ expected
FAILED test_factory_constructors.py::test_init_factory_signature - AssertionError: assert --- actual / +++ expected
FAILED test_numpy_vectorize.py::test_passthrough_arguments - AssertionError: assert --- actual / +++ expected
FAILED test_kwargs_and_defaults.py::test_mixed_args_and_kwargs - assert --- actual / +++ expected
FAILED test_kwargs_and_defaults.py::test_keyword_only_args - AssertionError: assert '__init__(sel... 0) -> None\n' == '__init__(sel... 0) -> None\n'
FAILED test_kwargs_and_defaults.py::test_positional_only_args - AssertionError: assert 'args_kwonly_...s) -> tuple\n' == 'args_kwonly_...s) -> tuple\n'
FAILED test_kwargs_and_defaults.py::test_signatures - AssertionError: assert 'kw_only_all(...t) -> tuple\n' == 'kw_only_all(...t) -> tuple\n'
FAILED test_pytypes.py::test_dict_annotations - assert --- actual / +++ expected
FAILED test_pytypes.py::test_union_object_annotations - assert --- actual / +++ expected
FAILED test_pytypes.py::test_iterator_annotations - assert --- actual / +++ expected
FAILED test_pytypes.py::test_list_annotations - assert --- actual / +++ expected
FAILED test_pytypes.py::test_optional_object_annotations - assert --- actual / +++ expected
FAILED test_pytypes.py::test_class_attribute_types - AssertionError: assert 'typing.ClassVar[float]' == 'typing.Class...upportsFloat]'
FAILED test_pytypes.py::test_module_attribute_types - AssertionError: assert 'list[int]' == 'list[typing.SupportsInt]'
FAILED test_pytypes.py::test_type_annotation - assert --- actual / +++ expected
FAILED test_pytypes.py::test_redeclaration_attr_with_type_hint - AssertionError: assert 'float' == 'typing.SupportsFloat'
FAILED test_pytypes.py::test_get_annotations_compliance - AssertionError: assert 'list[int]' == 'list[typing.SupportsInt]'
FAILED test_methods_and_attributes.py::test_str_issue - AssertionError: assert --- actual / +++ expected
FAILED test_methods_and_attributes.py::test_overload_ordering - AssertionError: assert '1. overload_order(arg0: typing.SupportsInt) -> int' in 'overload_order(*args, **kwargs)\nOverloaded function.\n\n1. overload_order(arg0: int)...
FAILED test_stl.py::test_vector - assert --- actual / +++ expected
FAILED test_stl.py::test_array - assert --- actual / +++ expected
FAILED test_stl.py::test_reference_sensitive_optional - assert --- actual / +++ expected
FAILED test_stl.py::test_variant - assert --- actual / +++ expected
FAILED test_stl.py::test_stl_pass_by_pointer - assert --- actual / +++ expected
FAILED test_stl.py::test_variant_monostate - assert --- actual / +++ expected
FAILED test_stl.py::test_sequence_caster_protocol - assert --- actual / +++ expected
FAILED test_stl.py::test_mapping_caster_protocol - assert --- actual / +++ expected
FAILED test_stl.py::test_set_caster_protocol - assert --- actual / +++ expected
FAILED test_stl.py::test_valarray - assert --- actual / +++ expected
FAILED test_type_caster_pyobject_ptr.py::test_type_caster_name_via_incompatible_function_arguments_type_error - AssertionError: Regex pattern did not match.
=============================================================== 39 failed, 1247 passed, 3 skipped in 5.19s ===============================================================
Could you create a new test case file for this and only define the macro in that file?
I will try to make a single test that uses this macro instead of the other change - this looks straightforward, but I have never used the pybind11 testing system so we will see.