On Wed, Aug 5, 2020 at 2:03 PM Ricky Teachey <ricky@teachey.org> wrote:

And btw this works: 

>>> class const(int):
...     def __new__(cls, name, val):
...         obj = super().__new__(cls, val)
...         obj.name = name
...         return obj
...     def about(self):
...         print(self.name, '=', self)
...
>>> a = const('a', 5)
>>> a
5
>>> a.about()
a = 5

That's literally useless, because after running that there is nothing stopping you from doing:

>>> a = 10

or even:

>>> a = "python has no constants"

And now a has a value different from 5.

There is nothing even remotely resembling const-ness to that class. In order to get const-ness, you would need the ability to overload assignments, like C++ can do. And Python can't do that, and that's probably a good thing.