Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
832fe4fd
Commit
832fe4fd
authored
May 02, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add control flow testcases
parent
b40ce510
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
335 additions
and
0 deletions
+335
-0
tests/errors/w_uninitialized.pyx
tests/errors/w_uninitialized.pyx
+69
-0
tests/errors/w_uninitialized_class.pyx
tests/errors/w_uninitialized_class.pyx
+17
-0
tests/errors/w_uninitialized_del.pyx
tests/errors/w_uninitialized_del.pyx
+16
-0
tests/errors/w_uninitialized_exc.pyx
tests/errors/w_uninitialized_exc.pyx
+77
-0
tests/errors/w_uninitialized_for.pyx
tests/errors/w_uninitialized_for.pyx
+38
-0
tests/errors/w_uninitialized_py2.pyx
tests/errors/w_uninitialized_py2.pyx
+26
-0
tests/errors/w_uninitialized_py3.pyx
tests/errors/w_uninitialized_py3.pyx
+21
-0
tests/errors/w_uninitialized_while.pyx
tests/errors/w_uninitialized_while.pyx
+30
-0
tests/errors/w_unused.pyx
tests/errors/w_unused.pyx
+41
-0
No files found.
tests/errors/w_uninitialized.pyx
0 → 100644
View file @
832fe4fd
# 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
# Disable for now
## def withctx(ctx):
## with ctx:
## pass
## with ctx as foo:
## print(foo)
_ERRORS
=
"""
6:11: local variable 'a' referenced before assignment
12:12: local variable 'a' might be referenced before assignment
29:12: local variable 'a' might be referenced before assignment
35:15: local variable 'b' might be referenced before assignment
"""
tests/errors/w_uninitialized_class.pyx
0 → 100644
View file @
832fe4fd
# cython: warn.maybe_uninitialized=True
# mode: error
# tag: werror
# class scope
def
foo
(
c
):
class
Foo
(
object
):
if
c
>
0
:
b
=
1
print
a
,
b
a
=
1
return
Foo
_ERRORS
=
"""
10:15: local variable 'a' referenced before assignment
10:18: local variable 'b' might be referenced before assignment
"""
tests/errors/w_uninitialized_del.pyx
0 → 100644
View file @
832fe4fd
# cython: warn.maybe_uninitialized=True
# mode: error
# tag: werror
def
foo
(
x
):
a
=
1
del
a
,
b
b
=
2
return
a
,
b
_ERRORS
=
"""
7:9: Deletion of non-Python, non-C++ object
7:12: local variable 'b' referenced before assignment
7:12: Deletion of non-Python, non-C++ object
9:12: local variable 'a' referenced before assignment
"""
tests/errors/w_uninitialized_exc.pyx
0 → 100644
View file @
832fe4fd
# cython: warn.maybe_uninitialized=True
# mode: error
# tag: werror
def
exc_target
():
try
:
{}[
'foo'
]
except
KeyError
,
e
:
pass
except
IndexError
,
i
:
pass
return
e
,
i
def
exc_body
():
try
:
a
=
1
except
Exception
:
pass
return
a
def
exc_else_pos
():
try
:
pass
except
Exception
,
e
:
pass
else
:
e
=
1
return
e
def
exc_body_pos
(
d
):
try
:
a
=
d
[
'foo'
]
except
KeyError
:
a
=
None
return
a
def
exc_pos
():
try
:
a
=
1
except
Exception
:
a
=
1
return
a
def
exc_finally
():
try
:
a
=
1
finally
:
pass
return
a
def
exc_finally2
():
try
:
pass
finally
:
a
=
1
return
a
def
exc_assmt_except
(
a
):
try
:
x
=
a
except
:
return
x
def
exc_assmt_finaly
(
a
):
try
:
x
=
a
except
:
return
x
_ERRORS
=
"""
12:12: local variable 'e' might be referenced before assignment
12:15: local variable 'i' might be referenced before assignment
19:12: local variable 'a' might be referenced before assignment
63:16: local variable 'x' might be referenced before assignment
69:16: local variable 'x' might be referenced before assignment
"""
tests/errors/w_uninitialized_for.pyx
0 → 100644
View file @
832fe4fd
# cython: warn.maybe_uninitialized=True
# mode: error
# tag: werror
def
simple_for
(
n
):
for
i
in
n
:
a
=
1
return
a
def
simple_for_break
(
n
):
for
i
in
n
:
a
=
1
break
return
a
def
simple_for_pos
(
n
):
for
i
in
n
:
a
=
1
else
:
a
=
0
return
a
def
simple_target
(
n
):
for
i
in
n
:
pass
return
i
def
simple_target_f
(
n
):
for
i
in
n
:
i
*=
i
return
i
_ERRORS
=
"""
8:12: local variable 'a' might be referenced before assignment
14:12: local variable 'a' might be referenced before assignment
26:12: local variable 'i' might be referenced before assignment
31:12: local variable 'i' might be referenced before assignment
"""
tests/errors/w_uninitialized_py2.pyx
0 → 100644
View file @
832fe4fd
# cython: language_level=2, warn.maybe_uninitialized=True
# mode: error
# tag: werror
def
list_comp
(
a
):
r
=
[
i
for
i
in
a
]
return
i
# dict comp is py3 feuture and don't leak here
def
dict_comp
(
a
):
r
=
{
i
:
j
for
i
,
j
in
a
}
return
i
,
j
def
dict_comp2
(
a
):
r
=
{
i
:
j
for
i
,
j
in
a
}
print
i
,
j
i
,
j
=
0
,
0
_ERRORS
=
"""
7:12: local variable 'i' might be referenced before assignment
12:12: undeclared name not builtin: i
12:15: undeclared name not builtin: j
16:11: local variable 'i' referenced before assignment
16:14: local variable 'j' referenced before assignment
"""
tests/errors/w_uninitialized_py3.pyx
0 → 100644
View file @
832fe4fd
# cython: language_level=3, warn.maybe_uninitialized=True
# mode: error
# tag: werror
def
list_comp
(
a
):
r
=
[
i
for
i
in
a
]
print
(
i
)
i
=
0
return
r
def
dict_comp
(
a
):
r
=
{
i
:
j
for
i
,
j
in
a
}
print
(
i
)
i
=
0
return
r
_ERRORS
=
"""
7:11: local variable 'i' referenced before assignment
13:11: local variable 'i' referenced before assignment
"""
tests/errors/w_uninitialized_while.pyx
0 → 100644
View file @
832fe4fd
# cython: warn.maybe_uninitialized=True
# mode: error
# tag: werror
def
simple_while
(
n
):
while
n
>
0
:
n
-=
1
a
=
0
return
a
def
simple_while_break
(
n
):
while
n
>
0
:
n
-=
1
break
else
:
a
=
1
return
a
def
simple_while_pos
(
n
):
while
n
>
0
:
n
-=
1
a
=
0
else
:
a
=
1
return
a
_ERRORS
=
"""
9:12: local variable 'a' might be referenced before assignment
17:12: local variable 'a' might be referenced before assignment
"""
tests/errors/w_unused.pyx
0 → 100644
View file @
832fe4fd
# cython: warn.unused=True, warn.unused_arg=True, warn.unused_result=True
# mode: error
# tag: werror
def
unused_variable
():
a
=
1
def
unused_cascade
(
arg
):
a
,
b
=
arg
.
split
()
return
a
def
unused_arg
(
arg
):
pass
def
unused_result
():
r
=
1
+
1
r
=
2
return
r
def
unused_nested
():
def
unused_one
():
pass
def
unused_class
():
class
Unused
:
pass
# this should not generate warning
def
used
(
x
,
y
):
x
.
y
=
1
y
[
0
]
=
1
lambda
x
:
x
_ERRORS
=
"""
6:6: Unused entry 'a'
9:9: Unused entry 'b'
12:15: Unused argument 'arg'
16:6: Unused result in 'r'
21:4: Unused entry 'unused_one'
25:4: Unused entry 'Unused'
"""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment