diff options
author | Seth M Morton <seth.m.morton@gmail.com> | 2016-04-15 18:48:49 -0700 |
---|---|---|
committer | Seth M Morton <seth.m.morton@gmail.com> | 2016-04-15 18:48:49 -0700 |
commit | a4d78779e0352ede7f0a45ff9bcede4d599a2fd2 (patch) | |
tree | cc135ad59bcfb7386c393f7db6d71fcf4c61091a | |
parent | a86c70d953d05b40aa49db834b21e90f36f663ad (diff) | |
download | natsort-a4d78779e0352ede7f0a45ff9bcede4d599a2fd2.tar.gz |
Switched to try: except in fastnumbers.
This will only be used in Python2.
-rw-r--r-- | natsort/compat/fake_fastnumbers.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/natsort/compat/fake_fastnumbers.py b/natsort/compat/fake_fastnumbers.py index 1254449..da64d71 100644 --- a/natsort/compat/fake_fastnumbers.py +++ b/natsort/compat/fake_fastnumbers.py @@ -36,14 +36,14 @@ def fast_float(x, key=lambda x: x, nan=None, x = float(x) return nan if nan is not None and x != x else x except ValueError: - if len(x) == 1 and not (is_py2 and not isinstance(x, unicode)): - return uni(x, key(x)) - else: + try: + return uni(x, key(x)) if len(x) == 1 else key(x) + except TypeError: return key(x) else: - if len(x) == 1 and not (is_py2 and not isinstance(x, unicode)): - return uni(x, key(x)) - else: + try: + return uni(x, key(x)) if len(x) == 1 else key(x) + except TypeError: return key(x) @@ -57,12 +57,12 @@ def fast_int(x, key=lambda x: x, nan=None, uni=unicodedata.digit): try: return long(x) except ValueError: - if len(x) == 1 and not (is_py2 and not isinstance(x, unicode)): - return uni(x, key(x)) - else: + try: + return uni(x, key(x)) if len(x) == 1 else key(x) + except TypeError: return key(x) else: - if len(x) == 1 and not (is_py2 and not isinstance(x, unicode)): - return uni(x, key(x)) - else: + try: + return uni(x, key(x)) if len(x) == 1 else key(x) + except TypeError: return key(x) |