Skip to content

Commit

Permalink
Fix handling of Unicode for deprecated specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
avylove committed Nov 3, 2022
1 parent 079a268 commit a476a30
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 3 additions & 7 deletions prefixed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import re
import sys

__version__ = '0.4.1'
__version__ = '0.4.2'

try:
BASESTRING = basestring
Expand Down Expand Up @@ -100,12 +100,8 @@ def raise_from_none(exc): # pragma: no cover

if sys.version_info[0] >= 3: # pragma: no branch
exec('def raise_from_none(exc):\n raise exc from None') # pylint: disable=exec-used
maketrans = str.maketrans
else:
from string import maketrans # pragma: no cover

DEPRECATED = {'j', 'J'}
TRANS_DEPRECATED = maketrans('jJ', 'km')
DEPRECATED = {'j': 'k', 'J': 'm'}


def _convert(value, spec):
Expand Down Expand Up @@ -302,7 +298,7 @@ def __format__(self, format_spec):

# Handle deprecated spec types
if spec['type'] in DEPRECATED:
spec['type'] = spec['type'].translate(TRANS_DEPRECATED)
spec['type'] = DEPRECATED[spec['type']]

# If not a spec we handle, use float.__format__(()
if spec['type'] not in {'h', 'H', 'k', 'K', 'm', 'M'}:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ def test_deprecated(self):
self.assertEqual(format(Float(2048), '.2j'), '2.00Ki')
self.assertEqual(format(Float(2048), '.2J'), '2.00K')

# Unicode for Python 2
self.assertEqual(format(Float(2048), u'.2j'), '2.00Ki')
self.assertEqual(format(Float(2048), u'.2J'), '2.00K')


class TestFloatMath(unittest.TestCase):
"""
Expand Down

0 comments on commit a476a30

Please sign in to comment.