Skip to content

Commit

Permalink
[mypyc] Make exception type check in assertRaises test helper precise (
Browse files Browse the repository at this point in the history
  • Loading branch information
JukkaL authored Dec 4, 2024
1 parent f51090d commit cc45bec
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mypyc/test-data/fixtures/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def assertRaises(typ: type, msg: str = '') -> Iterator[None]:
try:
yield
except Exception as e:
assert isinstance(e, typ), f"{e!r} is not a {typ.__name__}"
assert type(e) is typ, f"{e!r} is not a {typ.__name__}"
assert msg in str(e), f'Message "{e}" does not match "{msg}"'
else:
assert False, f"Expected {typ.__name__} but got no exception"
Expand Down
18 changes: 9 additions & 9 deletions mypyc/test-data/run-i64.test
Original file line number Diff line number Diff line change
Expand Up @@ -1307,28 +1307,28 @@ def test_many_locals() -> None:
a31: i64 = 31
a32: i64 = 32
a33: i64 = 33
with assertRaises(NameError):
with assertRaises(UnboundLocalError):
print(a0)
with assertRaises(NameError):
with assertRaises(UnboundLocalError):
print(a31)
with assertRaises(NameError):
with assertRaises(UnboundLocalError):
print(a32)
with assertRaises(NameError):
with assertRaises(UnboundLocalError):
print(a33)
a0 = 5
assert a0 == 5
with assertRaises(NameError):
with assertRaises(UnboundLocalError):
print(a31)
with assertRaises(NameError):
with assertRaises(UnboundLocalError):
print(a32)
with assertRaises(NameError):
with assertRaises(UnboundLocalError):
print(a33)
a32 = 55
assert a0 == 5
assert a32 == 55
with assertRaises(NameError):
with assertRaises(UnboundLocalError):
print(a31)
with assertRaises(NameError):
with assertRaises(UnboundLocalError):
print(a33)
a31 = 10
a33 = 20
Expand Down
4 changes: 2 additions & 2 deletions mypyc/test-data/run-misc.test
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ from testutil import assertRaises

f(True, True)
f(False, False)
with assertRaises(NameError):
with assertRaises(UnboundLocalError):
f(False, True)
with assertRaises(NameError):
with assertRaises(UnboundLocalError):
g()
[out]
lol
Expand Down
4 changes: 2 additions & 2 deletions mypyc/test-data/run-primitives.test
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ delAttribute()
delAttributeMultiple()
with assertRaises(AttributeError):
native.global_var
with assertRaises(NameError, 'local variable "dummy" referenced before assignment'):
with assertRaises(UnboundLocalError, 'local variable "dummy" referenced before assignment'):
delLocal(True)
assert delLocal(False) == 10
with assertRaises(NameError, 'local variable "dummy" referenced before assignment'):
with assertRaises(UnboundLocalError, 'local variable "dummy" referenced before assignment'):
delLocalLoop()
[out]
(1, 2, 3)
Expand Down

0 comments on commit cc45bec

Please sign in to comment.