3 ms·
I don't see the point of `final` without an optimizing compiler. Name mangling is sufficient for stashing references to avoid accidental side-effects of overri
by xapata 7y ago
I don't see the point of `final` without an optimizing compiler. Name mangling is sufficient for stashing references to avoid accidental side-effects of overriding.
- eru 7y agoYou can guard yourself against overriding in the same module this way, too. For name mangling, I think you need to start your variable with underscores, and then it won't be accessible for reading outside the module either?
- Sean1708 7y agoFor modules you can access the variable just fine, but for classes you need to use the mangled name: $ cat >foo.py __FOO = 1 class Foo: __FOO = 2 $ cat >bar.py import foo print(foo.__FOO) print(foo.Foo()._Foo__FOO) $ python3 bar.py 1 2
- xapata 7y agoNope, you don't need to start the name with underscores. class Foo: bar = 'public' __bar = bar # stashed