Unexpected PendingDeprecationWarning
Chris Angelico
rosuav at gmail.com
Tue Nov 22 22:24:46 EST 2016
On Wed, Nov 23, 2016 at 2:14 PM, Nathan Ernst <nathan.ernst at gmail.com> wrote:
> I was not aware of that PEP.
>
> The logic in my function is exactly as desired, so to squelch the warning,
> I merely wrapped the iteration in a try/except:
>
> def adjacent_difference(seq, selector=identity):
> i = iter(seq)
> l = selector(next(i))
> try:
> while True:
> r = selector(next(i))
> yield r - l
> l = r
> except StopIteration:
> return
You'll probably want to move the 'try' up one line - unless you want
an exception if the sequence is empty. And it's exactly this kind of
ambiguity that this change helps to catch.
ChrisA
More information about the Python-list
mailing list