Typing and Generics

typing.SupportsFloat

Runtime-checkable protocol for objects providing __float__(). A static checker checks the method contract; runtime membership checks only inspect the presence of the required member, not its signature or return type.

Formal Syntax & Structure

python syntaxpython
typing.SupportsFloat

Return Value

protocol class

Typing construct or runtime result as described; static typing rules are not runtime validation.

Working Example

Example Snippetpython
from typing import SupportsFloat
class Value:    def __float__(self): return 2.5item=Value()print((isinstance(item,SupportsFloat), float(item)))
Python Reference