I think this construct is overly specific and adds unnecessary logic.
For a collection, it is relevant that:
It has an iterator method: __iter__().
That said iterator method returns an iterator, and we can get the type of the collection then by checking the type of __next__.
The return type of __next__ then determines the type of the lookup.
For tuples, there is TrueName logic to deal with such constructs.
For literal collections (i.e. defined to top level such as def x := {2,3,4}), we can have helper methods which constraint this:
Iterator method returns a class, and we can pass generics to this class to determine the type of the __next__ method.
Then we can proceed as above.
If we don't know the set type at the generation site, we can probably use a temporary variable.
Summary of current issue
I think this construct is overly specific and adds unnecessary logic. For a collection, it is relevant that:
__iter__()
.__next__
.__next__
then determines the type of the lookup.For tuples, there is
TrueName
logic to deal with such constructs. For literal collections (i.e. defined to top level such asdef x := {2,3,4}
), we can have helper methods which constraint this:__next__
method. Then we can proceed as above.