gh-109218: Deprecate weird cases in the complex() constructor by serhiy-storchaka · Pull Request #119620 · python/cpython (original) (raw)
try_complex_special_method is relatively expensive in comparison to PyNumber_Float()
That seems to be an implementation detail. I wonder if we could add nb_complex slot: there is a reserved slot right now anyway.
And complex is looked up even for exact complex, float and int.
The current (i.e. in the main) code - uses here same logic as the float constructor: there is a case for exact complex (as for exact float in PyNumber_Float()).
We can not also completely exclude complex subclasses without complex.
People could break thing in very crazy ways, but should we support such cases? (Looks as a variant of #112636.)