Skip to content

Conversation

daltairwalter
Copy link
Contributor

Description

Allow suppression of the SupportsInt and SupportsFloat type hints:

See #5767

Suggested changelog entry:

Allow suppression of the SupportsInt and SupportsFloat type hints by defining PYBIND11_DISABLE_NUMERIC_SUPPORTS_HINT

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

We should exercise this, e.g. by adding the new define here:

-DPYBIND11_INTERNALS_VERSION=10000000

(please add before DPYBIND11_INTERNALS_VERSION; I think it's best to keep that last, for max visibility)

# 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.

@rwgk
Copy link
Collaborator

rwgk commented Oct 17, 2025

@gentlegiantJGC @timohl @InvincibleRMC for visibility

@rwgk
Copy link
Collaborator

rwgk commented Oct 19, 2025

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 ===============================================================

@gentlegiantJGC
Copy link
Contributor

Could you create a new test case file for this and only define the macro in that file?

@daltairwalter
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants