On this page
  1. typing.SupportsAbs
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from typing import SupportsAbs
help(SupportsAbs)

Linked from

Related notes