On this page
typing.SupportsComplex
Prev: typing.SupportsBytes | Up: typing | Next: typing.SupportsFloat
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.SupportsComplex
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import SupportsComplex
Signature & Overview
typing.SupportsComplex(*args, **kwargs)
A protocol with one abstract method complex.
Usage
from typing import SupportsComplex
class Impedance:
def __complex__(self) -> complex:
return 1 + 2j
assert isinstance(Impedance(), SupportsComplex)
assert complex(Impedance()) == (1 + 2j)
Gotchas
- Structural protocol for
__complex__(): Matches custom classes defining__complex__()(and built-incomplexin Python 3.11+);intandfloatconvert tocomplexvia__float__/__index__instead.
REPL Inspect
from typing import SupportsComplex
help(SupportsComplex)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/SupportsBytes Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/SupportsFloat Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/typing/AbstractSet Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Annotated Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Any Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_never Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_type shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncContextManager shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncGenerator shared tags: #stdlib, #typing