question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DeprecationWarning: generator '_sep_inserter' raised StopIteration - PEP 479

See original GitHub issue

In Python 3.6.1, I’m experiencing an issue with a DeprecationWarning as shown below:

lib/python3.6/site-packages/natsort/utils.py:366: DeprecationWarning: generator '_sep_inserter' raised StopIteration
  return lambda split_val, val: tuple(split_val)

Code functions and proceeds, however it pops the above DeprecationWarning for every sort.

Appears to be PEP 479 related. As of Python 3.5, StopIteration handling has changed inside generators.

From PEP 479 section on the Transition Plan, it seems like the correct timing as 3.6 is when the non-silent warning was instituted:

Python 3.5: Enable new semantics under __future__ import; silent deprecation warning if StopIteration bubbles out of a generator not under __future__ import.
Python 3.6: Non-silent deprecation warning.
Python 3.7: Enable new semantics everywhere.

The Natsort code itself shows a comment about StopIteration inside of the referenced _sep_inserter method: https://github.com/SethMMorton/natsort/blob/master/natsort/utils.py#L233

# Get the first element. If StopIteration is raised, that's OK.

Seems like we may just need to handle the raised StopIteration exception as outlined in PEP 479 and execute inside a try...except block to catch StopIteration.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SethMMortoncommented, Aug 19, 2017

This was fixed with merge request #43. I will close the issue when then next version of natsort is released.

0reactions
SethMMortoncommented, Aug 19, 2017

Added in version 5.1.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 479 – Change StopIteration handling inside generators
This PEP proposes a change to generators: when StopIteration is raised inside a generator, it is replaced with RuntimeError . (More precisely, this...
Read more >
generator 'RevisionMap._iterate_revisions' raised ... - GitHub
Migrated issue, originally created by Christopher Sang (@csang) Run a downgrade on an initially empty db, using a command like: python -Wall `which...
Read more >
How to get rid of warning "DeprecationWarning generator ...
This is happening because ngrams is raising StopIteration exception to end a generator, and this is deprecated from Python 3.5.
Read more >
Python 3.7: StopIteration could be your next headache
Python 3.7 release notes explains very clearly changes that this new version brings into python behavior, being one of them PEP-479.
Read more >
Python 3.7 - RuntimeError: generator raised StopIteration
PEP 479 is enabled for all code in Python 3.7, meaning that StopIteration exceptions raised directly or indirectly in coroutines and generators ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found