Closed LuKuangChen closed 2 years ago
Assertions in Python are stripped by the compiler if the optimization level is 1+. If we refine a type in our static compiler based on an isinstance
assert, we transform that assert into a CAST
at runtime. If the type is wrong, a CAST
raises TypeError
. So these two tests are both passing, and correct. With optimization level 1, the assertion is stripped but replaced by a CAST
and so TypeError
is raised. With optimization level 0, AssertionError
is raised.
I'm curious, shouldn't the test then be predicated by the optimization level? You're saying there are really two different tests here, one for level 0 and one for level 1+.
The one test passes optimize=1
to in_module
which compiles the code str with opt level 1; the other compiles with the default opt level 0.
Are you seeing the _optimized
one fail when you run it? It passes here and in GitHub CI.
Ah, that explains it. We'd been running the codestr
by themselves and hadn't noticed optimize=1
was setting up a context.
2022-01-07
foo("a")
raises anAssertionError
, but the test expects aTypeError
.There is a test that looks like a corrected version of this one.