[Python-ideas] Should Python have user-defined constants?
Stéfane Fermigier
sf at fermigier.com
Tue Nov 21 06:12:44 EST 2017
That's one way to do it with no changes to the language, though
syntaxically I find it lacking a bit of elegance (maybe a matter of getting
accustomed with it?).
Also, I'm not sure "Final" really conveys what it means (at first glance, I
thought it was about immutability, not constantness).
Maybe "Const" would be better in this context ? (Or maybe you've discussed
this question already and come to the conclusion that "Final" is better for
some reason?)
S.
On Tue, Nov 21, 2017 at 11:41 AM, Ivan Levkivskyi <levkivskyi at gmail.com>
wrote:
> On 21 November 2017 at 10:47, Paul Moore <p.f.moore at gmail.com> wrote:
>
>> -1. I don't see how this would improve any programs I've written or
>> seen. Tools like mypy or linters might benefit from a feature to track
>> constants and ensure they don't get changed
>>
>
> It is actually likely that something like this will appear in ``typing``:
>
> from typing import Final, List
>
> x: Final = 42
> x = 1 # Fails type check
>
> lst: Final[List[int]] = []
> lst.append(5) # OK
> lst = [1, 2, 3] # Fails type check
>
> --
> Ivan
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
--
Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier -
http://linkedin.com/in/sfermigier
Founder & CEO, Abilian - Enterprise Social Software -
http://www.abilian.com/
Chairman, Free&OSS Group / Systematic Cluster -
http://www.gt-logiciel-libre.org/
Co-Chairman, National Council for Free & Open Source Software (CNLL) -
http://cnll.fr/
Founder & Organiser, PyData Paris - http://pydata.fr/
---
“You never change things by fighting the existing reality. To change
something, build a new model that makes the existing model obsolete.” — R.
Buckminster Fuller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171121/0006b211/attachment-0001.html>
More information about the Python-ideas
mailing list