1515
1616TYPE_CHECKING = False
1717if TYPE_CHECKING :
18+ from collections .abc import Callable
1819 from typing import TypeAlias
1920
2021 # This type can be better defined by typing.SupportsFloat
@@ -458,13 +459,13 @@ def scientific(value: NumberOrString, precision: int = 2) -> str:
458459
459460
460461def clamp (
461- value : float ,
462- format : str = "{:}" ,
462+ value : float | None ,
463+ format : str | Callable [[ float ], str ] = "{:}" ,
463464 floor : float | None = None ,
464465 ceil : float | None = None ,
465466 floor_token : str = "<" ,
466467 ceil_token : str = ">" ,
467- ) -> str :
468+ ) -> str | None :
468469 """Returns number with the specified format, clamped between floor and ceil.
469470
470471 If the number is larger than ceil or smaller than floor, then the respective limit
@@ -488,7 +489,7 @@ def clamp(
488489 ```
489490
490491 Args:
491- value (int, float): Input number.
492+ value (int, float, None ): Input number, or `None` to return `None` .
492493 format (str OR callable): Can either be a formatting string, or a callable
493494 function that receives value and returns a string.
494495 floor (int, float): Smallest value before clamping.
@@ -499,7 +500,8 @@ def clamp(
499500 to output.
500501
501502 Returns:
502- str: Formatted number. The output is clamped between the indicated floor and
503+ str | None: Formatted number, or `None` when `value` is `None`.
504+ The output is clamped between the indicated floor and
503505 ceil. If the number is larger than ceil or smaller than floor, the output
504506 will be prepended with a token indicating as such.
505507
0 commit comments