[Python-ideas] Should Python have user-defined constants?

אלעזר elazarg at gmail.com
Tue Nov 21 06:10:46 EST 2017


Note that no other feature in typing is about the reference - everything is
about the objects themselves. Final makes less sense as a general type. We
can't enforce A[T]().foo() not to reassign a Final T.

Elazar

בתאריך יום ג׳, 21 בנוב׳ 2017, 12:42, מאת Ivan Levkivskyi ‏<
levkivskyi at gmail.com>:

> 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/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171121/49313ff9/attachment.html>


More information about the Python-ideas mailing list