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")
def more(self):
self.eggs += 1
spam: Final[Spam] = Spam()
spam.more() # This is allowed, but spam changed
del spam # Allowed as well
Moreover, `Final` is part of typing, which is strange because it indicates a
property of the variable name itself, not of its type. Perhaps the constant
keyword can become a replacement for the confusing `typing.Final`.
So "constant" is semantically different than `typing.Final` (and
`typing.final`), and it makes more sense to have it be a keyword (e.g.
`constant spam`), instead of it being an annotation; it only should be used
when declaring variables and attributes (e.g. `def f(a: Final)` is not allowed).
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/IDERCN7SGKKV34ISDROFMTCEJJIND4NH/
Code of Conduct: http://python.org/psf/codeofconduct/