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