On Wed, 26 May 2021 at 13:13, Shreyan Avigyan <pythonshreya...@gmail.com> wrote:
>
> Reply to Paul Moore:
>
> In Python terms, a constant is a name that binds itself to a value in memory 
> and that name cannot bind itself to a different value now (unlike variables). 
> The value can be mutated (if mutable) but the name cannot bind to a different 
> value once it has bind itself to a value.

"value in memory" isn't Python terminology. Nor is "variable". Please
point me to the exact sections in the language reference if you feel
I'm wrong here. In particular, Python refers to "identifiers" and
"names" - see 
https://docs.python.org/3/reference/lexical_analysis.html#identifiers
("Identifiers (also referred to as names) are described by the
following lexical definitions.")

On Wed, 26 May 2021 at 13:31, Shreyan Avigyan <pythonshreya...@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.

OK, so a=3 may raise an exception at runtime (depending on the value
of some_condition). We need to decide exactly what exception would be
used but I'm OK with that. It's specifically *not* a syntax exception,
though, as that's a compile-time exception.

>
> for i in range(10):
>     constant a = []
>
> Not sure. Though it's preferable to be runtime. Preferable is "not allowed".

I don't know what you mean here. Are you saying that you'd prefer it
not to be allowed? It's your proposal, the decision is up to you.

> And lists are also literals. Any Python Object that is not assigned to a 
> variable is a literal. Python claims that itself. A preview -

Read the language reference here:
https://docs.python.org/3/reference/lexical_analysis.html#literals

> [10] = [2]
> SyntaxError: Can't assign to literal here.

As Chris pointed out, this is flagging the assignment to the literal
10. Have you properly researched the existing semantics to make sure
you understand what you're proposing to change, or are you just
guessing?

> Constants should have a similar error -
>
> constant x = 10
> x = [2]
> SomeErrorType: Can't assign to constant here.

But you just said it was runtime, so it definitely *isn't* similar to
the syntax error "Can't assign to literal here". You're making
inconsistent statements again :-(

On Wed, 26 May 2021 at 13:53, Shreyan Avigyan <pythonshreya...@gmail.com> wrote:
>
> I've already given one. Since Python is dynamically typed changing a critical 
> variable can cause huge instability. Want a demonstration? Here we go,
>
> import sys
> sys.stdout = None

However, there's a *huge* amount of extremely useful code out there
that does assign to sys.stdout - pytest's mechanisms for capturing
test output use this, for example. Making sys.stdout constant would
break this.

I don't think you've thought this proposal through at all, to be
honest. You seem to be making up answers as the questions arise, which
is *not* what people are asking for here. We are asking that you
*explain* your proposal, assuming that you already know the answers
and are simply struggling to communicate the details.

Paul
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DJSIL362DVSYXOLGZEM24NGAXJTOHGL3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to