The typing_extensions module defines a "Final" type that can be used to prevent subsequent assignments.
See https://mypy.readthedocs.io/en/latest/final_attrs.html from typing_extensions.
After looking at this more, I'm inclined not to support it at this time. I don't think it's very well conceived.
Hmm, Final appears in typing.pyi as supplied in the pyright extension, but it doesn't work. Perhaps it should be removed?
Now that this is part of the python standard (as of 3.8), I think it makes sense to add support for it. Reopening.
Boy, the specification of the "Final" annotation is full of inconsistencies. I wish I could go back in time and improve the proposal before it made its way into the Python spec. :(
That said, I added support for it in Pyright (with some semi-gross hacks and assumptions). This will be in the next release.
This is now implemented in 1.1.20, which I just published.
Thanks!
Most helpful comment
Now that this is part of the python standard (as of 3.8), I think it makes sense to add support for it. Reopening.