[issue35966] Didn't raise "StopIteration" Error when I use "yield" in the function

2019-02-11 Thread sheiun


sheiun  added the comment:

But it still can catch by using try/except

>>> def generate_loop_stopiteration():
... for i in range(10):
... print(i)
... # should raise StopIteration when i > 5
... try:
... k = next(j for j in range(5) if j == i)
... except StopIteration:
... print('catch')
... print(k)
... yield k
...
>>> print(list(generate_loop_stopiteration()))
0
0
1
1
2
2
3
3
4
4
5
catch
4
6
catch
4
7
catch
4
8
catch
4
9
catch
4
[0, 1, 2, 3, 4, 4, 4, 4, 4, 4]
>>>

--

___
Python tracker 
<https://bugs.python.org/issue35966>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35966] Didn't raise "StopIteration" Error when I use "yield" in the function

2019-02-11 Thread sheiun


Change by sheiun :


--
nosy:  -sheiun

___
Python tracker 
<https://bugs.python.org/issue35966>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35966] Didn't raise "StopIteration" Error when I use "yield" in the function

2019-02-11 Thread sheiun


New submission from sheiun :

Python 3.6.7 |Anaconda custom (64-bit)| (default, Oct 28 2018, 19:44:12) [MSC 
v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def generate_loop():
... for i in range(10):
... print(i)
... # should raise StopIteration when i > 5
... k = next(j for j in range(5) if j == i)
... print(k)
... yield k
...
>>>
>>> def generate():
... # should raise StopIteration
... k = next(j for j in range(5) if j == 6)
... yield k
...
>>>
>>> print(list(generate_loop()))
0
0
1
1
2
2
3
3
4
4
5
[0, 1, 2, 3, 4]
>>>
>>> print(list(generate()))
[]
>>>
>>> k = next(j for j in range(5) if j == 6)
Traceback (most recent call last):
  File "", line 1, in 
StopIteration
>>>

--
components: Library (Lib)
files: test.py
messages: 335215
nosy: sheiun
priority: normal
severity: normal
status: open
title: Didn't raise "StopIteration" Error when I use "yield" in the function
versions: Python 3.6
Added file: https://bugs.python.org/file48133/test.py

___
Python tracker 
<https://bugs.python.org/issue35966>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com