Details
-
Bug
-
Resolution: Fixed
-
P4: Low
-
6.5.1
-
None
-
ubuntu 23.04 x86-64, python 3.11.4, qt 6.5.1, pyside also 6.5.1 (self compiled)
-
-
5f7ea698a (dev), 890db123f (dev), 7c1ac18f4 (dev), 12c47988d (6.5), c128e952c (6.5), 1a19663aa (dev), a807b0f67 (6.5), 45e39b3e6 (dev), 3dc05f2d7 (dev), eceacdd60 (dev), 51f20b59e (6.5), 919c05013 (6.5)
Description
Exposing some special functions seems to be not working correctly.
The ones that doesnt work:
_floor, __pow, __rpow, __abs_
the ones that work:
_str, __repr, __format_
The type is exposed in xml as follows:
<value-type name="TestNumType"> <add-function signature="__float__()" return-type="double"> <inject-code class="target" position="end"> double cppResult = const_cast<const ::TestNumType *>(cppSelf)->to_double_shiboken(); pyResult = Shiboken::Conversions::copyToPython(Shiboken::Conversions::PrimitiveTypeConverter<double>(), &cppResult); if (PyErr_Occurred() || !pyResult) { Py_XDECREF(pyResult); return {}; } return pyResult; </inject-code> </add-function> </value-type>
this prints following error (runtime)
Traceback (most recent call last):
File "/media/data/devel/shiboken-test/bin/python/plugins/test_plugin/_init_.py", line 148, in onGenerateUi
print(f"as float: {float(TestNumType('1.16'))}")
^^^^^^^^^^^^^^^^^^^^^^
TypeError: float() argument must be a string or a real number, not 'TestApi.TestNumType'
it should be sufficient for the float() to work - following python class works correctly:
class TestPythonClass: def __float__(self): return 42.42 print(f"python class as float: {float(TestPythonClass())}")
str(), repr(), '{0:f}'.format(TestApi.TestNumType()) works correctly
where:
import math
float(), abs(), pow operator( a ** b) doesnt work - i am getting same error as in the _float_ function above.
is there something more that should be done? or is it simply bug?
i would also like to note that (str / repr / format) works even that i do expose them using modify function tag - for example:
<modify-function signature="repr_shiboken()const" rename="_repr_"/>