@@ -318,6 +318,11 @@ are always available. They are listed here in alphabetical order.
318318 :class: `int ` and :class: `float `. If both arguments are omitted, returns
319319 ``0j ``.
320320
321+ For a general Python object ``x ``, ``complex(x) `` delegates to
322+ ``x.__complex__() ``. If ``__complex__() `` is not defined then it falls back
323+ to :meth: `__float__ `. If ``__float__() `` is not defined then it falls back
324+ to :meth: `__index__ `.
325+
321326 .. note ::
322327
323328 When converting from a string, the string must not contain whitespace
@@ -330,6 +335,10 @@ are always available. They are listed here in alphabetical order.
330335 .. versionchanged :: 3.6
331336 Grouping digits with underscores as in code literals is allowed.
332337
338+ .. versionchanged :: 3.8
339+ Falls back to :meth: `__index__ ` if :meth: `__complex__ ` and
340+ :meth: `__float__ ` are not defined.
341+
333342
334343.. function :: delattr(object, name)
335344
@@ -584,7 +593,8 @@ are always available. They are listed here in alphabetical order.
584593 float, an :exc: `OverflowError ` will be raised.
585594
586595 For a general Python object ``x ``, ``float(x) `` delegates to
587- ``x.__float__() ``.
596+ ``x.__float__() ``. If ``__float__() `` is not defined then it falls back
597+ to :meth: `__index__ `.
588598
589599 If no argument is given, ``0.0 `` is returned.
590600
@@ -609,6 +619,9 @@ are always available. They are listed here in alphabetical order.
609619 .. versionchanged :: 3.7
610620 *x * is now a positional-only parameter.
611621
622+ .. versionchanged :: 3.8
623+ Falls back to :meth: `__index__ ` if :meth: `__float__ ` is not defined.
624+
612625
613626.. index ::
614627 single: __format__
@@ -780,7 +793,8 @@ are always available. They are listed here in alphabetical order.
780793
781794 Return an integer object constructed from a number or string *x *, or return
782795 ``0 `` if no arguments are given. If *x * defines :meth: `__int__ `,
783- ``int(x) `` returns ``x.__int__() ``. If *x * defines :meth: `__trunc__ `,
796+ ``int(x) `` returns ``x.__int__() ``. If *x * defines :meth: `__index__ `,
797+ it returns ``x.__index__() ``. If *x * defines :meth: `__trunc__ `,
784798 it returns ``x.__trunc__() ``.
785799 For floating point numbers, this truncates towards zero.
786800
@@ -812,6 +826,9 @@ are always available. They are listed here in alphabetical order.
812826 .. versionchanged :: 3.7
813827 *x * is now a positional-only parameter.
814828
829+ .. versionchanged :: 3.8
830+ Falls back to :meth: `__index__ ` if :meth: `__int__ ` is not defined.
831+
815832
816833.. function :: isinstance(object, classinfo)
817834
0 commit comments