Python 3.5+typingterm
typing.SupportsAbs
Supports* protocols
A runtime-checkable protocol for objects supporting abs() (has __abs__).
Syntax
isinstance(obj, typing.SupportsAbs)
Its main use is as a parameter annotation — mark that a function accepts any object with abs(), without tying it to a concrete class. It is generic in the return type: SupportsAbs[float] states that abs() yields a float. The isinstance check only confirms __abs__ exists, not its signature or return type.
Examples
from typing import SupportsAbs
print(isinstance(5, SupportsAbs)) # → True
print(isinstance('abc', SupportsAbs)) # → False
from typing import SupportsAbs
class Money: __abs__ = lambda self: 42
print(isinstance(Money(), SupportsAbs)) # → True
print(abs(Money())) # → 42
print(issubclass(complex, SupportsAbs)) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy