On Tue, 25 May 2021 11:53:20 -0000
"Shreyan Avigyan" <firstname.lastname@example.org> wrote:
> I posted my previous idea regarding this on the mailing list. This
> idea is a little different. This idea suggests introducing constant
> name bindings. This is similar to const pointer in C/C++. Once a name
> has been assigned to a data we can change the data (if mutable) but
> we cannot change the name to point to a different data. The only way
> the data the constant points can get deallocated is if it goes out of
> scope, the program exits or the constant is manually `del` by the
> user. The proposed syntax is as follows,
> constant x = 10
> constant y = ["List"]
> constant z: str = "Hi"
The idea of introducing constants on the core language level in Python
is well-known topic and was brought up on multiple occasions both on
the python-ideas and python-dev mailing lists. A random example:
"constants in Python: Starting simple and gradually adding more
features, was: Re: Pattern Matching controversy"
The matter is actually implementing it in different Python
implementations. And some implementations had support for *some kind*
of constants for many years (e.g. MicroPython with it's pre-annotation
syntax of "FOO = const(1)"), while CPython still has it only on the
level of external first-generation annotation module, "typing".
As another example, I can give "strict mode"
feature of my Python dialect, Pycopy
), which implements some (but again,
not all) aspects of const'ness. E.g.:
a: const = 1
a: const = 2
a = 3
Warning: strict mode: overriding (monkey-patching) const name 'a'
Traceback (most recent call last):
File "strict.py", line 9, in __main__
RuntimeError: strict mode: cannot override const name
Python-ideas mailing list -- email@example.com
To unsubscribe send an email to firstname.lastname@example.org
Message archived at
Code of Conduct: http://python.org/psf/codeofconduct/