def convert_int_from_base_unit(base_value: int, base_unit: Optional[str]) -> Optional[str]:
    """Convert an integer value in some base unit to a human-friendly unit.

    The output unit is chosen so that it's the greatest unit that can represent
    the value without loss.

    :param base_value: value to be converted from a base unit
    :param base_unit: unit of *value*. Should be one of the base units (case sensitive):

            * For space: ``B``, ``kB``, ``MB``;
            * For time: ``ms``, ``s``, ``min``.

    :returns: :class:`str` value representing *base_value* converted from *base_unit* to the greatest
        possible human-friendly unit, or ``None`` if conversion failed.

    :Example:

        >>> convert_int_from_base_unit(1024, 'kB')
        '1MB'

        >>> convert_int_from_base_unit(1025, 'kB')
        '1025kB'

        >>> convert_int_from_base_unit(4, '256MB')
        '1GB'

        >>> convert_int_from_base_unit(4, '256 MB') is None
        True

        >>> convert_int_from_base_unit(1024, 'KB') is None
        True
    """
    base_value_mult, base_unit = strtol(base_unit, False)
    if TYPE_CHECKING:  # pragma: no cover
        assert isinstance(base_value_mult, int)
    base_value *= base_value_mult

    convert_tbl = get_conversion_table(base_unit)
    for unit in convert_tbl:
        multiplier = convert_tbl[unit][base_unit]
        if multiplier <= 1.0 or base_value % multiplier == 0:
            return str(round(base_value / multiplier)) + unit
Convert an integer value in some base unit to a human-friendly unit.

    The output unit is chosen so that it's the greatest unit that can represent
    the value without loss.

    :param base_value: value to be converted from a base unit
    :param base_unit: unit of *value*. Should be one of the base units (case sensitive):

            * For space: ``B``, ``kB``, ``MB``;
            * For time: ``ms``, ``s``, ``min``.

    :returns: :class:`str` value representing *base_value* converted from *base_unit* to the greatest
        possible human-friendly unit, or ``None`` if conversion failed.

    :Example:

        >>> convert_int_from_base_unit(1024, 'kB')
        '1MB'

        >>> convert_int_from_base_unit(1025, 'kB')
        '1025kB'

        >>> convert_int_from_base_unit(4, '256MB')
        '1GB'

        >>> convert_int_from_base_unit(4, '256 MB') is None
        True

        >>> convert_int_from_base_unit(1024, 'KB') is None
        True
    
patroni/utils.py