[Python-Dev] pep8 reasoning

Steven D'Aprano steve at pearwood.info
Sat Apr 26 09:07:40 CEST 2014


On Fri, Apr 25, 2014 at 08:42:02PM -0400, Donald Stufft wrote:
> 
> On Apr 25, 2014, at 7:20 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> 
> > On 04/25/2014 03:26 PM, Donald Stufft wrote:
> >> 
> >> pep8.py doesn’t violate PEP8, it just takes a stricter view of it.
> > 
> > If pep8 reports errors on things that PEP 8 says are okay, that's a violation.

> Not really, any code that passes the pep8.py check is perfectly valid in the eyes of PEP8,
> if a check was implemented to say, require camelCase method names, then that would
> be a violation of a check. Being stricter is not a violation, it’s being stricter.

Suppose that some package claiming to check for PEP 8 compliance decided 
to flag variable names like "foo" and "bar" as errors. Perhaps it was 
inspired by Tim Peters:

    Indeed, when I design my killer language, the identifiers 
    "foo" and "bar" will be reserved words, never used, and not 
    even mentioned in the reference manual. Any program using 
    one will simply dump core without comment. Multitudes will 
    rejoice.  --  Tim Peters, 29 Apr 1998

Or perhaps it decides that one should never, ever have more than a 
single dot in a row, a treat that as an error:

    obj.method()  # okay
    obj.method().attribute  # Law Of Demeter violation

This hypothetical checker is stricter than PEP 8, in that it allows 
nothing that PEP 8 forbids. But it also forbids things which are allowed 
by PEP 8, which is a false negative error: things which should be 
allowed (according to PEP 8) are forbidden by the checker.

(The other kind of error is a false positive, where things which are 
forbidden by PEP 8 are wrongly allowed by the checker.)

I stress that they're only errors if the checker is running in PEP 8 
compatibility mode, where it is supposed to check for PEP 8 compliance. 
That's the crux of Nick's, and Ethan's, argument: with a name like 
"PEP8", it is reasonable to expect that by default the checker operates 
in PEP 8 compatibility mode. I agree with them.



-- 
Steven


More information about the Python-Dev mailing list