16
\$\begingroup\$

Your task is to write a file which contains a line with many pep8 violations.

The rules:

  • We use pep8 version 1.5.7 and the default settings.
  • Calling pep8 with other command line options or using a custom rc file is not allowed.
  • Maximum line length 120 characters. You can violate E501, sure, but the line which your score is calculated on has to be <= 120 characters.
  • Your module can have other lines before or after, but only one line contributes to your score.
  • Your file can contain SyntaxErrors or any kind of garbage, it needn't import or run.

Example of scoring:

The following module thing.py has a score of 2, because it contains a line (line 1) with 2 pep8 violations.

 spam='potato'

To check a score:

~$ mktmpenv 
(tmp-ae3045bd2f629a8c)~/.virtualenvs/tmp-ae3045bd2f629a8c$ pip install pep8==1.5.7
(tmp-ae3045bd2f629a8c)~/.virtualenvs/tmp-ae3045bd2f629a8c$ echo -n "spam='potato'" > thing.py
(tmp-ae3045bd2f629a8c)~/.virtualenvs/tmp-ae3045bd2f629a8c$ pep8 thing.py 
thing.py:1:5: E225 missing whitespace around operator
thing.py:1:14: W292 no newline at end of file
\$\endgroup\$
  • 2
    \$\begingroup\$ Is this a... language-specific challenge? Because we don't really like these. \$\endgroup\$ – John Dvorak Jul 15 '14 at 17:37
  • \$\begingroup\$ I guess it's not really language specific (because the file can contain any garbage) but obviously people familiar with python coding will have some advantage \$\endgroup\$ – wim Jul 15 '14 at 17:38
11
\$\begingroup\$

241

if you want the most error, just go crazy with semicolon

$ cat test.py
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

$ cat test.py | wc -m
120

$ pep8 test.py | wc -l
241

most of the error are:

test.py:1:119: E231 missing whitespace after ';'
test.py:1:119: E702 multiple statements on one line (semicolon)

with those error at the end:

test.py:1:120: E703 statement ends with a semicolon
test.py:1:121: W292 no newline at end of file
\$\endgroup\$
  • \$\begingroup\$ @wim couldn't reply to your post so i just put it here. you were right about the advantage, i be surprise if someone figure out something else that cause more error then what i posted above \$\endgroup\$ – freeforall tousez Jul 17 '14 at 0:08
  • \$\begingroup\$ I think you are a semicolon short. wc counts the trailing newline, but we don't count that for character counts on this site. As you can see in your code quote, your last character is #119. You should get 240, 2 for each semicolon except the last one, 1 for the overly long line, and 1 for ending with a semicolon. \$\endgroup\$ – isaacg Jul 17 '14 at 2:58
  • \$\begingroup\$ @isaacg ah, you are right, i thought it was weird that it gotten less error than number of character * 2, i blame gedit for adding the invisible newline :P \$\endgroup\$ – freeforall tousez Jul 17 '14 at 3:10
  • \$\begingroup\$ haha, kind of cheap .. but effective! +1 \$\endgroup\$ – wim Jul 17 '14 at 10:13
7
\$\begingroup\$

123

Yes, more violations than characters!

$ curl -s http://pastebin.com/raw.php?i=RwLJfa0Q | cat
 (  =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =   =
$ curl -s http://pastebin.com/raw.php?i=RwLJfa0Q | wc -m
 120
$ curl -s http://pastebin.com/raw.php?i=RwLJfa0Q | pep8 - | wc -l
 123

The trick is that an = after a ( makes pep think you're doing a keyword in a function call (e.g. foo(bar=12)). In this context, doing [TAB]= triggers both

killpep.py:1:3: E223 tab before operator
killpep.py:1:3: E251 unexpected spaces around keyword / parameter equals

And doing =[TAB] triggers both

killpep.py:1:5: E224 tab after operator
killpep.py:1:5: E251 unexpected spaces around keyword / parameter equals

Gleefully enough, you can just chain these.

This gives a violation count of one per character. I need ( to set it up, but not providing the ) gives us:

killpep.py:2:1: E901 TokenError: EOF in multi-line statement

That's 120. No newline = 121. It managed to trigger the "line too long" error, so that's 122. Finally, using one character to start with a space (thanks eric_lagergren) gives 2 violations instead of 1:

killpep.py:1:2: E111 indentation is not a multiple of four
killpep.py:1:2: E113 unexpected indentation

Victory!

\$\endgroup\$
  • \$\begingroup\$ Add a leading whitespace and remove the last z and you'll end up with 103... but whenever I copy this code I get 83 instead of 102. I think the spacing is getting messed up. \$\endgroup\$ – Eric Lagergren Jul 16 '14 at 2:09
  • \$\begingroup\$ @eric_lagergren: I'm using tabs instead of spaces and I guess they aren't copying properly. Will pastebin it I guess! \$\endgroup\$ – Claudiu Jul 16 '14 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.