osdir.com


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

Pylint false positives


On 2018-08-17, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> On the other hand, your objection to the following three idioms is as 
> good an example of the Blurb Paradox as I've ever seen.

Do you mean the Blub Paradox? If so, you're misunderstanding or at
least misapplying it.

>>   * code running directly under the class definition 
>>   * creating a method then changing its name with foo.__name__ 
>>   * poking things into to the class namespace with locals() 
>
> Each of these are standard Python techniques, utterly unexceptional.

I guess we'll have to agree to disagree there.

> "Code running directly under the class" describes every use of the class 
> keyword (except those with an empty body). If you write:
>
>     class Spam:
>         x = 1
>
> you are running code under the class. This is not just a pedantic 
> technicality,

Yes, it absolutely is, in this context. Having code other than
assignments and function definitions under the class statement
is extremely rare.

>>   * dynamically adding @abstractmethod methods to a class
>
> I simply don't get this objection at all. All methods are added 
> dynamically to classes (that's how Python's execution model works, def is 
> an executable statement not a declaration). Making them abstract doesn't 
> change this.
>
> You might be thinking of the warning in the docs:
>
>     "Dynamically adding abstract methods to a class, [...] 
>     [is] not supported."
>
> but that is talking about the case where you add the method to the class 
> after the class is created, from the outside:

Yes, I was referring to that. You may well be right about what it
means to say, but it's not what it actually says.

>> (Not to mention your code means the methods cannot have meaningful
>> docstrings.)
>
> Of course they can, provided they're all identical, give or take some 
> simple string substitutions.

Hence "meaningful".