Python 3.5+typingterm
typing.SupportsRound
Supports* protocols
A runtime-checkable protocol for objects supporting round() (has __round__).
Syntax
isinstance(obj, typing.SupportsRound)
This is a generic protocol — SupportsRound[T] is parameterized by the type round() returns. Like the other Supports* protocols, isinstance only checks that __round__ exists, not its signature or ndigits support, so a True result doesn't guarantee round(x, 2) won't fail.
Examples
from typing import SupportsRound
from decimal import Decimal
print(isinstance(5, SupportsRound)) # → True
print(isinstance('3.7', SupportsRound)) # → False
print(isinstance(Decimal('2.5'), SupportsRound)) # → True
print(isinstance(1 + 2j, SupportsRound)) # → False
print(issubclass(int, SupportsRound)) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy