Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mypyc] Make exception type check in assertRaises test helper precise #18241

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading