On Wed, May 26, 2021 at 10:31 PM Shreyan Avigyan pythonshreyan09@gmail.com wrote:
Reply to Paul Moore:
if some_condition: constant a = 1 else: a = 2 a = 3
Yes this is allowed. This is runtime.
for i in range(10): constant a = []
Not sure. Though it's preferable to be runtime. Preferable is "not allowed".
And lists are also literals. Any Python Object that is not assigned to a variable is a literal. Python claims that itself. A preview -
[10] = [2] SyntaxError: Can't assign to literal here.
The literal that you can't assign to here is "10". You're perfectly allowed to assign to a list display:
[x, y, z] = range(3)
Constants should have a similar error -
constant x = 10 x = [2] SomeErrorType: Can't assign to constant here.
Is it a syntax error? Be VERY specific here. It makes a huge difference.
Also, what about this:
constant x = 10 def f(): x = 20
SyntaxError? Runtime error? Shadowing?
This is important and cannot be brushed aside.
ChrisA