DeprecationWarning: generator '_sep_inserter' raised StopIteration - PEP 479
See original GitHub issueIn 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:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This was fixed with merge request #43. I will close the issue when then next version of
natsort
is released.Added in version 5.1.0.