diff --git a/prefixed/__init__.py b/prefixed/__init__.py index d189171..3dee5ba 100644 --- a/prefixed/__init__.py +++ b/prefixed/__init__.py @@ -15,7 +15,7 @@ import re import sys -__version__ = '0.4.0' +__version__ = '0.4.1' try: BASESTRING = basestring @@ -104,6 +104,7 @@ def raise_from_none(exc): # pragma: no cover else: from string import maketrans # pragma: no cover +DEPRECATED = {'j', 'J'} TRANS_DEPRECATED = maketrans('jJ', 'km') @@ -299,13 +300,14 @@ def __format__(self, format_spec): spec = match.groupdict() + # Handle deprecated spec types + if spec['type'] in DEPRECATED: + spec['type'] = spec['type'].translate(TRANS_DEPRECATED) + # If not a spec we handle, use float.__format__(() if spec['type'] not in {'h', 'H', 'k', 'K', 'm', 'M'}: return super(Float, self).__format__(format_spec) - # Handle deprecated spec types - spec['type'] = spec['type'].translate(TRANS_DEPRECATED) - # Determine value and prefix value, prefix, spec = _convert(float(self), spec) diff --git a/tests/test_float.py b/tests/test_float.py index c7552c7..915505f 100644 --- a/tests/test_float.py +++ b/tests/test_float.py @@ -418,6 +418,14 @@ def test_margin(self): self.assertEqual(format(Float(1049), '%5.2h'), '1049.00') self.assertEqual(format(Float(1050), '%5.2h'), '1.05k') + def test_deprecated(self): + """ + Confirm deprecated format specifiers function + """ + + self.assertEqual(format(Float(2048), '.2j'), '2.00Ki') + self.assertEqual(format(Float(2048), '.2J'), '2.00K') + class TestFloatMath(unittest.TestCase): """