2 ms·
This is an impressive library, but I don't really see the usefulness. That is either because I'm a Python programmer, and Java semantics aren't useful in Python
by StavrosK 11y ago
This is an impressive library, but I don't really see the usefulness. That is either because I'm a Python programmer, and Java semantics aren't useful in Python, or because I'm a Python programmer, and I haven't used Java semantics, so I wouldn't know.
I can say, though, that I've never had problems with something accessing private variables that it shouldn't have. The meaning of private variables in Python isn't "don't access anything that starts with an underscore", rather it's "you're accessing these variables at your own risk".
This "we're all adults" model has worked out very well for my use cases. Can anyone share a few cases where hard constraints here would be beneficial?
- tyingq 11y agoIt feels like it might work better used as a test/verify step, but doesn't have the mechanics to be toggled on and off easily. I can see the value in quickly knowing if new code is mucking with private/protected properties.
- msellout 11y ago> I can see the value in quickly knowing if new code is mucking with private/protected properties. Would this do it? re.findall(r'(?<!self)\._\w+', sourcelines) Anytime you're using ``obj._foo`` and it's not ``self._foo`` that suggests you're mucking about with the internals of an object that the author didn't expect you to use.
- tyingq 11y agoThat would miss some things, like iteration of all properties without a direct reference, subclasses accessing _Parent__private stuff, etc. I'm not actively looking for a solution, just noting this might be more well received if you could easily turn it off and on. Edit: Again, not looking for solutions. I thought the feedback of being able to turn it on/off might be useful for the OP.
- msellout 11y agoWell, for your future reference, Pylint (https://www.pylint.org/ https://www.pylint.org/) checks for that and many other common pitfalls. I'm sure its competitors PyChecker and Pyflakes do so as well.