w_uninitialized.pyx 2.66 KB
Newer Older
Vitja Makarov's avatar
Vitja Makarov committed
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
# cython: warn.maybe_uninitialized=True
# mode: error
# tag: werror

def simple():
    print a
    a = 0

def simple2(arg):
    if arg > 0:
        a = 1
    return a

def simple_pos(arg):
    if arg > 0:
        a = 1
    else:
        a = 0
    return a

def ifelif(c1, c2):
    if c1 == 1:
        if c2:
            a = 1
        else:
            a = 2
    elif c1 == 2:
        a = 3
    return a

def nowimpossible(a):
    if a:
        b = 1
    if a:
        print b

def fromclosure():
    def bar():
        print a
    a = 1
    return bar

# Should work ok in both py2 and py3
def list_comp(a):
    return [i for i in a]

def set_comp(a):
    return set(i for i in a)

def dict_comp(a):
    return {i: j for i, j in a}

# args and kwargs
def generic_args_call(*args, **kwargs):
    return args, kwargs

Vitja Makarov's avatar
Vitja Makarov committed
57 58 59 60 61 62 63
def cascaded(x):
    print a, b
    a = b = x

def from_import():
    print bar
    from foo import bar
Vitja Makarov's avatar
Vitja Makarov committed
64

Vitja Makarov's avatar
Vitja Makarov committed
65 66 67 68 69 70 71 72 73 74 75 76
def regular_import():
    print foo
    import foo

def raise_stat():
    try:
        raise exc, msg
    except:
        pass
    exc = ValueError
    msg = 'dummy'

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
def defnode_decorator():
    @decorator
    def foo():
        pass
    def decorator():
        pass

def defnode_default():
    def foo(arg=default()):
        pass
    def default():
        pass

def class_bases():
    class foo(bar):
        pass
    class bar(object):
        pass

def class_decorators():
    @decorator
    class foo(object):
        pass
    def decorator(cls):
        return cls

def class_py3k_metaclass():
    class foo(metaclass=Meta):
        pass
    class Meta(object):
        pass

def class_py3k_args():
    class foo(*args, **kwargs):
        pass
    args = []
    kwargs = {}

Vitja Makarov's avatar
Vitja Makarov committed
115
_ERRORS = """
116 117 118 119 120 121 122 123 124 125
6:10: local variable 'a' referenced before assignment
12:11: local variable 'a' might be referenced before assignment
29:11: local variable 'a' might be referenced before assignment
35:14: local variable 'b' might be referenced before assignment
58:10: local variable 'a' referenced before assignment
58:13: local variable 'b' referenced before assignment
62:10: local variable 'bar' referenced before assignment
66:10: local variable 'foo' referenced before assignment
71:14: local variable 'exc' referenced before assignment
71:19: local variable 'msg' referenced before assignment
126
78:4: local variable 'decorator' referenced before assignment
127 128
85:16: local variable 'default' referenced before assignment
91:14: local variable 'bar' referenced before assignment
129
97:4: local variable 'decorator' referenced before assignment
130 131 132
104:24: local variable 'Meta' referenced before assignment
110:15: local variable 'args' referenced before assignment
110:23: local variable 'kwargs' referenced before assignment
Vitja Makarov's avatar
Vitja Makarov committed
133
"""