You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using list() on a list variable does not work #2667
% cat examples/expr2.py from lpython import i32a: list[i32]a = [2, 3]b: list[i32]b = list(a)print(b)
% python examples/expr2.py[2, 3]
% lpython examples/expr2.pysemantic error: Type mismatch in assignment, the types must be compatible --> examples/expr2.py:6:1 |6 | b = list(a) | ^ ^^^^^^^ type mismatch ('list[i32]' and 'list[str]')Note: Please report unclear or confusing messages as bugs athttps://github.com/lcompilers/lpython/issues.
I have a working fix ready for this. I wish to discuss some design decisions before pushing the changes.
We essentially need generics to fully achieve this. The error in the above example stated list[str] because that is the only implementation we currently have for list() inside lpython_builtin.py. I have written some implementations for list of integers and floats, but we cannot handle arbitrary nesting this way. For now, we may handle some nesting by hand, like list[list[i32]]. Although it is not a good idea, it will help us to test methods like dict.keys and dict.values more clearly. Currently tests for both these methods check for the length of the returned list.
Activity
kmr-srbh commentedon Apr 26, 2024
I have a working fix ready for this. I wish to discuss some design decisions before pushing the changes.
We essentially need generics to fully achieve this. The error in the above example stated
list[str]because that is the only implementation we currently have forlist()insidelpython_builtin.py. I have written some implementations for list of integers and floats, but we cannot handle arbitrary nesting this way. For now, we may handle some nesting by hand, likelist[list[i32]]. Although it is not a good idea, it will help us to test methods likedict.keysanddict.valuesmore clearly. Currently tests for both these methods check for the length of the returned list.@Shaikh-Ubaid @certik @czgdp1807 What is your take on this?