Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for formatting NaN, Infinity #955

Merged
merged 2 commits into from
Jan 25, 2023

Conversation

DenverCoder1
Copy link
Contributor

@DenverCoder1 DenverCoder1 commented Jan 20, 2023

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'

@codecov
Copy link

codecov bot commented Jan 20, 2023

Codecov Report

Merging #955 (e87cc84) into master (2a4b784) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #955      +/-   ##
==========================================
+ Coverage   90.48%   90.50%   +0.01%     
==========================================
  Files          24       24              
  Lines        4393     4402       +9     
==========================================
+ Hits         3975     3984       +9     
  Misses        418      418              
Impacted Files Coverage Δ
babel/numbers.py 98.04% <100.00%> (+0.04%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@akx akx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I wonder if there are some parameter combinations that might not handle infinities or NaNs, but this is way better than doing nothing with them 😄

@akx akx merged commit 79bcdf2 into python-babel:master Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

format functions fail on infinity
2 participants