-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Labels
triageNew bug, unverifiedNew bug, unverified
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
3.0.1
Problem description
If a float argument is marked as .noconvert() it will only accept python float arguments and will be type hinted as float.
PEP 484 says that a float type hint can accept float or int which is in conflict with the type caster.
This issue was spawned from #5767
Solutions
- Allow noconvert float to accept int
- I have no idea what breaking side effects this wil have
- Accept that the type hint is broken
- I don't think it is possible to type hint for only a float
Reproducible example code
m.def("test_float", [](float arg) { }, py::arg("arg"));
m.def("test_float_noconvert", [](float arg) { }, py::arg("arg").noconvert());>>> from m import test_float, test_float_noconvert
>>> test_float.__doc__
'test_float(arg: typing.SupportsFloat) -> None\n'
>>> test_float_noconvert.__doc__
'test_float_noconvert(arg: float) -> None\n'
>>> test_int.__doc__
'test_int(arg: typing.SupportsInt) -> None\n'
>>> test_int_noconvert.__doc__
'test_int_noconvert(arg: int) -> None\n'
>>> test_float(5.5)
>>> test_float(5)
>>> test_float_noconvert(5.5)
>>> test_float_noconvert(5)
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: test_float_noconvert(): incompatible function arguments. The following argument types are supported:
1. (arg: float) -> None
Invoked with: 5Is this a regression? Put the last known working version here if it is.
Not a regression
Metadata
Metadata
Assignees
Labels
triageNew bug, unverifiedNew bug, unverified