Should & could we have `testing.assertIsInstance(a, b, msg)`
I copied a number of exceptions and assertion functions from the Python unittest module into our testing module. Among them are:
-
assertIsInstance(a, b, msg) -
assertNotIsInstance(a, b, msg)
They do not work:
ERROR: Error when compiling testing module: Compilation error
|
232 | if not isinstance(a, b):
| ^
Unexpected variable name: b
I think this is natural for our type system, but don't really know? @nordlander ?
There is no requirement that we must have the same exceptions and assertion functions as in Python. On the contrary, it's really just an inspiration and we should adopt it to suit Acton.
So, my question is, can we support this? Even if we can, do we want to? Or how should users express assertions with isinstance in their testing? Does it even make sense in a typed language?
def _test_my_unit_test():
a = 3
if not isinstance(a, int):
raise testing.NotIsInstance(a, "int")
Maybe one tests this by relying on the type system?
def foo():
return "hi"
def _test_my_unit_test():
a = foo()
b: int = a
which turns it into compilation error... and that's sort of what we want. It's a good thing that we can move run time errors to build time errors with a strong type system, so maybe this is what we should encourage?