On this page
typing.SupportsAbs
Prev: typing.Protocol | Up: typing | Next: typing.SupportsBytes
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.SupportsAbs
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import SupportsAbs
Signature & Overview
typing.SupportsAbs(*args, **kwargs)
A protocol with one abstract method abs that is covariant in its return type.
Usage
from typing import SupportsAbs
def magnitude(x: SupportsAbs[float]) -> float:
return abs(x)
assert magnitude(-3.5) == 3.5
Gotchas
- Structural protocol for
__abs__: Matchesint,float,complex,Decimal,Fraction, and custom numeric classes.
REPL Inspect
from typing import SupportsAbs
help(SupportsAbs)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/Protocol Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/SupportsBytes 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