На 23.03.2018 в 07:00, Steven D'Aprano написа:
On Thu, Mar 22, 2018 at 08:30:44PM -0500, Ian Stapleton Cordasco wrote:
Regarding Q2: Why would you want to prohibit class attributes starting with single or double underscores? The former is useful for "private" class attributes. The latter performs name mangling which can be useful in situations (see: https://stackoverflow.com/a/1301369/1953283). I don't think pylint should be warning in this case.
But __all__ is a dunder name, and dunders are reserved for use by Python.
I don't know what the author of the class thought they were doing, but they shouldn't have been using __all__ for it, hence the idea of a warning. But it probably isn't practical to keep a white list of permitted dunders and warn about those that any others.
Thanks everyone for the replies and the useful links.
I also don't know what the original author was trying to do. In most cases in the original code this class attribute is not used and it looks like they were trying to control the list of exported class methods. I don't have other explanation about it.
I am with Steven on this one, __all__ is a dunder (plus it looks very confusing inside the class context) so warn about it.
I didn't express myself clearly on the second question. Instead of warning about class attributes that *start* with single or double underscore how about pylint warns about class attributes whose names are dunders (both start and end with double underscores) ?