Open kmr-srbh opened 3 months ago
The above code is completely valid and executes properly in CPython.
I have 2 suggestions for a fix:
ListConstant
, but we are not handling it.The problem does not occur when a local scope is used.
from lpython import i32
def foo():
d: dict[str, str] = {"a": "hello", "b": "lpython"}
d.keys()
foo()
I think it is related to the return value not being utilised. A workaround for the issue can be to assign the return value to some dummy/temporary variable.
% cat examples/expr2.py
d: dict[str, str] = {"a": "hello", "b": "lpython"}
a: list[str] = d.keys()
% python examples/expr2.py
% lpython examples/expr2.py
I think it is related to the return value not being utilised.
You are right @Shaikh-Ubaid. The code I had shared above is valid in CPython, but in LPython, it causes the compiler to believe it is executing in interactive mode. This does not happen for all the methods with a return value. The following executes normally.
from lpython import i32
l: list[i32] = [1, 2, 3, 4, 5]
l.pop(0)
print(l)