Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
417e1c5f
Commit
417e1c5f
authored
Jan 10, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some nonzero-related tests
parent
eae111dd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
1 deletion
+117
-1
src/core/cfg.cpp
src/core/cfg.cpp
+4
-0
test/tests/boolops.py
test/tests/boolops.py
+13
-1
test/tests/nonzero_exceptions.py
test/tests/nonzero_exceptions.py
+100
-0
No files found.
src/core/cfg.cpp
View file @
417e1c5f
...
...
@@ -1055,6 +1055,10 @@ public:
#endif
curblock
->
push_back
(
node
);
return
;
}
else
if
(
asgn
->
value
->
type
==
AST_TYPE
::
Name
&&
ast_cast
<
AST_Name
>
(
asgn
->
value
)
->
id
[
0
]
==
'#'
)
{
// Assigning from one temporary name to another:
curblock
->
push_back
(
node
);
return
;
}
}
}
...
...
test/tests/boolops.py
View file @
417e1c5f
...
...
@@ -34,4 +34,16 @@ if 0:
print
bool
(
c
)
# this will fail
print
1
and
c
# Note: nonzero isn't called on the second argument!
print
C
(
True
)
or
1
# prints the object repr, not the nonzero repr
print
c
and
1
print
# nonzero should fall back on __len__ if that exists but __nonzero__ doesn't:
class
D
(
object
):
def
__init__
(
self
,
n
):
self
.
n
=
n
def
__len__
(
self
):
print
"__len__"
return
self
.
n
for
i
in
xrange
(
0
,
3
):
print
i
,
bool
(
D
(
i
))
test/tests/nonzero_exceptions.py
0 → 100644
View file @
417e1c5f
class
MyException
(
Exception
):
pass
class
C
(
object
):
def
__init__
(
self
,
x
):
self
.
x
=
x
def
__nonzero__
(
self
):
raise
MyException
(
self
.
x
)
# Make sure that we can handle nonzero() throwing an exception wherever it occurs:
try
:
print
C
(
1
)
and
1
except
TypeError
,
e
:
print
e
try
:
print
C
(
2
)
or
1
except
TypeError
,
e
:
print
e
try
:
if
C
(
3
):
pass
except
TypeError
,
e
:
print
e
try
:
while
C
(
4
):
pass
except
TypeError
,
e
:
print
e
try
:
assert
C
(
5
)
except
TypeError
,
e
:
print
e
try
:
print
[
1
for
i
in
range
(
5
)
if
C
(
6
)]
except
TypeError
,
e
:
print
e
try
:
print
list
(
1
for
i
in
range
(
5
)
if
C
(
7
))
except
TypeError
,
e
:
print
e
try
:
print
1
if
C
(
8
)
else
0
except
TypeError
,
e
:
print
e
class
M
(
type
):
def
__instancecheck__
(
self
,
instance
):
print
"instancecheck"
,
instance
return
C
(
9
)
def
__subclasscheck__
(
self
,
sub
):
print
"subclasscheck"
,
sub
return
C
(
10
)
class
F
(
Exception
):
__metaclass__
=
M
# We should check the type of exception against F using __subclasscheck__, but it's going throw an exception
# trying to evaluate __subclasscheck__.
# But that new error should get suppressed and the original exception not caught (by that block)
try
:
1
/
0
except
F
:
print
"shouldn't get here"
except
ZeroDivisionError
:
print
"ok"
# But if the exception gets thrown at a slightly different point in the
# exception-handler-filtering, the new exception propagates!
try
:
try
:
1
/
0
except
C
()
or
1
:
print
"shouldn't get here"
print
"shouldn't get here 2"
except
TypeError
,
e
:
print
e
class
E
(
object
):
def
__lt__
(
self
,
rhs
):
return
C
(
"false"
)
# This is ok because it doesn't evaluate the result of the comparison:
print
E
()
<
1
try
:
# This is not ok because it will!
print
E
()
<
1
<
1
except
TypeError
,
e
:
print
e
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