Skip to content

Commit

Permalink
pofile: don't crash when message.locations can't be sorted
Browse files Browse the repository at this point in the history
Fixes #606
  • Loading branch information
akx committed May 27, 2019
1 parent 1d7a4da commit 509f209
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion babel/messages/pofile.py
Expand Up @@ -581,7 +581,16 @@ def _write_message(message, prefix=''):

if not no_location:
locs = []
for filename, lineno in sorted(message.locations):

# Attempt to sort the locations. If we can't do that, for instance
# because there are mixed integers and Nones or whatnot (see issue #606)
# then give up, but also don't just crash.
try:
locations = sorted(message.locations)
except TypeError: # e.g. "TypeError: unorderable types: NoneType() < int()"
locations = message.locations

for filename, lineno in locations:
if lineno and include_lineno:
locs.append(u'%s:%d' % (filename.replace(os.sep, '/'), lineno))
else:
Expand Down

0 comments on commit 509f209

Please sign in to comment.