[Python-ideas] Re: Introduce constant variables in Python

2021-06-17 Thread Stephen J. Turnbull
tabeb qena writes: > Great Idea, I have joined the mailing list to write the same idea. > > As I can't find the great difference between Final and Constant, > So, I will use the name Final. > > I suggest one the following syntax: The syntaxes proposed already are fine. The problem is mo

[Python-ideas] Re: Introduce constant variables in Python

2021-06-17 Thread Wes Turner
On Thu, Jun 17, 2021 at 10:50 AM Chris Angelico wrote: > On Fri, Jun 18, 2021 at 12:43 AM Wes Turner wrote: > > > > > What would be the advantage of such a declaration? > > > > Constants don't need to be locked or unlocked; which is advantageous for > parallelism and reasoning about program corr

[Python-ideas] Re: Introduce constant variables in Python

2021-06-17 Thread Chris Angelico
On Fri, Jun 18, 2021 at 12:43 AM Wes Turner wrote: > > > What would be the advantage of such a declaration? > > Constants don't need to be locked or unlocked; which is advantageous for > parallelism and reasoning about program correctness. > True consts (wherein everything referred to in that obj

[Python-ideas] Re: Introduce constant variables in Python

2021-06-17 Thread Wes Turner
On Mon, May 24, 2021 at 5:43 PM Chris Angelico wrote: > > Requiring that a name not be rebound is well-defined and testable. > Requiring that an object not change is either trivial (in the case of, > say, an integer) or virtually impossible (in the case of most > objects). > What would be the a

[Python-ideas] Re: Introduce constant variables in Python

2021-06-16 Thread tabeb qena
Great Idea, I have joined the mailing list to write the same idea. As I can't find the great difference between Final and Constant, So, I will use the name Final. I suggest one the following syntax: from collection import Final 》x = Final(100) 》print(x) 》100 》y = x*2 》Print(Y) 》200 》print (

[Python-ideas] Re: Introduce constant variables in Python

2021-05-25 Thread Shreyan Avigyan
Sorry for the name conflict. I tried to type Steven D'Aprano but instead it resulted in Steve D'Aprano ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Shreyan Avigyan
Reply to Steve D'Aprano - I am talking about constant name binding. Once the name is bind it cannot be changed. The data will remain immutable or mutable. > That seems very odd. That would mean that you can't pass constants to > functions, or put them in lists or dicts, since that would create

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Steven D'Aprano
"Constant variables" is a contradiction in terms. If it is constant, it cannot be a variable, and vice versa. Can we be more precise in the language used please? We have two independent concepts here: * name bindings: names can be bound to a value, or unbound with the `del` statement; * val

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Chris Angelico
On Tue, May 25, 2021 at 8:09 AM Joren wrote: > > We could define "change" in terms of the hash of the object the name points > to, as well as the name itself (the pointer to the object). The hash of a random.Random() object doesn't change when its state does (its derived solely from its id). Nor

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Stestagg
-1 for all of this unless it’s included as part of a bigger change that has proven performance benefits when constants are used On Mon, 24 May 2021 at 23:10, Joren wrote: > We could define "change" in terms of the hash of the object the name > points to, as well as the name itself (the pointer t

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Joren
We could define "change" in terms of the hash of the object the name points to, as well as the name itself (the pointer to the object). ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Chris Angelico
On Tue, May 25, 2021 at 7:30 AM Joren wrote: > > typing.Final actually means something like "cannot be reassigned", whereas > constant variable means "cannot change". Consider e.g. > > class Spam: > def __init__(self): > self.eggs = 0 > > @final # method cannot be overridden (wh

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Joren
typing.Final actually means something like "cannot be reassigned", whereas constant variable means "cannot change". Consider e.g. class Spam: def __init__(self): self.eggs = 0 @final # method cannot be overridden (which is more related to "reassignment" than to "change")

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Shreyan Avigyan
Thomas Grainger: > This is already available with typing.Final and immutable types: > > from typing import Final > > ham: Final = 3 > ham = 4 # Error > > hams: Final[Sequence[str]] = ["ham", "spam"] > hams.append("meat") # Error I'm not sure whether it's a reply to me or someone else. But anyways

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Thomas Grainger
This is already available with typing.Final and immutable types: from typing import Final ham: Final = 3 ham = 4 # Error hams: Final[Sequence[str]] = ["ham", "spam"] hams.append("meat") # Error On Mon, 24 May 2021, 18:40 Abdur-Rahmaan Janhangeer, wrote: > Greetings, > > Just a light-hearted

[Python-ideas] Re: Introduce constant variables in Python

2021-05-24 Thread Abdur-Rahmaan Janhangeer
Greetings, Just a light-hearted note, if ever the idea is taken seriously, variable: constant = 10 seems more pythonic to me. constant variable = 10 opens the doors for int x = 5 etc Kind Regards, Abdur-Rahmaan Janhangeer about | blog