1PYCODESTYLE(1) pycodestyle PYCODESTYLE(1)
2
3
4
6 pycodestyle - pycodestyle documentation
7
8 Python style guide checker
9
10 pycodestyle (formerly pep8) is a tool to check your Python code against
11 some of the style conventions in PEP 8.
12
13 Contents:
14
16 pycodestyle is a tool to check your Python code against some of the
17 style conventions in PEP 8.
18
19 • Features
20
21 • Disclaimer
22
23 • Installation
24
25 • Example usage and output
26
27 • Configuration
28
29 • Error codes
30
31 • Related tools
32
33 Features
34 • Plugin architecture: Adding new checks is easy.
35
36 • Parseable output: Jump to error location in your editor.
37
38 • Small: Just one Python file, requires only stdlib. You can use just
39 the pycodestyle.py file for this purpose.
40
41 • Comes with a comprehensive test suite.
42
43 Disclaimer
44 This utility does not enforce every single rule of PEP 8. It helps to
45 verify that some coding conventions are applied but it does not intend
46 to be exhaustive. Some rules cannot be expressed with a simple algo‐
47 rithm, and other rules are only guidelines which you could circumvent
48 when you need to.
49
50 Always remember this statement from PEP 8:
51 A style guide is about consistency. Consistency with this style
52 guide is important. Consistency within a project is more important.
53 Consistency within one module or function is most important.
54
55 Among other things, these features are currently not in the scope of
56 the pycodestyle library:
57
58 • naming conventions: this kind of feature is supported through plug‐
59 ins. Install flake8 and the pep8-naming extension to use this fea‐
60 ture.
61
62 • docstring conventions: they are not in the scope of this library; see
63 the pydocstyle project.
64
65 • automatic fixing: see the section PEP8 Fixers in the related tools
66 page.
67
68 Installation
69 You can install, upgrade, uninstall pycodestyle.py with these commands:
70
71 $ pip install pycodestyle
72 $ pip install --upgrade pycodestyle
73 $ pip uninstall pycodestyle
74
75 Example usage and output
76 $ pycodestyle --first optparse.py
77 optparse.py:69:11: E401 multiple imports on one line
78 optparse.py:77:1: E302 expected 2 blank lines, found 1
79 optparse.py:88:5: E301 expected 1 blank line, found 0
80 optparse.py:222:34: W602 deprecated form of raising exception
81 optparse.py:347:31: E211 whitespace before '('
82 optparse.py:357:17: E201 whitespace after '{'
83 optparse.py:472:29: E221 multiple spaces before operator
84 optparse.py:544:21: W601 .has_key() is deprecated, use 'in'
85
86 You can also make pycodestyle.py show the source code for each error,
87 and even the relevant text from PEP 8:
88
89 $ pycodestyle --show-source --show-pep8 testsuite/E40.py
90 testsuite/E40.py:2:10: E401 multiple imports on one line
91 import os, sys
92 ^
93 Imports should usually be on separate lines.
94
95 Okay: import os\nimport sys
96 E401: import sys, os
97
98 Or you can display how often each error was found:
99
100 $ pycodestyle --statistics -qq Python-2.5/Lib
101 232 E201 whitespace after '['
102 599 E202 whitespace before ')'
103 631 E203 whitespace before ','
104 842 E211 whitespace before '('
105 2531 E221 multiple spaces before operator
106 4473 E301 expected 1 blank line, found 0
107 4006 E302 expected 2 blank lines, found 1
108 165 E303 too many blank lines (4)
109 325 E401 multiple imports on one line
110 3615 E501 line too long (82 characters)
111 612 W601 .has_key() is deprecated, use 'in'
112 1188 W602 deprecated form of raising exception
113
114 You can also make pycodestyle.py show the error text in different for‐
115 mats by using --format having options default/pylint/custom:
116
117 $ pycodestyle testsuite/E40.py --format=default
118 testsuite/E40.py:2:10: E401 multiple imports on one line
119
120 $ pycodestyle testsuite/E40.py --format=pylint
121 testsuite/E40.py:2: [E401] multiple imports on one line
122
123 $ pycodestyle testsuite/E40.py --format='%(path)s|%(row)d|%(col)d| %(code)s %(text)s'
124 testsuite/E40.py|2|10| E401 multiple imports on one line
125
126 Variables in the custom format option
127
128 ┌─────────┬───────────────┐
129 │Variable │ Significance │
130 └─────────┴───────────────┘
131
132
133 │path │ File name │
134 ├─────────┼───────────────┤
135 │row │ Row number │
136 ├─────────┼───────────────┤
137 │col │ Column number │
138 ├─────────┼───────────────┤
139 │code │ Error code │
140 ├─────────┼───────────────┤
141 │text │ Error text │
142 └─────────┴───────────────┘
143
144 Quick help is available on the command line:
145
146 $ pycodestyle -h
147 Usage: pycodestyle [options] input ...
148
149 Options:
150 --version show program's version number and exit
151 -h, --help show this help message and exit
152 -v, --verbose print status messages, or debug with -vv
153 -q, --quiet report only file names, or nothing with -qq
154 --first show first occurrence of each error
155 --exclude=patterns exclude files or directories which match these comma
156 separated patterns (default: .svn,CVS,.bzr,.hg,.git)
157 --filename=patterns when parsing directories, only check filenames matching
158 these comma separated patterns (default: *.py)
159 --select=errors select errors and warnings (e.g. E,W6)
160 --ignore=errors skip errors and warnings (e.g. E4,W)
161 --show-source show source code for each error
162 --show-pep8 show text of PEP 8 for each error (implies --first)
163 --statistics count errors and warnings
164 --count print total number of errors and warnings to standard
165 error and set exit code to 1 if total is not null
166 --max-line-length=n set maximum allowed line length (default: 79)
167 --max-doc-length=n set maximum allowed doc line length and perform these
168 checks (unchecked if not set)
169 --hang-closing hang closing bracket instead of matching indentation of
170 opening bracket's line
171 --format=format set the error format [default|pylint|<custom>]
172 --diff report only lines changed according to the unified diff
173 received on STDIN
174
175 Testing Options:
176 --benchmark measure processing speed
177
178 Configuration:
179 The project options are read from the [pycodestyle] section of the
180 tox.ini file or the setup.cfg file located in any parent folder of the
181 path(s) being processed. Allowed options are: exclude, filename,
182 select, ignore, max-line-length, max-doc-length, hang-closing, count,
183 format, quiet, show-pep8, show-source, statistics, verbose.
184
185 --config=path user config file location
186 (default: ~/.config/pycodestyle)
187
188 Configuration
189 The behaviour may be configured at two levels, the user and project
190 levels.
191
192 At the user level, settings are read from the following locations:
193
194 If on Windows:
195 ~\.pycodestyle
196
197 Otherwise, if the XDG_CONFIG_HOME environment variable is defined:
198 XDG_CONFIG_HOME/pycodestyle
199
200 Else if XDG_CONFIG_HOME is not defined:
201 ~/.config/pycodestyle
202
203 Example:
204
205 [pycodestyle]
206 count = False
207 ignore = E226,E302,E41
208 max-line-length = 160
209 statistics = True
210
211 At the project level, a setup.cfg file or a tox.ini file is read if
212 present. If none of these files have a [pycodestyle] section, no
213 project specific configuration is loaded.
214
215 Error codes
216 This is the current list of error and warning codes:
217
218 ┌──────────┬────────────────────────────┐
219 │code │ sample message │
220 ├──────────┼────────────────────────────┤
221 │E1 │ Indentation │
222 ├──────────┼────────────────────────────┤
223 │E101 │ indentation contains mixed │
224 │ │ spaces and tabs │
225 ├──────────┼────────────────────────────┤
226 │E111 │ indentation is not a mul‐ │
227 │ │ tiple of four │
228 ├──────────┼────────────────────────────┤
229 │E112 │ expected an indented block │
230 ├──────────┼────────────────────────────┤
231 │E113 │ unexpected indentation │
232 ├──────────┼────────────────────────────┤
233 │E114 │ indentation is not a mul‐ │
234 │ │ tiple of four (comment) │
235 ├──────────┼────────────────────────────┤
236 │E115 │ expected an indented block │
237 │ │ (comment) │
238 ├──────────┼────────────────────────────┤
239 │E116 │ unexpected indentation │
240 │ │ (comment) │
241 ├──────────┼────────────────────────────┤
242 │E117 │ over-indented │
243 ├──────────┼────────────────────────────┤
244 │E121 (*^) │ continuation line un‐ │
245 │ │ der-indented for hanging │
246 │ │ indent │
247 ├──────────┼────────────────────────────┤
248 │E122 (^) │ continuation line missing │
249 │ │ indentation or outdented │
250 ├──────────┼────────────────────────────┤
251 │E123 (*) │ closing bracket does not │
252 │ │ match indentation of open‐ │
253 │ │ ing bracket's line │
254 ├──────────┼────────────────────────────┤
255 │E124 (^) │ closing bracket does not │
256 │ │ match visual indentation │
257 ├──────────┼────────────────────────────┤
258 │E125 (^) │ continuation line with │
259 │ │ same indent as next logi‐ │
260 │ │ cal line │
261 ├──────────┼────────────────────────────┤
262 │E126 (*^) │ continuation line over-in‐ │
263 │ │ dented for hanging indent │
264 └──────────┴────────────────────────────┘
265
266
267 │E127 (^) │ continuation line over-in‐ │
268 │ │ dented for visual indent │
269 ├──────────┼────────────────────────────┤
270 │E128 (^) │ continuation line un‐ │
271 │ │ der-indented for visual │
272 │ │ indent │
273 ├──────────┼────────────────────────────┤
274 │E129 (^) │ visually indented line │
275 │ │ with same indent as next │
276 │ │ logical line │
277 ├──────────┼────────────────────────────┤
278 │E131 (^) │ continuation line un‐ │
279 │ │ aligned for hanging indent │
280 ├──────────┼────────────────────────────┤
281 │E133 (*) │ closing bracket is missing │
282 │ │ indentation │
283 ├──────────┼────────────────────────────┤
284 │ │ │
285 ├──────────┼────────────────────────────┤
286 │E2 │ Whitespace │
287 ├──────────┼────────────────────────────┤
288 │E201 │ whitespace after '(' │
289 ├──────────┼────────────────────────────┤
290 │E202 │ whitespace before ')' │
291 ├──────────┼────────────────────────────┤
292 │E203 │ whitespace before ':' │
293 ├──────────┼────────────────────────────┤
294 │ │ │
295 ├──────────┼────────────────────────────┤
296 │E211 │ whitespace before '(' │
297 ├──────────┼────────────────────────────┤
298 │ │ │
299 ├──────────┼────────────────────────────┤
300 │E221 │ multiple spaces before op‐ │
301 │ │ erator │
302 ├──────────┼────────────────────────────┤
303 │E222 │ multiple spaces after op‐ │
304 │ │ erator │
305 ├──────────┼────────────────────────────┤
306 │E223 │ tab before operator │
307 ├──────────┼────────────────────────────┤
308 │E224 │ tab after operator │
309 ├──────────┼────────────────────────────┤
310 │E225 │ missing whitespace around │
311 │ │ operator │
312 ├──────────┼────────────────────────────┤
313 │E226 (*) │ missing whitespace around │
314 │ │ arithmetic operator │
315 ├──────────┼────────────────────────────┤
316 │E227 │ missing whitespace around │
317 │ │ bitwise or shift operator │
318 ├──────────┼────────────────────────────┤
319 │E228 │ missing whitespace around │
320 │ │ modulo operator │
321 ├──────────┼────────────────────────────┤
322 │ │ │
323 ├──────────┼────────────────────────────┤
324 │E231 │ missing whitespace after │
325 │ │ ',', ';', or ':' │
326 ├──────────┼────────────────────────────┤
327 │ │ │
328 ├──────────┼────────────────────────────┤
329 │E241 (*) │ multiple spaces after ',' │
330 ├──────────┼────────────────────────────┤
331 │E242 (*) │ tab after ',' │
332 └──────────┴────────────────────────────┘
333
334 │ │ │
335 ├──────────┼────────────────────────────┤
336 │E251 │ unexpected spaces around │
337 │ │ keyword / parameter equals │
338 ├──────────┼────────────────────────────┤
339 │ │ │
340 ├──────────┼────────────────────────────┤
341 │E261 │ at least two spaces before │
342 │ │ inline comment │
343 ├──────────┼────────────────────────────┤
344 │E262 │ inline comment should │
345 │ │ start with '# ' │
346 ├──────────┼────────────────────────────┤
347 │E265 │ block comment should start │
348 │ │ with '# ' │
349 ├──────────┼────────────────────────────┤
350 │E266 │ too many leading '#' for │
351 │ │ block comment │
352 ├──────────┼────────────────────────────┤
353 │ │ │
354 ├──────────┼────────────────────────────┤
355 │E271 │ multiple spaces after key‐ │
356 │ │ word │
357 ├──────────┼────────────────────────────┤
358 │E272 │ multiple spaces before │
359 │ │ keyword │
360 ├──────────┼────────────────────────────┤
361 │E273 │ tab after keyword │
362 ├──────────┼────────────────────────────┤
363 │E274 │ tab before keyword │
364 ├──────────┼────────────────────────────┤
365 │E275 │ missing whitespace after │
366 │ │ keyword │
367 ├──────────┼────────────────────────────┤
368 │ │ │
369 ├──────────┼────────────────────────────┤
370 │E3 │ Blank line │
371 ├──────────┼────────────────────────────┤
372 │E301 │ expected 1 blank line, │
373 │ │ found 0 │
374 ├──────────┼────────────────────────────┤
375 │E302 │ expected 2 blank lines, │
376 │ │ found 0 │
377 ├──────────┼────────────────────────────┤
378 │E303 │ too many blank lines (3) │
379 ├──────────┼────────────────────────────┤
380 │E304 │ blank lines found after │
381 │ │ function decorator │
382 ├──────────┼────────────────────────────┤
383 │E305 │ expected 2 blank lines af‐ │
384 │ │ ter end of function or │
385 │ │ class │
386 ├──────────┼────────────────────────────┤
387 │E306 │ expected 1 blank line be‐ │
388 │ │ fore a nested definition │
389 ├──────────┼────────────────────────────┤
390 │ │ │
391 ├──────────┼────────────────────────────┤
392 │E4 │ Import │
393 ├──────────┼────────────────────────────┤
394 │E401 │ multiple imports on one │
395 │ │ line │
396 ├──────────┼────────────────────────────┤
397 │E402 │ module level import not at │
398 │ │ top of file │
399 └──────────┴────────────────────────────┘
400
401 │ │ │
402 ├──────────┼────────────────────────────┤
403 │E5 │ Line length │
404 ├──────────┼────────────────────────────┤
405 │E501 (^) │ line too long (82 > 79 │
406 │ │ characters) │
407 ├──────────┼────────────────────────────┤
408 │E502 │ the backslash is redundant │
409 │ │ between brackets │
410 ├──────────┼────────────────────────────┤
411 │ │ │
412 ├──────────┼────────────────────────────┤
413 │E7 │ Statement │
414 ├──────────┼────────────────────────────┤
415 │E701 │ multiple statements on one │
416 │ │ line (colon) │
417 ├──────────┼────────────────────────────┤
418 │E702 │ multiple statements on one │
419 │ │ line (semicolon) │
420 ├──────────┼────────────────────────────┤
421 │E703 │ statement ends with a │
422 │ │ semicolon │
423 ├──────────┼────────────────────────────┤
424 │E704 (*) │ multiple statements on one │
425 │ │ line (def) │
426 ├──────────┼────────────────────────────┤
427 │E711 (^) │ comparison to None should │
428 │ │ be 'if cond is None:' │
429 ├──────────┼────────────────────────────┤
430 │E712 (^) │ comparison to True should │
431 │ │ be 'if cond is True:' or │
432 │ │ 'if cond:' │
433 ├──────────┼────────────────────────────┤
434 │E713 │ test for membership should │
435 │ │ be 'not in' │
436 ├──────────┼────────────────────────────┤
437 │E714 │ test for object identity │
438 │ │ should be 'is not' │
439 ├──────────┼────────────────────────────┤
440 │E721 (^) │ do not compare types, use │
441 │ │ 'isinstance()' │
442 ├──────────┼────────────────────────────┤
443 │E722 │ do not use bare except, │
444 │ │ specify exception instead │
445 ├──────────┼────────────────────────────┤
446 │E731 │ do not assign a lambda ex‐ │
447 │ │ pression, use a def │
448 ├──────────┼────────────────────────────┤
449 │E741 │ do not use variables named │
450 │ │ 'l', 'O', or 'I' │
451 ├──────────┼────────────────────────────┤
452 │E742 │ do not define classes │
453 │ │ named 'l', 'O', or 'I' │
454 ├──────────┼────────────────────────────┤
455 │E743 │ do not define functions │
456 │ │ named 'l', 'O', or 'I' │
457 ├──────────┼────────────────────────────┤
458 │ │ │
459 ├──────────┼────────────────────────────┤
460 │E9 │ Runtime │
461 ├──────────┼────────────────────────────┤
462 │E901 │ SyntaxError or Indenta‐ │
463 │ │ tionError │
464 ├──────────┼────────────────────────────┤
465 │E902 │ IOError │
466 └──────────┴────────────────────────────┘
467
468 │ │ │
469 ├──────────┼────────────────────────────┤
470 │W1 │ Indentation warning │
471 ├──────────┼────────────────────────────┤
472 │W191 │ indentation contains tabs │
473 ├──────────┼────────────────────────────┤
474 │ │ │
475 ├──────────┼────────────────────────────┤
476 │W2 │ Whitespace warning │
477 ├──────────┼────────────────────────────┤
478 │W291 │ trailing whitespace │
479 ├──────────┼────────────────────────────┤
480 │W292 │ no newline at end of file │
481 ├──────────┼────────────────────────────┤
482 │W293 │ blank line contains white‐ │
483 │ │ space │
484 ├──────────┼────────────────────────────┤
485 │ │ │
486 ├──────────┼────────────────────────────┤
487 │W3 │ Blank line warning │
488 ├──────────┼────────────────────────────┤
489 │W391 │ blank line at end of file │
490 ├──────────┼────────────────────────────┤
491 │ │ │
492 ├──────────┼────────────────────────────┤
493 │W5 │ Line break warning │
494 ├──────────┼────────────────────────────┤
495 │W503 (*) │ line break before binary │
496 │ │ operator │
497 ├──────────┼────────────────────────────┤
498 │W504 (*) │ line break after binary │
499 │ │ operator │
500 ├──────────┼────────────────────────────┤
501 │W505 (*^) │ doc line too long (82 > 79 │
502 │ │ characters) │
503 ├──────────┼────────────────────────────┤
504 │ │ │
505 ├──────────┼────────────────────────────┤
506 │W6 │ Deprecation warning │
507 ├──────────┼────────────────────────────┤
508 │W601 │ .has_key() is deprecated, │
509 │ │ use 'in' │
510 ├──────────┼────────────────────────────┤
511 │W602 │ deprecated form of raising │
512 │ │ exception │
513 ├──────────┼────────────────────────────┤
514 │W603 │ '<>' is deprecated, use │
515 │ │ '!=' │
516 ├──────────┼────────────────────────────┤
517 │W604 │ backticks are deprecated, │
518 │ │ use 'repr()' │
519 ├──────────┼────────────────────────────┤
520 │W605 │ invalid escape sequence │
521 │ │ 'x' │
522 ├──────────┼────────────────────────────┤
523 │W606 │ 'async' and 'await' are │
524 │ │ reserved keywords starting │
525 │ │ with Python 3.7 │
526 └──────────┴────────────────────────────┘
527
528 (*) In the default configuration, the checks E121, E123, E126, E133,
529 E226, E241, E242, E704, W503, W504 and W505 are ignored because they
530 are not rules unanimously accepted, and PEP 8 does not enforce them.
531 Please note that if the option --ignore=errors is used, the default
532 configuration will be overridden and ignore only the check(s) you skip.
533 The check W503 is mutually exclusive with check W504. The check E133
534 is mutually exclusive with check E123. Use switch --hang-closing to
535 report E133 instead of E123. Use switch --max-doc-length=n to report
536 W505.
537
538 (^) These checks can be disabled at the line level using the # noqa
539 special comment. This possibility should be reserved for special
540 cases.
541 Special cases aren't special enough to break the rules.
542
543 Note: most errors can be listed with such one-liner:
544
545 $ python pycodestyle.py --first --select E,W testsuite/ --format '%(code)s: %(text)s'
546
547 Related tools
548 The flake8 checker is a wrapper around pycodestyle and similar tools.
549 It supports plugins.
550
551 Other tools which use pycodestyle are referenced in the Wiki: list of
552 related tools.
553
555 Automated tests
556 You can also execute pycodestyle tests from Python code. For example,
557 this can be highly useful for automated testing of coding style confor‐
558 mance in your project:
559
560 import unittest
561 import pycodestyle
562
563
564 class TestCodeFormat(unittest.TestCase):
565
566 def test_conformance(self):
567 """Test that we conform to PEP-8."""
568 style = pycodestyle.StyleGuide(quiet=True)
569 result = style.check_files(['file1.py', 'file2.py'])
570 self.assertEqual(result.total_errors, 0,
571 "Found code style errors (and warnings).")
572
573 There's also a shortcut for checking a single file:
574
575 import pycodestyle
576
577 fchecker = pycodestyle.Checker('testsuite/E27.py', show_source=True)
578 file_errors = fchecker.check_all()
579
580 print("Found %s errors (and warnings)" % file_errors)
581
582 Configuring tests
583 You can configure automated pycodestyle tests in a variety of ways.
584
585 For example, you can pass in a path to a configuration file that py‐
586 codestyle should use:
587
588 import pycodestyle
589
590 style = pycodestyle.StyleGuide(config_file='/path/to/tox.ini')
591
592 You can also set specific options explicitly:
593
594 style = pycodestyle.StyleGuide(ignore=['E501'])
595
596 Skip file header
597 Another example is related to the feature request #143: skip a number
598 of lines at the beginning and the end of a file. This use case is easy
599 to implement through a custom wrapper for the PEP 8 library:
600
601 #!python
602 import pycodestyle
603
604 LINES_SLICE = slice(14, -20)
605
606 class StyleGuide(pycodestyle.StyleGuide):
607 """This subclass of pycodestyle.StyleGuide will skip the first and last lines
608 of each file."""
609
610 def input_file(self, filename, lines=None, expected=None, line_offset=0):
611 if lines is None:
612 assert line_offset == 0
613 line_offset = LINES_SLICE.start or 0
614 lines = pycodestyle.readlines(filename)[LINES_SLICE]
615 return super(StyleGuide, self).input_file(
616 filename, lines=lines, expected=expected, line_offset=line_offset)
617
618 if __name__ == '__main__':
619 style = StyleGuide(parse_argv=True, config_file=True)
620 report = style.check_files()
621 if report.total_errors:
622 raise SystemExit(1)
623
624 This module declares a lines' window which skips 14 lines at the begin‐
625 ning and 20 lines at the end. If there's no line to skip at the end,
626 it could be changed with LINES_SLICE = slice(14, None) for example.
627
628 You can save it in a file and use it with the same options as the orig‐
629 inal pycodestyle.
630
632 The library provides classes which are usable by third party tools.
633
634 • Checker Classes
635
636 • Report Classes
637
638 • Utilities
639
640 Checker Classes
641 The StyleGuide class is used to configure a style guide checker in‐
642 stance to check multiple files.
643
644 The Checker class can be used to check a single file.
645
646 class pycodestyle.StyleGuide(parse_argv=False, config_file=None,
647 parser=None, paths=None, report=None, **kwargs)
648 Initialize a PEP-8 instance with few options.
649
650 init_report(reporter=None)
651 Initialize the report instance.
652
653 check_files(paths=None)
654 Run all checks on the paths.
655
656 input_file(filename, lines=None, expected=None, line_offset=0)
657 Run all checks on a Python source file.
658
659 input_dir(dirname)
660 Check all files in this directory and all subdirectories.
661
662 excluded(filename, parent=None)
663 Check if the file should be excluded.
664
665 Check if 'options.exclude' contains a pattern matching
666 filename.
667
668 ignore_code(code)
669 Check if the error code should be ignored.
670
671 If 'options.select' contains a prefix of the error code,
672 return False. Else, if 'options.ignore' contains a pre‐
673 fix of the error code, return True.
674
675 get_checks(argument_name)
676 Get all the checks for this category.
677
678 Find all globally visible functions where the first argu‐
679 ment name starts with argument_name and which contain se‐
680 lected tests.
681
682 class pycodestyle.Checker(filename=None, lines=None, report=None,
683 **kwargs)
684 Load a Python source file, tokenize it, check coding style.
685
686 readline()
687 Get the next line from the input buffer.
688
689 run_check(check, argument_names)
690 Run a check plugin.
691
692 check_physical(line)
693 Run all physical checks on a raw input line.
694
695 build_tokens_line()
696 Build a logical line from tokens.
697
698 check_logical()
699 Build a line from tokens and run all logical checks on
700 it.
701
702 check_ast()
703 Build the file's AST and run all AST checks.
704
705 generate_tokens()
706 Tokenize file, run physical line checks and yield tokens.
707
708 check_all(expected=None, line_offset=0)
709 Run all checks on the input file.
710
711 Report Classes
712 class pycodestyle.BaseReport(options)
713 Collect the results of the checks.
714
715 start()
716 Start the timer.
717
718 stop() Stop the timer.
719
720 init_file(filename, lines, expected, line_offset)
721 Signal a new file.
722
723 increment_logical_line()
724 Signal a new logical line.
725
726 error(line_number, offset, text, check)
727 Report an error, according to options.
728
729 get_file_results()
730 Return the count of errors and warnings for this file.
731
732 get_count(prefix='')
733 Return the total count of errors and warnings.
734
735 get_statistics(prefix='')
736 Get statistics for message codes that start with the pre‐
737 fix.
738
739 prefix='' matches all errors and warnings prefix='E'
740 matches all errors prefix='W' matches all warnings pre‐
741 fix='E4' matches all errors that have to do with imports
742
743 print_statistics(prefix='')
744 Print overall statistics (number of errors and warnings).
745
746 print_benchmark()
747 Print benchmark numbers.
748
749 class pycodestyle.FileReport(options)
750 Collect the results of the checks and print the filenames.
751
752 class pycodestyle.StandardReport(options)
753 Collect and print the results of the checks.
754
755 class pycodestyle.DiffReport(options)
756 Collect and print the results for the changed lines only.
757
758 Utilities
759 pycodestyle.expand_indent(line)
760 Return the amount of indentation.
761
762 Tabs are expanded to the next multiple of 8.
763
764 >>> expand_indent(' ')
765 4
766 >>> expand_indent('\t')
767 8
768 >>> expand_indent(' \t')
769 8
770 >>> expand_indent(' \t')
771 16
772
773 pycodestyle.mute_string(text)
774 Replace contents with 'xxx' to prevent syntax matching.
775
776 >>> mute_string('"abc"')
777 '"xxx"'
778 >>> mute_string("'''abc'''")
779 "'''xxx'''"
780 >>> mute_string("r'abc'")
781 "r'xxx'"
782
783 pycodestyle.read_config(options, args, arglist, parser)
784 Read and parse configurations.
785
786 If a config file is specified on the command line with the
787 "--config" option, then only it is used for configuration.
788
789 Otherwise, the user configuration (~/.config/pycodestyle) and
790 any local configurations in the current directory or above will
791 be merged together (in that order) using the read method of Con‐
792 figParser.
793
794 pycodestyle.process_options(arglist=None, parse_argv=False, con‐
795 fig_file=None)
796 Process options passed either via arglist or command line args.
797
798 Passing in the config_file parameter allows other tools, such as
799 flake8 to specify their own options to be processed in py‐
800 codestyle.
801
802 pycodestyle.register_check(func_or_cls, codes=None)
803 Register a new check object.
804
806 Source code
807 The source code is currently available on GitHub under the terms and
808 conditions of the Expat license. Fork away!
809
810 • Source code and issue tracker on GitHub.
811
812 • Continuous tests against Python 2.7 and 3.4+ as well as the nightly
813 Python build and PyPy, on Travis CI platform.
814
815 Direction
816 Some high-level aims and directions to bear in mind for contributions:
817
818 • pycodestyle is intended to be as fast as possible. Using the ast
819 module defeats that purpose. The pep8-naming plugin exists for this
820 sort of functionality.
821
822 • If you want to provide extensibility / plugins, please see flake8 -
823 pycodestyle doesn't want or need a plugin architecture.
824
825 • pycodestyle aims to have no external dependencies.
826
827 Contribute
828 You can add checks to this program by writing plugins. Each plugin is
829 a simple function that is called for each line of source code, either
830 physical or logical.
831
832 Physical line:
833
834 • Raw line of text from the input file.
835
836 Logical line:
837
838 • Multi-line statements converted to a single line.
839
840 • Stripped left and right.
841
842 • Contents of strings replaced with "xxx" of same length.
843
844 • Comments removed.
845
846 The check function requests physical or logical lines by the name of
847 the first argument:
848
849 def maximum_line_length(physical_line)
850 def extraneous_whitespace(logical_line)
851 def blank_lines(logical_line, blank_lines, indent_level, line_number)
852
853 The last example above demonstrates how check plugins can request addi‐
854 tional information with extra arguments. All attributes of the Checker
855 object are available. Some examples:
856
857 • lines: a list of the raw lines from the input file
858
859 • tokens: the tokens that contribute to this logical line
860
861 • line_number: line number in the input file
862
863 • total_lines: number of lines in the input file
864
865 • blank_lines: blank lines before this one
866
867 • indent_char: indentation character in this file (" " or "\t")
868
869 • indent_level: indentation (with tabs expanded to multiples of 8)
870
871 • previous_indent_level: indentation on previous line
872
873 • previous_logical: previous logical line
874
875 Check plugins can also maintain per-file state. If you need this, de‐
876 clare a parameter named checker_state. You will be passed a dict, which
877 will be the same one for all lines in the same file but a different one
878 for different files. Each check plugin gets its own dict, so you don't
879 need to worry about clobbering the state of other plugins.
880
881 The docstring of each check function shall be the relevant part of text
882 from PEP 8. It is printed if the user enables --show-pep8. Several
883 docstrings contain examples directly from the PEP 8 document.
884
885 Okay: spam(ham[1], {eggs: 2})
886 E201: spam( ham[1], {eggs: 2})
887
888 These examples are verified automatically when pycodestyle.py is run
889 with the --doctest option. You can add examples for your own check
890 functions. The format is simple: "Okay" or error/warning code followed
891 by colon and space, the rest of the line is example source code. If
892 you put 'r' before the docstring, you can use \n for newline and \t for
893 tab.
894
895 Then be sure to pass the tests:
896
897 $ python pycodestyle.py --testsuite testsuite
898 $ python pycodestyle.py --doctest
899 $ python pycodestyle.py --verbose pycodestyle.py
900
901 When contributing to pycodestyle, please observe our Code of Conduct.
902
903 To run the tests, the core developer team and Travis CI use tox:
904
905 $ pip install -r dev-requirements.txt
906 $ tox
907
908 All the tests should pass for all available interpreters, with the sum‐
909 mary of:
910
911 congratulations :)
912
913 Changes
914 2.6.0 (2020-05-11)
915 Announcements:
916
917 • Anthony Sottile (@asottile) joined the team as a core developer.
918 :tada:
919
920 Changes:
921
922 • E306: fix detection inside async def. PR #929.
923
924 • E301: fix regression disallowing decorated one-liners. PR #927.
925
926 • E714: fix false positive with chained is not. PR #931.
927
928 2.6.0a1 (2020-04-23)
929 New checks:
930
931 • E225: require whitespace around and in is and or. PR #847.
932
933 Changes:
934
935 • E117: fix indentation using tabs by treating as 8-space indents. PR
936 #837.
937
938 • E721: fix false positive with names containg istype. PR #850.
939
940 • E741: allow l as a named argument in a function call. PR #853.
941
942 • E302: fix false-negative with decorated functions. PR #859.
943
944 • W504: ellipsis (...) is no longer treated as a binary operator. PR
945 #875.
946
947 • E402: allow with, if, elif, else to guard imports. PR #834.
948
949 • Add support for assignment expressions := (PEP 572). PR #879.
950
951 • Add support for positional-only arguments / (PEP 570). PR #872,
952 #918.
953
954 • Add support for python 3.8.
955
956 • Add support for matrix multiplication operator @ (PEP 465). PR #897.
957
958 • Support visual indent for continuation lines for with / assert /
959 raise. PR #912.
960
961 • E302: allow two blank lines after a block of one-liners. PR #913.
962
963 • E302: allow two-and-fewer newlines at the top of the file. PR #919.
964
965 2.5.0 (2019-01-29)
966 New checks:
967
968 • E117: Over-indented code blocks
969
970 • W505: Maximum doc-string length only when configured with
971 --max-doc-length
972
973 Changes:
974
975 • Remove support for EOL Python 2.6 and 3.3. PR #720.
976
977 • Add E117 error for over-indented code blocks.
978
979 • Allow W605 to be silenced by # noqa and fix the position reported by
980 W605
981
982 • Allow users to omit blank lines around one-liner definitions of
983 classes and functions
984
985 • Include the function return annotation (->) as requiring surrounding
986 whitespace only on Python 3
987
988 • Verify that only names can follow await. Previously we allowed num‐
989 bers and strings.
990
991 • Add support for Python 3.7
992
993 • Fix detection of annotated argument defaults for E252
994
995 • Correct the position reported by W504
996
997 2.4.0 (2018-04-10)
998 New checks:
999
1000 • Add W504 warning for checking that a break doesn't happen after a bi‐
1001 nary operator. This check is ignored by default. PR #502.
1002
1003 • Add W605 warning for invalid escape sequences in string literals. PR
1004 #676.
1005
1006 • Add W606 warning for 'async' and 'await' reserved keywords being in‐
1007 troduced in Python 3.7. PR #684.
1008
1009 • Add E252 error for missing whitespace around equal sign in type anno‐
1010 tated function arguments with defaults values. PR #717.
1011
1012 Changes:
1013
1014 • An internal bisect search has replaced a linear search in order to
1015 improve efficiency. PR #648.
1016
1017 • pycodestyle now uses PyPI trove classifiers in order to document sup‐
1018 ported python versions on PyPI. PR #654.
1019
1020 • 'setup.cfg' '[wheel]' section has been renamed to '[bdist_wheel]', as
1021 the former is legacy. PR #653.
1022
1023 • pycodestyle now handles very long lines much more efficiently for
1024 python 3.2+. Fixes #643. PR #644.
1025
1026 • You can now write 'pycodestyle.StyleGuide(verbose=True)' instead of
1027 'pycodestyle.StyleGuide(verbose=True, paths=['-v'])' in order to
1028 achieve verbosity. PR #663.
1029
1030 • The distribution of pycodestyle now includes the license text in or‐
1031 der to comply with open source licenses which require this. PR #694.
1032
1033 • 'maximum_line_length' now ignores shebang ('#!') lines. PR #736.
1034
1035 • Add configuration option for the allowed number of blank lines. It is
1036 implemented as a top level dictionary which can be easily overwrit‐
1037 ten. Fixes #732. PR #733.
1038
1039 Bugs:
1040
1041 • Prevent a 'DeprecationWarning', and a 'SyntaxError' in future python,
1042 caused by an invalid escape sequence. PR #625.
1043
1044 • Correctly report E501 when the first line of a docstring is too long.
1045 Resolves #622. PR #630.
1046
1047 • Support variable annotation when variable start by a keyword, such as
1048 class variable type annotations in python 3.6. PR #640.
1049
1050 • pycodestyle internals have been changed in order to allow 'python3 -m
1051 cProfile' to report correct metrics. PR #647.
1052
1053 • Fix a spelling mistake in the description of E722. PR #697.
1054
1055 • 'pycodestyle --diff' now does not break if your 'gitconfig' enables
1056 'mnemonicprefix'. PR #706.
1057
1058 2.3.1 (2017-01-31)
1059 Bugs:
1060
1061 • Fix regression in detection of E302 and E306; #618, #620
1062
1063 2.3.0 (2017-01-30)
1064 New Checks:
1065
1066 • Add E722 warning for bare except clauses
1067
1068 • Report E704 for async function definitions (async def)
1069
1070 Bugs:
1071
1072 • Fix another E305 false positive for variables beginning with "class"
1073 or "def"
1074
1075 • Fix detection of multiple spaces between async and def
1076
1077 • Fix handling of variable annotations. Stop reporting E701 on Python
1078 3.6 for variable annotations.
1079
1080 2.2.0 (2016-11-14)
1081 Announcements:
1082
1083 • Added Make target to obtain proper tarball file permissions; #599
1084
1085 Bugs:
1086
1087 • Fixed E305 regression caused by #400; #593
1088
1089 2.1.0 (2016-11-04)
1090 Announcements:
1091
1092 • Change all references to the pep8 project to say pycodestyle; #530
1093
1094 Changes:
1095
1096 • Report E302 for blank lines before an "async def"; #556
1097
1098 • Update our list of tested and supported Python versions which are
1099 2.6, 2.7, 3.2, 3.3, 3.4 and 3.5 as well as the nightly Python build
1100 and PyPy.
1101
1102 • Report E742 and E743 for functions and classes badly named 'l', 'O',
1103 or 'I'.
1104
1105 • Report E741 on 'global' and 'nonlocal' statements, as well as prohib‐
1106 ited single-letter variables.
1107
1108 • Deprecated use of [pep8] section name in favor of [pycodestyle]; #591
1109
1110 • Report E722 when bare except clause is used; #579
1111
1112 Bugs:
1113
1114 • Fix opt_type AssertionError when using Flake8 2.6.2 and pycodestyle;
1115 #561
1116
1117 • Require two blank lines after toplevel def, class; #536
1118
1119 • Remove accidentally quadratic computation based on the number of
1120 colons. This will make pycodestyle faster in some cases; #314
1121
1122 2.0.0 (2016-05-31)
1123 Announcements:
1124
1125 • Repository renamed to pycodestyle; Issue #466 / #481.
1126
1127 • Added joint Code of Conduct as member of PyCQA; #483
1128
1129 Changes:
1130
1131 • Added tox test support for Python 3.5 and pypy3
1132
1133 • Added check E275 for whitespace on from ... import ... lines; #489 /
1134 #491
1135
1136 • Added W503 to the list of codes ignored by default ignore list; #498
1137
1138 • Removed use of project level .pep8 configuration file; #364
1139
1140 Bugs:
1141
1142 • Fixed bug with treating ~ operator as binary; #383 / #384
1143
1144 • Identify binary operators as unary; #484 / #485
1145
1146 1.7.0 (2016-01-12)
1147 Announcements:
1148
1149 • Repository moved to PyCQA Organization on GitHub:
1150 https://github.com/pycqa/pep8
1151
1152 Changes:
1153
1154 • Reverted the fix in #368, "options passed on command line are only
1155 ones accepted" feature. This has many unintended consequences in pep8
1156 and flake8 and needs to be reworked when I have more time.
1157
1158 • Added support for Python 3.5. (Issue #420 & #459)
1159
1160 • Added support for multi-line config_file option parsing. (Issue #429)
1161
1162 • Improved parameter parsing. (Issues #420 & #456)
1163
1164 Bugs:
1165
1166 • Fixed BytesWarning on Python 3. (Issue #459)
1167
1168 1.6.2 (2015-02-15)
1169 Changes:
1170
1171 • Added check for breaking around a binary operator. (Issue #197, Pull
1172 #305)
1173
1174 Bugs:
1175
1176 • Restored config_file parameter in process_options(). (Issue #380)
1177
1178 1.6.1 (2015-02-08)
1179 Changes:
1180
1181 • Assign variables before referenced. (Issue #287)
1182
1183 Bugs:
1184
1185 • Exception thrown due to unassigned local_dir variable. (Issue #377)
1186
1187 1.6.0 (2015-02-06)
1188 News:
1189
1190 • Ian Lee <ianlee1521@gmail.com> joined the project as a maintainer.
1191
1192 Changes:
1193
1194 • Report E731 for lambda assignment. (Issue #277)
1195
1196 • Report E704 for one-liner def instead of E701. Do not report this
1197 error in the default configuration. (Issue #277)
1198
1199 • Replace codes E111, E112 and E113 with codes E114, E115 and E116 for
1200 bad indentation of comments. (Issue #274)
1201
1202 • Report E266 instead of E265 when the block comment starts with multi‐
1203 ple #. (Issue #270)
1204
1205 • Report E402 for import statements not at the top of the file. (Issue
1206 #264)
1207
1208 • Do not enforce whitespaces around ** operator. (Issue #292)
1209
1210 • Strip whitespace from around paths during normalization. (Issue #339
1211 / #343)
1212
1213 • Update --format documentation. (Issue #198 / Pull Request #310)
1214
1215 • Add .tox/ to default excludes. (Issue #335)
1216
1217 • Do not report E121 or E126 in the default configuration. (Issues #256
1218 / #316)
1219
1220 • Allow spaces around the equals sign in an annotated function. (Issue
1221 #357)
1222
1223 • Allow trailing backslash if in an inline comment. (Issue #374)
1224
1225 • If --config is used, only that configuration is processed. Otherwise,
1226 merge the user and local configurations are merged. (Issue #368 /
1227 #369)
1228
1229 Bug fixes:
1230
1231 • Don't crash if Checker.build_tokens_line() returns None. (Issue #306)
1232
1233 • Don't crash if os.path.expanduser() throws an ImportError. (Issue
1234 #297)
1235
1236 • Missing space around keyword parameter equal not always reported,
1237 E251. (Issue #323)
1238
1239 • Fix false positive E711/E712/E713. (Issues #330 and #336)
1240
1241 • Do not skip physical checks if the newline is escaped. (Issue #319)
1242
1243 • Flush sys.stdout to avoid race conditions with printing. See flake8
1244 bug: https://gitlab.com/pycqa/flake8/issues/17 for more details. (Is‐
1245 sue #363)
1246
1247 1.5.7 (2014-05-29)
1248 Bug fixes:
1249
1250 • Skip the traceback on "Broken pipe" signal. (Issue #275)
1251
1252 • Do not exit when an option in setup.cfg or tox.ini is not recognized.
1253
1254 • Check the last line even if it does not end with a newline. (Issue
1255 #286)
1256
1257 • Always open files in universal newlines mode in Python 2. (Issue
1258 #288)
1259
1260 1.5.6 (2014-04-14)
1261 Bug fixes:
1262
1263 • Check the last line even if it has no end-of-line. (Issue #273)
1264
1265 1.5.5 (2014-04-10)
1266 Bug fixes:
1267
1268 • Fix regression with E22 checks and inline comments. (Issue #271)
1269
1270 1.5.4 (2014-04-07)
1271 Bug fixes:
1272
1273 • Fix negative offset with E303 before a multi-line docstring. (Issue
1274 #269)
1275
1276 1.5.3 (2014-04-04)
1277 Bug fixes:
1278
1279 • Fix wrong offset computation when error is on the last char of a
1280 physical line. (Issue #268)
1281
1282 1.5.2 (2014-04-04)
1283 Changes:
1284
1285 • Distribute a universal wheel file.
1286
1287 Bug fixes:
1288
1289 • Report correct line number for E303 with comments. (Issue #60)
1290
1291 • Do not allow newline after parameter equal. (Issue #252)
1292
1293 • Fix line number reported for multi-line strings. (Issue #220)
1294
1295 • Fix false positive E121/E126 with multi-line strings. (Issue #265)
1296
1297 • Fix E501 not detected in comments with Python 2.5.
1298
1299 • Fix caret position with --show-source when line contains tabs.
1300
1301 1.5.1 (2014-03-27)
1302 Bug fixes:
1303
1304 • Fix a crash with E125 on multi-line strings. (Issue #263)
1305
1306 1.5 (2014-03-26)
1307 Changes:
1308
1309 • Report E129 instead of E125 for visually indented line with same in‐
1310 dent as next logical line. (Issue #126)
1311
1312 • Report E265 for space before block comment. (Issue #190)
1313
1314 • Report E713 and E714 when operators not in and is not are recom‐
1315 mended. (Issue #236)
1316
1317 • Allow long lines in multiline strings and comments if they cannot be
1318 wrapped. (Issue #224).
1319
1320 • Optionally disable physical line checks inside multiline strings, us‐
1321 ing # noqa. (Issue #242)
1322
1323 • Change text for E121 to report "continuation line under-indented for
1324 hanging indent" instead of indentation not being a multiple of 4.
1325
1326 • Report E131 instead of E121 / E126 if the hanging indent is not con‐
1327 sistent within the same continuation block. It helps when error E121
1328 or E126 is in the ignore list.
1329
1330 • Report E126 instead of E121 when the continuation line is hanging
1331 with extra indentation, even if indentation is not a multiple of 4.
1332
1333 Bug fixes:
1334
1335 • Allow the checkers to report errors on empty files. (Issue #240)
1336
1337 • Fix ignoring too many checks when --select is used with codes de‐
1338 clared in a flake8 extension. (Issue #216)
1339
1340 • Fix regression with multiple brackets. (Issue #214)
1341
1342 • Fix StyleGuide to parse the local configuration if the keyword argu‐
1343 ment paths is specified. (Issue #246)
1344
1345 • Fix a false positive E124 for hanging indent. (Issue #254)
1346
1347 • Fix a false positive E126 with embedded colon. (Issue #144)
1348
1349 • Fix a false positive E126 when indenting with tabs. (Issue #204)
1350
1351 • Fix behaviour when exclude is in the configuration file and the cur‐
1352 rent directory is not the project directory. (Issue #247)
1353
1354 • The logical checks can return None instead of an empty iterator.
1355 (Issue #250)
1356
1357 • Do not report multiple E101 if only the first indentation starts with
1358 a tab. (Issue #237)
1359
1360 • Fix a rare false positive W602. (Issue #34)
1361
1362 1.4.6 (2013-07-02)
1363 Changes:
1364
1365 • Honor # noqa for errors E711 and E712. (Issue #180)
1366
1367 • When both a tox.ini and a setup.cfg are present in the project direc‐
1368 tory, merge their contents. The tox.ini file takes precedence (same
1369 as before). (Issue #182)
1370
1371 • Give priority to --select over --ignore. (Issue #188)
1372
1373 • Compare full path when excluding a file. (Issue #186)
1374
1375 • New option --hang-closing to switch to the alternative style of clos‐
1376 ing bracket indentation for hanging indent. Add error E133 for clos‐
1377 ing bracket which is missing indentation. (Issue #103)
1378
1379 • Accept both styles of closing bracket indentation for hanging indent.
1380 Do not report error E123 in the default configuration. (Issue #103)
1381
1382 Bug fixes:
1383
1384 • Do not crash when running AST checks and the document contains null
1385 bytes. (Issue #184)
1386
1387 • Correctly report other E12 errors when E123 is ignored. (Issue #103)
1388
1389 • Fix false positive E261/E262 when the file contains a BOM. (Issue
1390 #193)
1391
1392 • Fix E701, E702 and E703 not detected sometimes. (Issue #196)
1393
1394 • Fix E122 not detected in some cases. (Issue #201 and #208)
1395
1396 • Fix false positive E121 with multiple brackets. (Issue #203)
1397
1398 1.4.5 (2013-03-06)
1399 • When no path is specified, do not try to read from stdin. The fea‐
1400 ture was added in 1.4.3, but it is not supported on Windows. Use -
1401 filename argument to read from stdin. This usage is supported since
1402 1.3.4. (Issue #170)
1403
1404 • Do not require setuptools in setup.py. It works around an issue with
1405 pip and Python 3. (Issue #172)
1406
1407 • Add __pycache__ to the ignore list.
1408
1409 • Change misleading message for E251. (Issue #171)
1410
1411 • Do not report false E302 when the source file has a coding cookie or
1412 a comment on the first line. (Issue #174)
1413
1414 • Reorganize the tests and add tests for the API and for the command
1415 line usage and options. (Issues #161 and #162)
1416
1417 • Ignore all checks which are not explicitly selected when select is
1418 passed to the StyleGuide constructor.
1419
1420 1.4.4 (2013-02-24)
1421 • Report E227 or E228 instead of E225 for whitespace around bitwise,
1422 shift or modulo operators. (Issue #166)
1423
1424 • Change the message for E226 to make clear that it is about arithmetic
1425 operators.
1426
1427 • Fix a false positive E128 for continuation line indentation with
1428 tabs.
1429
1430 • Fix regression with the --diff option. (Issue #169)
1431
1432 • Fix the TestReport class to print the unexpected warnings and errors.
1433
1434 1.4.3 (2013-02-22)
1435 • Hide the --doctest and --testsuite options when installed.
1436
1437 • Fix crash with AST checkers when the syntax is invalid. (Issue #160)
1438
1439 • Read from standard input if no path is specified.
1440
1441 • Initiate a graceful shutdown on Control+C.
1442
1443 • Allow changing the checker_class for the StyleGuide.
1444
1445 1.4.2 (2013-02-10)
1446 • Support AST checkers provided by third-party applications.
1447
1448 • Register new checkers with register_check(func_or_cls, codes).
1449
1450 • Allow constructing a StyleGuide with a custom parser.
1451
1452 • Accept visual indentation without parenthesis after the if statement.
1453 (Issue #151)
1454
1455 • Fix UnboundLocalError when using # noqa with continued lines. (Issue
1456 #158)
1457
1458 • Re-order the lines for the StandardReport.
1459
1460 • Expand tabs when checking E12 continuation lines. (Issue #155)
1461
1462 • Refactor the testing class TestReport and the specific test functions
1463 into a separate test module.
1464
1465 1.4.1 (2013-01-18)
1466 • Allow sphinx.ext.autodoc syntax for comments. (Issue #110)
1467
1468 • Report E703 instead of E702 for the trailing semicolon. (Issue #117)
1469
1470 • Honor # noqa in addition to # nopep8. (Issue #149)
1471
1472 • Expose the OptionParser factory for better extensibility.
1473
1474 1.4 (2012-12-22)
1475 • Report E226 instead of E225 for optional whitespace around common op‐
1476 erators (*, **, /, + and -). This new error code is ignored in the
1477 default configuration because PEP 8 recommends to "use your own
1478 judgement". (Issue #96)
1479
1480 • Lines with a # nopep8 at the end will not issue errors on line length
1481 E501 or continuation line indentation E12*. (Issue #27)
1482
1483 • Fix AssertionError when the source file contains an invalid line end‐
1484 ing "\r\r\n". (Issue #119)
1485
1486 • Read the [pep8] section of tox.ini or setup.cfg if present. (Issue
1487 #93 and #141)
1488
1489 • Add the Sphinx-based documentation, and publish it on
1490 https://pycodestyle.readthedocs.io/. (Issue #105)
1491
1492 1.3.4 (2012-12-18)
1493 • Fix false positive E124 and E128 with comments. (Issue #100)
1494
1495 • Fix error on stdin when running with bpython. (Issue #101)
1496
1497 • Fix false positive E401. (Issue #104)
1498
1499 • Report E231 for nested dictionary in list. (Issue #142)
1500
1501 • Catch E271 at the beginning of the line. (Issue #133)
1502
1503 • Fix false positive E126 for multi-line comments. (Issue #138)
1504
1505 • Fix false positive E221 when operator is preceded by a comma. (Issue
1506 #135)
1507
1508 • Fix --diff failing on one-line hunk. (Issue #137)
1509
1510 • Fix the --exclude switch for directory paths. (Issue #111)
1511
1512 • Use - filename to read from standard input. (Issue #128)
1513
1514 1.3.3 (2012-06-27)
1515 • Fix regression with continuation line checker. (Issue #98)
1516
1517 1.3.2 (2012-06-26)
1518 • Revert to the previous behaviour for --show-pep8: do not imply
1519 --first. (Issue #89)
1520
1521 • Add E902 for IO errors. (Issue #87)
1522
1523 • Fix false positive for E121, and missed E124. (Issue #92)
1524
1525 • Set a sensible default path for config file on Windows. (Issue #95)
1526
1527 • Allow verbose in the configuration file. (Issue #91)
1528
1529 • Show the enforced max-line-length in the error message. (Issue #86)
1530
1531 1.3.1 (2012-06-18)
1532 • Explain which configuration options are expected. Accept and recom‐
1533 mend the options names with hyphen instead of underscore. (Issue #82)
1534
1535 • Do not read the user configuration when used as a module (except if
1536 config_file=True is passed to the StyleGuide constructor).
1537
1538 • Fix wrong or missing cases for the E12 series.
1539
1540 • Fix cases where E122 was missed. (Issue #81)
1541
1542 1.3 (2012-06-15)
1543 WARNING:
1544 The internal API is backwards incompatible.
1545
1546 • Remove global configuration and refactor the library around a
1547 StyleGuide class; add the ability to configure various reporters.
1548 (Issue #35 and #66)
1549
1550 • Read user configuration from ~/.config/pep8 and local configuration
1551 from ./.pep8. (Issue #22)
1552
1553 • Fix E502 for backslash embedded in multi-line string. (Issue #68)
1554
1555 • Fix E225 for Python 3 iterable unpacking (PEP 3132). (Issue #72)
1556
1557 • Enable the new checkers from the E12 series in the default configura‐
1558 tion.
1559
1560 • Suggest less error-prone alternatives for E712 errors.
1561
1562 • Rewrite checkers to run faster (E22, E251, E27).
1563
1564 • Fixed a crash when parsed code is invalid (too many closing brack‐
1565 ets).
1566
1567 • Fix E127 and E128 for continuation line indentation. (Issue #74)
1568
1569 • New option --format to customize the error format. (Issue #23)
1570
1571 • New option --diff to check only modified code. The unified diff is
1572 read from STDIN. Example: hg diff | pep8 --diff (Issue #39)
1573
1574 • Correctly report the count of failures and set the exit code to 1
1575 when the --doctest or the --testsuite fails.
1576
1577 • Correctly detect the encoding in Python 3. (Issue #69)
1578
1579 • Drop support for Python 2.3, 2.4 and 3.0. (Issue #78)
1580
1581 1.2 (2012-06-01)
1582 • Add E121 through E128 for continuation line indentation. These
1583 checks are disabled by default. If you want to force all checks, use
1584 switch --select=E,W. Patch by Sam Vilain. (Issue #64)
1585
1586 • Add E721 for direct type comparisons. (Issue #47)
1587
1588 • Add E711 and E712 for comparisons to singletons. (Issue #46)
1589
1590 • Fix spurious E225 and E701 for function annotations. (Issue #29)
1591
1592 • Add E502 for explicit line join between brackets.
1593
1594 • Fix E901 when printing source with --show-source.
1595
1596 • Report all errors for each checker, instead of reporting only the
1597 first occurrence for each line.
1598
1599 • Option --show-pep8 implies --first.
1600
1601 1.1 (2012-05-24)
1602 • Add E901 for syntax errors. (Issues #63 and #30)
1603
1604 • Add E271, E272, E273 and E274 for extraneous whitespace around key‐
1605 words. (Issue #57)
1606
1607 • Add tox.ini configuration file for tests. (Issue #61)
1608
1609 • Add .travis.yml configuration file for continuous integration. (Is‐
1610 sue #62)
1611
1612 1.0.1 (2012-04-06)
1613 • Fix inconsistent version numbers.
1614
1615 1.0 (2012-04-04)
1616 • Fix W602 raise to handle multi-char names. (Issue #53)
1617
1618 0.7.0 (2012-03-26)
1619 • Now --first prints only the first occurrence of each error. The
1620 --repeat flag becomes obsolete because it is the default behaviour.
1621 (Issue #6)
1622
1623 • Allow specifying --max-line-length. (Issue #36)
1624
1625 • Make the shebang more flexible. (Issue #26)
1626
1627 • Add testsuite to the bundle. (Issue #25)
1628
1629 • Fixes for Jython. (Issue #49)
1630
1631 • Add PyPI classifiers. (Issue #43)
1632
1633 • Fix the --exclude option. (Issue #48)
1634
1635 • Fix W602, accept raise with 3 arguments. (Issue #34)
1636
1637 • Correctly select all tests if DEFAULT_IGNORE == ''.
1638
1639 0.6.1 (2010-10-03)
1640 • Fix inconsistent version numbers. (Issue #21)
1641
1642 0.6.0 (2010-09-19)
1643 • Test suite reorganized and enhanced in order to check more failures
1644 with fewer test files. Read the run_tests docstring for details
1645 about the syntax.
1646
1647 • Fix E225: accept print >>sys.stderr, "..." syntax.
1648
1649 • Fix E501 for lines containing multibyte encoded characters. (Issue
1650 #7)
1651
1652 • Fix E221, E222, E223, E224 not detected in some cases. (Issue #16)
1653
1654 • Fix E211 to reject v = dic['a'] ['b']. (Issue #17)
1655
1656 • Exit code is always 1 if any error or warning is found. (Issue #10)
1657
1658 • --ignore checks are now really ignored, especially in conjunction
1659 with --count. (Issue #8)
1660
1661 • Blank lines with spaces yield W293 instead of W291: some developers
1662 want to ignore this warning and indent the blank lines to paste their
1663 code easily in the Python interpreter.
1664
1665 • Fix E301: do not require a blank line before an indented block. (Is‐
1666 sue #14)
1667
1668 • Fix E203 to accept NumPy slice notation a[0, :]. (Issue #13)
1669
1670 • Performance improvements.
1671
1672 • Fix decoding and checking non-UTF8 files in Python 3.
1673
1674 • Fix E225: reject True+False when running on Python 3.
1675
1676 • Fix an exception when the line starts with an operator.
1677
1678 • Allow a new line before closing ), } or ]. (Issue #5)
1679
1680 0.5.0 (2010-02-17)
1681 • Changed the --count switch to print to sys.stderr and set exit code
1682 to 1 if any error or warning is found.
1683
1684 • E241 and E242 are removed from the standard checks. If you want to
1685 include these checks, use switch --select=E,W. (Issue #4)
1686
1687 • Blank line is not mandatory before the first class method or nested
1688 function definition, even if there's a docstring. (Issue #1)
1689
1690 • Add the switch --version.
1691
1692 • Fix decoding errors with Python 3. (Issue #13 [1])
1693
1694 • Add --select option which is mirror of --ignore.
1695
1696 • Add checks E261 and E262 for spaces before inline comments.
1697
1698 • New check W604 warns about deprecated usage of backticks.
1699
1700 • New check W603 warns about the deprecated operator <>.
1701
1702 • Performance improvement, due to rewriting of E225.
1703
1704 • E225 now accepts:
1705
1706 • no whitespace after unary operator or similar. (Issue #9 [1])
1707
1708 • lambda function with argument unpacking or keyword defaults.
1709
1710 • Reserve "2 blank lines" for module-level logical blocks. (E303)
1711
1712 • Allow multi-line comments. (E302, issue #10 [1])
1713
1714 0.4.2 (2009-10-22)
1715 • Decorators on classes and class methods are OK now.
1716
1717 0.4 (2009-10-20)
1718 • Support for all versions of Python from 2.3 to 3.1.
1719
1720 • New and greatly expanded self tests.
1721
1722 • Added --count option to print the total number of errors and warn‐
1723 ings.
1724
1725 • Further improvements to the handling of comments and blank lines.
1726 (Issue #1 [1] and others changes.)
1727
1728 • Check all py files in directory when passed a directory (Issue #2
1729 [1]). This also prevents an exception when traversing directories
1730 with non *.py files.
1731
1732 • E231 should allow commas to be followed by ). (Issue #3 [1])
1733
1734 • Spaces are no longer required around the equals sign for keyword ar‐
1735 guments or default parameter values.
1736
1737 [1] These issues refer to the previous issue tracker.
1738
1739 0.3.1 (2009-09-14)
1740 • Fixes for comments: do not count them when checking for blank lines
1741 between items.
1742
1743 • Added setup.py for pypi upload and easy_installability.
1744
1745 0.2 (2007-10-16)
1746 • Loads of fixes and improvements.
1747
1748 0.1 (2006-10-01)
1749 • First release.
1750
1751 • Online documentation: https://pycodestyle.readthedocs.io/
1752
1753 • Source code and issue tracker: https://github.com/pycqa/pycodestyle
1754
1755 • genindex
1756
1757 • search
1758
1759 Created by Johann C. Rocholl.
1760
1761 Maintained by Florent Xicluna and Ian Lee.
1762
1763 The pycodestyle library is provided under the terms and conditions of
1764 the Expat license:
1765
1766 # Permission is hereby granted, free of charge, to any person
1767 # obtaining a copy of this software and associated documentation files
1768 # (the "Software"), to deal in the Software without restriction,
1769 # including without limitation the rights to use, copy, modify, merge,
1770 # publish, distribute, sublicense, and/or sell copies of the Software,
1771 # and to permit persons to whom the Software is furnished to do so,
1772 # subject to the following conditions:
1773 #
1774 # The above copyright notice and this permission notice shall be
1775 # included in all copies or substantial portions of the Software.
1776 #
1777 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1778 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1779 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1780 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1781 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1782 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1783 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1784 # SOFTWARE.
1785
1787 Johann C. Rocholl, Florent Xicluna, Ian Lee
1788
1790 2006-2021, Johann C. Rocholl, Florent Xicluna, Ian Lee
1791
1792
1793
1794
17952.6 Feb 18, 2021 PYCODESTYLE(1)