Builtin Type Conversion
The return type of these special methods is invariant. Python will raise an
error if some other (sub)type is returned.
This is why these optype interfaces don't accept generic type arguments.
| operator | operand | |||
|---|---|---|---|---|
| expression | function | type | method | type |
complex(_) |
do_complex |
DoesComplex |
__complex__ |
CanComplex |
float(_) |
do_float |
DoesFloat |
__float__ |
CanFloat |
int(_) |
do_int |
DoesInt |
__int__ |
CanInt |
bool(_) |
do_bool |
DoesBool |
__bool__ |
CanBool[+R: bool = bool] |
bytes(_) |
do_bytes |
DoesBytes |
__bytes__ |
CanBytes |
str(_) |
do_str |
DoesStr |
__str__ |
CanStr |
repr(_) |
do_repr |
DoesRepr |
__repr__ |
CanRepr |
format(_, x) |
do_format |
DoesFormat |
__format__ |
CanFormat |
hash(_) |
do_hash |
DoesHash |
__hash__ |
CanHash |
_.__index__()
(docs)
|
do_index |
DoesIndex |
__index__ |
CanIndex |