summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth Morton <seth.m.morton@gmail.com>2017-08-17 23:02:24 -0700
committerGitHub <noreply@github.com>2017-08-17 23:02:24 -0700
commitc2f4b5d8adc2c1fddc2968c75fae04175f96061f (patch)
tree5472577043055797fbb8e967a3c9dd0ad6fe8ac2
parente412d5a9109efd3408a7cf1e290c597142a3ba4f (diff)
parentf64e5345a8dd3a4e774e6771f582de01b23df7c5 (diff)
downloadnatsort-c2f4b5d8adc2c1fddc2968c75fae04175f96061f.tar.gz
Merge pull request #43 from lykinsbd/master
-rw-r--r--natsort/utils.py35
1 files changed, 20 insertions, 15 deletions
diff --git a/natsort/utils.py b/natsort/utils.py
index f47c0a9..c21d3b4 100644
--- a/natsort/utils.py
+++ b/natsort/utils.py
@@ -234,25 +234,30 @@ def _sep_inserter(iterable, sep):
# Get the first element. If StopIteration is raised, that's OK.
# Since we are controlling the types of the input, 'type' is used
# instead of 'isinstance' for the small speed advantage it offers.
- types = (int, float, long)
- first = next(iterable)
- if type(first) in types:
- yield sep
- yield first
-
- # Now, check if pair of elements are both numbers. If so, add ''.
- second = next(iterable)
- if type(first) in types and type(second) in types:
- yield sep
- yield second
-
- # Now repeat in a loop.
- for x in iterable:
- first, second = second, x
+ try:
+ types = (int, float, long)
+ first = next(iterable)
+ if type(first) in types:
+ yield sep
+ yield first
+
+ # Now, check if pair of elements are both numbers. If so, add ''.
+ second = next(iterable)
if type(first) in types and type(second) in types:
yield sep
yield second
+ # Now repeat in a loop.
+ for x in iterable:
+ first, second = second, x
+ if type(first) in types and type(second) in types:
+ yield sep
+ yield second
+ except StopIteration:
+ # Catch StopIteration per deprecation in PEP 479:
+ # "Change StopIteration handling inside generators"
+ return
+
def _input_string_transform_factory(alg):
"""