[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Pylint false positives

Steven D'Aprano <steve+comp.lang.python at pearwood.info>:

> On Sun, 19 Aug 2018 11:43:44 +0300, Marko Rauhamaa wrote:
>> At least some of the methods of inner classes are closures (or there
>> would be no point to an inner class).
> [...]
> (2) Whether or not the methods of an inner class are closures depends on 
> the methods, not the fact that it is an inner class. There are no 
> closures here:
>     class Outer:
>         class Inner:
>            ...
> no matter what methods Inner has. Nor is this a closure:
>     class Outer:
>         def method(self):
>             class Inner:
>                 def spam(self):
>                     return self.eggs
>             return Inner

The most useful use of inner classes is something like this:

    class Outer:
        def method(self):
            outer = self

            class Inner:
                def spam(self, a, b):
                    outer.quarantine(a, b)

            return Inner()

> You made a vague comment about inner classes being equivalent to
> closures in some unknown fashion, but inner classes are not themselves
> closures, and the methods of inner classes are not necessarily
> closures.

I hope the above outline removes the vagueness.

>>>> populating an object with fields (methods) in a loop is very rarely
>>>> a good idea.
>>> Of course it is *rarely* a good idea
>> So no dispute then.
> Isn't there? Then why are you disagreeing with me about the
> exceptional cases where it *is* a good idea?

I don't know which statement of mine you are referring to exactly now.