Support for formatting NaN, Infinity by DenverCoder1 · Pull Request #955 · python-babel/babel

This came up while I was looking for ways to improve type-safety - specifically that the type of decimal_tuple.exponent in get_decimal_precision() is int | Literal['n', 'N', 'F'] and can't be compared with 0 or taken the absolute value of if it is not an int.

This fixes that type issue but I'm making this a separate PR since it also fixes NaN and Infinity cases in other areas, so it won't raise exceptions when formatting.

Fixes #132

>>> format_decimal(decimal.Decimal('Infinity'))
'∞'
>>> format_decimal(decimal.Decimal('-Infinity'))
'-∞'
>>> format_decimal(decimal.Decimal('NaN'))
'NaN'