type testing #15
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Python seems to want
isinstance(obj, the_type)
and nottype(obj) === the_type
.But, we might still want our own function that can be used with "subscripted generics".
I don't think subscripted generics can be tested in Python. In general, we can just discard the generic paramter, and there would be no way to get it back, so there is no way to test it. For containers that uses generic parameters such as lists, it is possible to have elements of different types, so the function has to scan through the whole object possibly recursively, which is not efficient.
Forgot this previously. We can use this, the syntax is not a big issue. Will open another PR.
The goal here is to have the same behavior in the interpreter and NAC3.
In NAC3 I think we want to be able to test for
List[float]
vs.List[int]
for example.In the interpreter we can:
The simulator could have a debug/performance switch that selects either behavior.
For option two, perhaps we should do something like this:
Maybe we should use a custom function instead of using builtin functions, so we can provide one for running on host.
@pca006132 I like this idea and as mentioned, this can be handled well in a simulator.
Also, will we use
list[int]
ortyping.List[int]
? I think the former is legal since Python 3.9 while the latter is used for earlier Python versions but still legal.Ah right, and it's even deprecated
https://docs.python.org/3/library/typing.html#typing.List
We could do Python 3.9+ only then and
list[int]
.