cython

Форк
0
/
generator_frame_cycle.py 
58 строк · 1.1 Кб
1
# mode: run
2
# tag: generator
3

4
import cython
5
import sys
6

7

8
def test_generator_frame_cycle():
9
    """
10
    >>> test_generator_frame_cycle()
11
    ("I'm done",)
12
    """
13
    testit = []
14
    def whoo():
15
        try:
16
            yield
17
        except:
18
            yield
19
        finally:
20
            testit.append("I'm done")
21
    g = whoo()
22
    next(g)
23

24
    # Frame object cycle
25
    eval('g.throw(ValueError)', {'g': g})
26
    del g
27

28
    return tuple(testit)
29

30

31
def test_generator_frame_cycle_with_outer_exc():
32
    """
33
    >>> test_generator_frame_cycle_with_outer_exc()
34
    ("I'm done",)
35
    """
36
    testit = []
37
    def whoo():
38
        try:
39
            yield
40
        except:
41
            yield
42
        finally:
43
            testit.append("I'm done")
44
    g = whoo()
45
    next(g)
46

47
    try:
48
        raise ValueError()
49
    except ValueError as exc:
50
        assert sys.exc_info()[1] is exc, sys.exc_info()
51
        # Frame object cycle
52
        eval('g.throw(ValueError)', {'g': g})
53
        # CPython 3.3 handles this incorrectly itself :)
54
        assert sys.exc_info()[1] is exc, sys.exc_info()
55
        del g
56
        assert sys.exc_info()[1] is exc, sys.exc_info()
57

58
    return tuple(testit)
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.