Repository: python-babel/babel
Pull request #925 (2022-11-02 06:32:28)

Remove vestigial Python 2 `long` check

codecov[bot]: # [Codecov](https://codecov.io/gh/python-babel/babel/pull/925?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-babel) Report
> Merging [#925](https://codecov.io/gh/python-babel/babel/pull/925?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-babel) (989305f) into [master](https://codecov.io/gh/python-babel/babel/commit/f7af1b72e765278b3431de3f3b92c6b9a189b18e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-babel) (f7af1b7) will **decrease** coverage by `0.62%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master     #925      +/-   ##
==========================================
- Coverage   91.55%   90.93%   -0.63%     
==========================================
  Files          21       21              
  Lines        4217     4213       -4     
==========================================
- Hits         3861     3831      -30     
- Misses        356      382      +26     
```


| [Impacted Files](https://codecov.io/gh/python-babel/babel/pull/925?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-babel) | Coverage Δ | |
|---|---|---|
| [babel/numbers.py](https://codecov.io/gh/python-babel/babel/pull/925/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-babel#diff-YmFiZWwvbnVtYmVycy5weQ==) | `97.83% <100.00%> (-0.03%)` | :arrow_down: |
| [babel/localtime/\_win32.py](https://codecov.io/gh/python-babel/babel/pull/925/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-babel#diff-YmFiZWwvbG9jYWx0aW1lL193aW4zMi5weQ==) | `21.56% <0.00%> (-39.22%)` | :arrow_down: |
| [babel/localtime/\_\_init\_\_.py](https://codecov.io/gh/python-babel/babel/pull/925/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-babel#diff-YmFiZWwvbG9jYWx0aW1lL19faW5pdF9fLnB5) | `61.53% <0.00%> (-2.57%)` | :arrow_down: |
| [babel/localedata.py](https://codecov.io/gh/python-babel/babel/pull/925/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-babel#diff-YmFiZWwvbG9jYWxlZGF0YS5weQ==) | `95.04% <0.00%> (-0.83%)` | :arrow_down: |
| [babel/messages/frontend.py](https://codecov.io/gh/python-babel/babel/pull/925/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-babel#diff-YmFiZWwvbWVzc2FnZXMvZnJvbnRlbmQucHk=) | `87.17% <0.00%> (-0.75%)` | :arrow_down: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-babel)


Patch:
diff --git a/babel/numbers.py b/babel/numbers.py
index 373a9bd..8a341c4 100644
--- a/babel/numbers.py
+++ b/babel/numbers.py
@@ -24,13 +24,6 @@ import warnings
 
 from babel.core import default_locale, Locale, get_global
 
-try:
-    # Python 2
-    long
-except NameError:
-    # Python 3
-    long = int
-
 
 LC_NUMERIC = default_locale('LC_NUMERIC')
 
@@ -371,7 +364,7 @@ def get_decimal_precision(number):
 
 def get_decimal_quantum(precision):
     """Return minimal quantum of a number, as defined by precision."""
-    assert isinstance(precision, (int, long, decimal.Decimal))
+    assert isinstance(precision, (int, decimal.Decimal))
     return decimal.Decimal(10) ** (-precision)
 
 
diff --git a/babel/support.py b/babel/support.py
index 80e9340..3efc003 100644
--- a/babel/support.py
+++ b/babel/support.py
@@ -18,7 +18,7 @@ from babel.core import Locale
 from babel.dates import format_date, format_datetime, format_time, \
     format_timedelta
 from babel.numbers import format_decimal, format_currency, \
-    format_percent, format_scientific
+    format_percent, format_scientific, format_compact_decimal
 
 
 class Format:
@@ -108,6 +108,17 @@ class Format:
         """
         return format_decimal(number, format, locale=self.locale)
 
+    def compact_decimal(self, number, format_type='short', fraction_digits=0):
+        """Return a number formatted in compact form for the locale.
+
+        >>> fmt = Format('en_US')
+        >>> fmt.compact_decimal(123456789)
+        u'123M'
+        """
+        return format_compact_decimal(number, format_type=format_type,
+                                      fraction_digits=fraction_digits,
+                                      locale=self.locale)
+
     def currency(self, number, currency):
         """Return a number in the given currency formatted for the locale.
         """


Test patch:
diff --git a/tests/test_support.py b/tests/test_support.py
index 2d8e933..93ad37e 100644
--- a/tests/test_support.py
+++ b/tests/test_support.py
@@ -329,6 +329,11 @@ def test_format_decimal():
     assert fmt.decimal(1.2345) == '1.234'
 
 
+def test_format_compact_decimal():
+    fmt = support.Format('en_US')
+    assert fmt.compact_decimal(1234567, format_type='long', fraction_digits=2) == '1.23 million'
+
+
 def test_format_percent():
     fmt = support.Format('en_US')
     assert fmt.percent(0.34) == '34%'