File: cf_none.pyx

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (122 lines) | stat: -rw-r--r-- 2,377 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

cimport cython

@cython.test_fail_if_path_exists('//NoneCheckNode')
def none_checks(a):
    """
    >>> none_checks(1)
    22
    >>> none_checks(None)
    True
    """
    c = None
    d = {11:22}
    if a is c:
        return True
    else:
        return d.get(11)

@cython.test_assert_path_exists('//NoneCheckNode')
def dict_arg(dict a):
    """
    >>> dict_arg({})
    >>> dict_arg({1:2})
    2
    """
    return a.get(1)

@cython.test_fail_if_path_exists('//NoneCheckNode')
def dict_arg_not_none(dict a not None):
    """
    >>> dict_arg_not_none({})
    >>> dict_arg_not_none({1:2})
    2
    """
    return a.get(1)

@cython.test_assert_path_exists('//NoneCheckNode')
def reassignment(dict d):
    """
    >>> reassignment({})
    (None, 2)
    >>> reassignment({1:3})
    (3, 2)
    """
    a = d.get(1)
    d = {1:2}
    b = d.get(1)
    return a, b

@cython.test_fail_if_path_exists('//NoneCheckNode')
def conditional(a):
    """
    >>> conditional(True)
    2
    >>> conditional(False)
    3
    """
    if a:
        d = {1:2}
    else:
        d = {1:3}
    return d.get(1)

@cython.test_assert_path_exists('//NoneCheckNode')
def conditional_arg(a, dict d):
    """
    >>> conditional_arg(True,  {1:2})
    >>> conditional_arg(False, {1:2})
    2
    """
    if a:
        d = {}
    return d.get(1)

@cython.test_fail_if_path_exists('//NoneCheckNode')
def conditional_not_none(a, dict d not None):
    """
    >>> conditional_not_none(True,  {1:2})
    >>> conditional_not_none(False, {1:2})
    2
    """
    if a:
        d = {}
    return d.get(1)

@cython.test_fail_if_path_exists('//NoneCheckNode')
def self_dependency(int x):
    """
    >>> self_dependency(1)
    (1, 2)
    >>> self_dependency(2)
    (None, None)
    """
    cdef dict a, b
    a = {1:2}
    b = {2:1}
    for i in range(x):
        a,b = b,a
    return a.get(2), b.get(1)

@cython.test_assert_path_exists('//NoneCheckNode')
def self_dependency_none(int x):
    """
    >>> self_dependency_none(False)
    1
    >>> self_dependency_none(True)
    Traceback (most recent call last):
    AttributeError: 'NoneType' object has no attribute 'get'
    """
    cdef dict a, b
    a = None
    b = {2:1}
    if x:
        a,b = b,a
    return b.get(2)

@cython.test_fail_if_path_exists('//NoneCheckNode')
def in_place_op():
    vals = [0]
    vals += [1]
    for x in vals:
        pass