1PYCODESTYLE(1)                    pycodestyle                   PYCODESTYLE(1)
2
3
4

NAME

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

INTRODUCTION

16       pycodestyle is a tool to check your Python code  against  some  of  the
17       style conventions in PEP 8.
18
19Features
20
21Disclaimer
22
23Installation
24
25Example usage and output
26
27Configuration
28
29Error codes
30
31Related 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
58naming  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
62docstring conventions: they are not in the scope of this library; see
63         the pydocstyle project.
64
65automatic 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
133path     │ File name     │
134                             ├─────────┼───────────────┤
135row      │ Row number    │
136                             ├─────────┼───────────────┤
137col      │ Column number │
138                             ├─────────┼───────────────┤
139code     │ Error code    │
140                             ├─────────┼───────────────┤
141text     │ 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            --indent-size=n      set how many spaces make up an indent (default: 4)
170            --hang-closing       hang closing bracket instead of matching indentation of
171                                 opening bracket's line
172            --format=format      set the error format [default|pylint|<custom>]
173            --diff               report only lines changed according to the unified diff
174                                 received on STDIN
175
176            Testing Options:
177              --benchmark        measure processing speed
178
179            Configuration:
180              The project options are read from the [pycodestyle] section of the
181              tox.ini file or the setup.cfg file located in any parent folder of the
182              path(s) being processed.  Allowed options are: exclude, filename,
183              select, ignore, max-line-length, max-doc-length, hang-closing, count,
184              format, quiet, show-pep8, show-source, statistics, verbose.
185
186              --config=path      user config file location
187              (default: ~/.config/pycodestyle)
188
189   Configuration
190       The  behaviour  may  be  configured at two levels, the user and project
191       levels.
192
193       At the user level, settings are read from the following locations:
194
195       If on Windows:
196              ~\.pycodestyle
197
198       Otherwise, if the XDG_CONFIG_HOME environment variable is defined:
199              XDG_CONFIG_HOME/pycodestyle
200
201       Else if XDG_CONFIG_HOME is not defined:
202              ~/.config/pycodestyle
203
204       Example:
205
206          [pycodestyle]
207          count = False
208          ignore = E226,E302,E41
209          max-line-length = 160
210          statistics = True
211
212       At the project level, a setup.cfg file or a tox.ini  file  is  read  if
213       present.  If  none  of  these  files  have  a [pycodestyle] section, no
214       project specific configuration is loaded.
215
216   Error codes
217       This is the current list of error and warning codes:
218
219                      ┌──────────┬────────────────────────────┐
220                      │code      │ sample message             │
221                      ├──────────┼────────────────────────────┤
222E1        Indentation
223                      ├──────────┼────────────────────────────┤
224                      │E101      │ indentation contains mixed │
225                      │          │ spaces and tabs            │
226                      ├──────────┼────────────────────────────┤
227                      │E111      │ indentation  is not a mul‐ │
228                      │          │ tiple of four              │
229                      ├──────────┼────────────────────────────┤
230                      │E112      │ expected an indented block │
231                      ├──────────┼────────────────────────────┤
232                      │E113      │ unexpected indentation     │
233                      ├──────────┼────────────────────────────┤
234                      │E114      │ indentation is not a  mul‐ │
235                      │          │ tiple of four (comment)    │
236                      ├──────────┼────────────────────────────┤
237                      │E115      │ expected an indented block │
238                      │          │ (comment)                  │
239                      ├──────────┼────────────────────────────┤
240                      │E116      │ unexpected     indentation │
241                      │          │ (comment)                  │
242                      ├──────────┼────────────────────────────┤
243                      │E117      │ over-indented              │
244                      ├──────────┼────────────────────────────┤
245                      │E121 (*^) │ continuation    line   un‐ │
246                      │          │ der-indented  for  hanging │
247                      │          │ indent                     │
248                      ├──────────┼────────────────────────────┤
249                      │E122 (^)  │ continuation  line missing │
250                      │          │ indentation or outdented   │
251                      ├──────────┼────────────────────────────┤
252                      │E123 (*)  │ closing bracket  does  not │
253                      │          │ match indentation of open‐ │
254                      │          │ ing bracket's line         │
255                      ├──────────┼────────────────────────────┤
256                      │E124 (^)  │ closing bracket  does  not │
257                      │          │ match visual indentation   │
258                      ├──────────┼────────────────────────────┤
259                      │E125 (^)  │ continuation   line   with │
260                      │          │ same indent as next  logi‐ │
261                      │          │ cal line                   │
262                      ├──────────┼────────────────────────────┤
263                      │E126 (*^) │ continuation line over-in‐ │
264                      │          │ dented for hanging indent  │
265                      └──────────┴────────────────────────────┘
266
267
268
269                      │E127 (^)  │ continuation line over-in‐ │
270                      │          │ dented for visual indent   │
271                      ├──────────┼────────────────────────────┤
272                      │E128 (^)  │ continuation    line   un‐ │
273                      │          │ der-indented  for   visual │
274                      │          │ indent                     │
275                      ├──────────┼────────────────────────────┤
276                      │E129 (^)  │ visually   indented   line │
277                      │          │ with same indent  as  next │
278                      │          │ logical line               │
279                      ├──────────┼────────────────────────────┤
280                      │E131 (^)  │ continuation    line   un‐ │
281                      │          │ aligned for hanging indent │
282                      ├──────────┼────────────────────────────┤
283                      │E133 (*)  │ closing bracket is missing │
284                      │          │ indentation                │
285                      ├──────────┼────────────────────────────┤
286                      │          │                            │
287                      ├──────────┼────────────────────────────┤
288E2        Whitespace
289                      ├──────────┼────────────────────────────┤
290                      │E201      │ whitespace after '('       │
291                      ├──────────┼────────────────────────────┤
292                      │E202      │ whitespace before ')'      │
293                      ├──────────┼────────────────────────────┤
294                      │E203      │ whitespace   before   ',', │
295                      │          │ ';', or ':'                │
296                      ├──────────┼────────────────────────────┤
297                      │          │                            │
298                      ├──────────┼────────────────────────────┤
299                      │E211      │ whitespace before '('      │
300                      ├──────────┼────────────────────────────┤
301                      │          │                            │
302                      ├──────────┼────────────────────────────┤
303                      │E221      │ multiple spaces before op‐ │
304                      │          │ erator                     │
305                      ├──────────┼────────────────────────────┤
306                      │E222      │ multiple  spaces after op‐ │
307                      │          │ erator                     │
308                      ├──────────┼────────────────────────────┤
309                      │E223      │ tab before operator        │
310                      ├──────────┼────────────────────────────┤
311                      │E224      │ tab after operator         │
312                      ├──────────┼────────────────────────────┤
313                      │E225      │ missing whitespace  around │
314                      │          │ operator                   │
315                      ├──────────┼────────────────────────────┤
316                      │E226 (*)  │ missing  whitespace around │
317                      │          │ arithmetic operator        │
318                      ├──────────┼────────────────────────────┤
319                      │E227      │ missing whitespace  around │
320                      │          │ bitwise or shift operator  │
321                      ├──────────┼────────────────────────────┤
322                      │E228      │ missing  whitespace around │
323                      │          │ modulo operator            │
324                      ├──────────┼────────────────────────────┤
325                      │          │                            │
326                      ├──────────┼────────────────────────────┤
327                      │E231      │ missing  whitespace  after │
328                      │          │ ',', ';', or ':'           │
329                      ├──────────┼────────────────────────────┤
330                      │          │                            │
331                      ├──────────┼────────────────────────────┤
332                      │E241 (*)  │ multiple spaces after ','  │
333                      ├──────────┼────────────────────────────┤
334                      │E242 (*)  │ tab after ','              │
335                      └──────────┴────────────────────────────┘
336
337                      │          │                            │
338                      ├──────────┼────────────────────────────┤
339                      │E251      │ unexpected  spaces  around │
340                      │          │ keyword / parameter equals │
341                      ├──────────┼────────────────────────────┤
342                      │          │                            │
343                      ├──────────┼────────────────────────────┤
344                      │E261      │ at least two spaces before │
345                      │          │ inline comment             │
346                      ├──────────┼────────────────────────────┤
347                      │E262      │ inline    comment   should │
348                      │          │ start with '# '            │
349                      ├──────────┼────────────────────────────┤
350                      │E265      │ block comment should start │
351                      │          │ with '# '                  │
352                      ├──────────┼────────────────────────────┤
353                      │E266      │ too  many  leading '#' for │
354                      │          │ block comment              │
355                      ├──────────┼────────────────────────────┤
356                      │          │                            │
357                      ├──────────┼────────────────────────────┤
358                      │E271      │ multiple spaces after key‐ │
359                      │          │ word                       │
360                      ├──────────┼────────────────────────────┤
361                      │E272      │ multiple   spaces   before │
362                      │          │ keyword                    │
363                      ├──────────┼────────────────────────────┤
364                      │E273      │ tab after keyword          │
365                      ├──────────┼────────────────────────────┤
366                      │E274      │ tab before keyword         │
367                      ├──────────┼────────────────────────────┤
368                      │E275      │ missing  whitespace  after │
369                      │          │ keyword                    │
370                      ├──────────┼────────────────────────────┤
371                      │          │                            │
372                      ├──────────┼────────────────────────────┤
373E3        Blank line
374                      ├──────────┼────────────────────────────┤
375                      │E301      │ expected   1  blank  line, │
376                      │          │ found 0                    │
377                      ├──────────┼────────────────────────────┤
378                      │E302      │ expected  2  blank  lines, │
379                      │          │ found 0                    │
380                      ├──────────┼────────────────────────────┤
381                      │E303      │ too many blank lines (3)   │
382                      ├──────────┼────────────────────────────┤
383                      │E304      │ blank  lines  found  after │
384                      │          │ function decorator         │
385                      ├──────────┼────────────────────────────┤
386                      │E305      │ expected 2 blank lines af‐ │
387                      │          │ ter  end  of  function  or │
388                      │          │ class                      │
389                      ├──────────┼────────────────────────────┤
390                      │E306      │ expected 1 blank line  be‐ │
391                      │          │ fore a nested definition   │
392                      ├──────────┼────────────────────────────┤
393                      │          │                            │
394                      ├──────────┼────────────────────────────┤
395E4        Import
396                      ├──────────┼────────────────────────────┤
397                      │E401      │ multiple  imports  on  one │
398                      │          │ line                       │
399                      ├──────────┼────────────────────────────┤
400                      │E402      │ module level import not at │
401                      │          │ top of file                │
402                      └──────────┴────────────────────────────┘
403
404
405                      │          │                            │
406                      ├──────────┼────────────────────────────┤
407E5        Line length
408                      ├──────────┼────────────────────────────┤
409                      │E501 (^)  │ line  too  long  (82  > 79 │
410                      │          │ characters)                │
411                      ├──────────┼────────────────────────────┤
412                      │E502      │ the backslash is redundant │
413                      │          │ between brackets           │
414                      ├──────────┼────────────────────────────┤
415                      │          │                            │
416                      ├──────────┼────────────────────────────┤
417E7        Statement
418                      ├──────────┼────────────────────────────┤
419                      │E701      │ multiple statements on one │
420                      │          │ line (colon)               │
421                      ├──────────┼────────────────────────────┤
422                      │E702      │ multiple statements on one │
423                      │          │ line (semicolon)           │
424                      ├──────────┼────────────────────────────┤
425                      │E703      │ statement   ends   with  a │
426                      │          │ semicolon                  │
427                      ├──────────┼────────────────────────────┤
428                      │E704 (*)  │ multiple statements on one │
429                      │          │ line (def)                 │
430                      ├──────────┼────────────────────────────┤
431                      │E711 (^)  │ comparison  to None should │
432                      │          │ be 'if cond is None:'      │
433                      ├──────────┼────────────────────────────┤
434                      │E712 (^)  │ comparison to True  should │
435                      │          │ be  'if  cond is True:' or │
436                      │          │ 'if cond:'                 │
437                      ├──────────┼────────────────────────────┤
438                      │E713      │ test for membership should │
439                      │          │ be 'not in'                │
440                      ├──────────┼────────────────────────────┤
441                      │E714      │ test  for  object identity │
442                      │          │ should be 'is not'         │
443                      ├──────────┼────────────────────────────┤
444                      │E721 (^)  │ do not compare types,  use │
445                      │          │ 'isinstance()'             │
446                      ├──────────┼────────────────────────────┤
447                      │E722      │ do  not  use  bare except, │
448                      │          │ specify exception instead  │
449                      ├──────────┼────────────────────────────┤
450                      │E731      │ do not assign a lambda ex‐ │
451                      │          │ pression, use a def        │
452                      ├──────────┼────────────────────────────┤
453                      │E741      │ do not use variables named │
454                      │          │ 'l', 'O', or 'I'           │
455                      ├──────────┼────────────────────────────┤
456                      │E742      │ do  not   define   classes │
457                      │          │ named 'l', 'O', or 'I'     │
458                      ├──────────┼────────────────────────────┤
459                      │E743      │ do  not  define  functions │
460                      │          │ named 'l', 'O', or 'I'     │
461                      ├──────────┼────────────────────────────┤
462                      │          │                            │
463                      ├──────────┼────────────────────────────┤
464E9        Runtime
465                      ├──────────┼────────────────────────────┤
466                      │E901      │ SyntaxError  or   Indenta‐ │
467                      │          │ tionError                  │
468                      ├──────────┼────────────────────────────┤
469                      │E902      │ IOError                    │
470                      └──────────┴────────────────────────────┘
471
472
473                      │          │                            │
474                      ├──────────┼────────────────────────────┤
475W1        Indentation warning
476                      ├──────────┼────────────────────────────┤
477                      │W191      │ indentation contains tabs  │
478                      ├──────────┼────────────────────────────┤
479                      │          │                            │
480                      ├──────────┼────────────────────────────┤
481W2        Whitespace warning
482                      ├──────────┼────────────────────────────┤
483                      │W291      │ trailing whitespace        │
484                      ├──────────┼────────────────────────────┤
485                      │W292      │ no newline at end of file  │
486                      ├──────────┼────────────────────────────┤
487                      │W293      │ blank line contains white‐ │
488                      │          │ space                      │
489                      ├──────────┼────────────────────────────┤
490                      │          │                            │
491                      ├──────────┼────────────────────────────┤
492W3        Blank line warning
493                      ├──────────┼────────────────────────────┤
494                      │W391      │ blank line at end of file  │
495                      ├──────────┼────────────────────────────┤
496                      │          │                            │
497                      ├──────────┼────────────────────────────┤
498W5        Line break warning
499                      ├──────────┼────────────────────────────┤
500                      │W503 (*)  │ line break  before  binary │
501                      │          │ operator                   │
502                      ├──────────┼────────────────────────────┤
503                      │W504 (*)  │ line  break  after  binary │
504                      │          │ operator                   │
505                      ├──────────┼────────────────────────────┤
506                      │W505 (*^) │ doc line too long (82 > 79 │
507                      │          │ characters)                │
508                      ├──────────┼────────────────────────────┤
509                      │          │                            │
510                      ├──────────┼────────────────────────────┤
511W6        Deprecation warning
512                      ├──────────┼────────────────────────────┤
513                      │W601      │ .has_key()  is deprecated, │
514                      │          │ use 'in'                   │
515                      ├──────────┼────────────────────────────┤
516                      │W602      │ deprecated form of raising │
517                      │          │ exception                  │
518                      ├──────────┼────────────────────────────┤
519                      │W603      │ '<>'  is  deprecated,  use │
520                      │          │ '!='                       │
521                      ├──────────┼────────────────────────────┤
522                      │W604      │ backticks are  deprecated, │
523                      │          │ use 'repr()'               │
524                      ├──────────┼────────────────────────────┤
525                      │W605      │ invalid   escape  sequence │
526                      │          │ 'x'                        │
527                      ├──────────┼────────────────────────────┤
528                      │W606      │ 'async'  and  'await'  are │
529                      │          │ reserved keywords starting │
530                      │          │ with Python 3.7            │
531                      └──────────┴────────────────────────────┘
532
533       (*) In the default configuration, the checks E121,  E123,  E126,  E133,
534       E226,  E241,  E242,  E704, W503, W504 and W505 are ignored because they
535       are not rules unanimously accepted, and PEP 8 does  not  enforce  them.
536       Please  note  that  if  the option --ignore=errors is used, the default
537       configuration will be overridden and ignore only the check(s) you skip.
538       The  check  W503 is mutually exclusive with check W504.  The check E133
539       is mutually exclusive with check E123.  Use  switch  --hang-closing  to
540       report  E133  instead  of E123. Use switch --max-doc-length=n to report
541       W505.
542
543       (^) These checks can be disabled at the line level  using  the  #  noqa
544       special  comment.   This  possibility  should  be  reserved for special
545       cases.
546          Special cases aren't special enough to break the rules.
547
548       Note: most errors can be listed with such one-liner:
549
550          $ python pycodestyle.py --first --select E,W testsuite/ --format '%(code)s: %(text)s'
551
552   Related tools
553       The flake8 checker is a wrapper around pycodestyle and  similar  tools.
554       It supports plugins.
555
556       Other  tools  which use pycodestyle are referenced in the Wiki: list of
557       related tools.
558

ADVANCED USAGE

560   Automated tests
561       You can also execute pycodestyle tests from Python code.  For  example,
562       this can be highly useful for automated testing of coding style confor‐
563       mance in your project:
564
565          import unittest
566          import pycodestyle
567
568
569          class TestCodeFormat(unittest.TestCase):
570
571              def test_conformance(self):
572                  """Test that we conform to PEP-8."""
573                  style = pycodestyle.StyleGuide(quiet=True)
574                  result = style.check_files(['file1.py', 'file2.py'])
575                  self.assertEqual(result.total_errors, 0,
576                                   "Found code style errors (and warnings).")
577
578       There's also a shortcut for checking a single file:
579
580          import pycodestyle
581
582          fchecker = pycodestyle.Checker('testsuite/E27.py', show_source=True)
583          file_errors = fchecker.check_all()
584
585          print("Found %s errors (and warnings)" % file_errors)
586
587   Configuring tests
588       You can configure automated pycodestyle tests in a variety of ways.
589
590       For example, you can pass in a path to a configuration  file  that  py‐
591       codestyle should use:
592
593          import pycodestyle
594
595          style = pycodestyle.StyleGuide(config_file='/path/to/tox.ini')
596
597       You can also set specific options explicitly:
598
599          style = pycodestyle.StyleGuide(ignore=['E501'])
600
601   Skip file header
602       Another  example  is related to the feature request #143: skip a number
603       of lines at the beginning and the end of a file.  This use case is easy
604       to implement through a custom wrapper for the PEP 8 library:
605
606          #!python
607          import pycodestyle
608
609          LINES_SLICE = slice(14, -20)
610
611          class StyleGuide(pycodestyle.StyleGuide):
612              """This subclass of pycodestyle.StyleGuide will skip the first and last lines
613              of each file."""
614
615              def input_file(self, filename, lines=None, expected=None, line_offset=0):
616                  if lines is None:
617                      assert line_offset == 0
618                      line_offset = LINES_SLICE.start or 0
619                      lines = pycodestyle.readlines(filename)[LINES_SLICE]
620                  return super(StyleGuide, self).input_file(
621                      filename, lines=lines, expected=expected, line_offset=line_offset)
622
623          if __name__ == '__main__':
624              style = StyleGuide(parse_argv=True, config_file=True)
625              report = style.check_files()
626              if report.total_errors:
627                  raise SystemExit(1)
628
629       This module declares a lines' window which skips 14 lines at the begin‐
630       ning and 20 lines at the end.  If there's no line to skip at  the  end,
631       it could be changed with LINES_SLICE = slice(14, None) for example.
632
633       You can save it in a file and use it with the same options as the orig‐
634       inal pycodestyle.
635

PYCODESTYLE API

637       The library provides classes which are usable by third party tools.
638
639Checker Classes
640
641Report Classes
642
643Utilities
644
645   Checker Classes
646       The StyleGuide class is used to configure a  style  guide  checker  in‐
647       stance to check multiple files.
648
649       The Checker class can be used to check a single file.
650
651       class     pycodestyle.StyleGuide(parse_argv=False,    config_file=None,
652       parser=None, paths=None, report=None, **kwargs)
653              Initialize a PEP-8 instance with few options.
654
655              init_report(reporter=None)
656                     Initialize the report instance.
657
658              check_files(paths=None)
659                     Run all checks on the paths.
660
661              input_file(filename, lines=None, expected=None, line_offset=0)
662                     Run all checks on a Python source file.
663
664              input_dir(dirname)
665                     Check all files in this directory and all subdirectories.
666
667              excluded(filename, parent=None)
668                     Check if the file should be excluded.
669
670                     Check if 'options.exclude' contains  a  pattern  matching
671                     filename.
672
673              ignore_code(code)
674                     Check if the error code should be ignored.
675
676                     If  'options.select' contains a prefix of the error code,
677                     return False.  Else, if 'options.ignore' contains a  pre‐
678                     fix of the error code, return True.
679
680              get_checks(argument_name)
681                     Get all the checks for this category.
682
683                     Find all globally visible functions where the first argu‐
684                     ment name starts with argument_name and which contain se‐
685                     lected tests.
686
687       class   pycodestyle.Checker(filename=None,   lines=None,   report=None,
688       **kwargs)
689              Load a Python source file, tokenize it, check coding style.
690
691              readline()
692                     Get the next line from the input buffer.
693
694              run_check(check, argument_names)
695                     Run a check plugin.
696
697              check_physical(line)
698                     Run all physical checks on a raw input line.
699
700              build_tokens_line()
701                     Build a logical line from tokens.
702
703              check_logical()
704                     Build a line from tokens and run all  logical  checks  on
705                     it.
706
707              check_ast()
708                     Build the file's AST and run all AST checks.
709
710              generate_tokens()
711                     Tokenize file, run physical line checks and yield tokens.
712
713              check_all(expected=None, line_offset=0)
714                     Run all checks on the input file.
715
716   Report Classes
717       class pycodestyle.BaseReport(options)
718              Collect the results of the checks.
719
720              start()
721                     Start the timer.
722
723              stop() Stop the timer.
724
725              init_file(filename, lines, expected, line_offset)
726                     Signal a new file.
727
728              increment_logical_line()
729                     Signal a new logical line.
730
731              error(line_number, offset, text, check)
732                     Report an error, according to options.
733
734              get_file_results()
735                     Return the count of errors and warnings for this file.
736
737              get_count(prefix='')
738                     Return the total count of errors and warnings.
739
740              get_statistics(prefix='')
741                     Get statistics for message codes that start with the pre‐
742                     fix.
743
744                     prefix='' matches  all  errors  and  warnings  prefix='E'
745                     matches  all  errors prefix='W' matches all warnings pre‐
746                     fix='E4' matches all errors that have to do with imports
747
748              print_statistics(prefix='')
749                     Print overall statistics (number of errors and warnings).
750
751              print_benchmark()
752                     Print benchmark numbers.
753
754       class pycodestyle.FileReport(options)
755              Collect the results of the checks and print the filenames.
756
757       class pycodestyle.StandardReport(options)
758              Collect and print the results of the checks.
759
760       class pycodestyle.DiffReport(options)
761              Collect and print the results for the changed lines only.
762
763   Utilities
764       pycodestyle.expand_indent(line)
765              Return the amount of indentation.
766
767              Tabs are expanded to the next multiple of 8.
768
769              >>> expand_indent('    ')
770              4
771              >>> expand_indent('\t')
772              8
773              >>> expand_indent('       \t')
774              8
775              >>> expand_indent('        \t')
776              16
777
778       pycodestyle.mute_string(text)
779              Replace contents with 'xxx' to prevent syntax matching.
780
781              >>> mute_string('"abc"')
782              '"xxx"'
783              >>> mute_string("'''abc'''")
784              "'''xxx'''"
785              >>> mute_string("r'abc'")
786              "r'xxx'"
787
788       pycodestyle.read_config(options, args, arglist, parser)
789              Read and parse configurations.
790
791              If a config file is specified  on  the  command  line  with  the
792              "--config" option, then only it is used for configuration.
793
794              Otherwise,  the  user  configuration (~/.config/pycodestyle) and
795              any local configurations in the current directory or above  will
796              be merged together (in that order) using the read method of Con‐
797              figParser.
798
799       pycodestyle.process_options(arglist=None,    parse_argv=False,     con‐
800       fig_file=None)
801              Process options passed either via arglist or command line args.
802
803              Passing in the config_file parameter allows other tools, such as
804              flake8 to specify their own  options  to  be  processed  in  py‐
805              codestyle.
806
807       pycodestyle.register_check(func_or_cls, codes=None)
808              Register a new check object.
809

DEVELOPER'S NOTES

811   Source code
812       The  source  code  is currently available on GitHub under the terms and
813       conditions of the Expat license.  Fork away!
814
815Source code and issue tracker on GitHub.
816
817Continuous tests against Python 2.7 and 3.5+ as well as  the  nightly
818         Python build and PyPy, on GitHub Actions.
819
820   Direction
821       Some high-level aims and directions to bear in mind for contributions:
822
823pycodestyle  is  intended  to  be as fast as possible.  Using the ast
824         module defeats that purpose.  The pep8-naming plugin exists for  this
825         sort of functionality.
826
827       • If  you  want to provide extensibility / plugins, please see flake8 -
828         pycodestyle doesn't want or need a plugin architecture.
829
830pycodestyle aims to have no external dependencies.
831
832   Contribute
833       You can add checks to this program by writing plugins.  Each plugin  is
834       a  simple  function that is called for each line of source code, either
835       physical or logical.
836
837       Physical line:
838
839       • Raw line of text from the input file.
840
841       Logical line:
842
843       • Multi-line statements converted to a single line.
844
845       • Stripped left and right.
846
847       • Contents of strings replaced with "xxx" of same length.
848
849       • Comments removed.
850
851       The check function requests physical or logical lines by  the  name  of
852       the first argument:
853
854          def maximum_line_length(physical_line)
855          def extraneous_whitespace(logical_line)
856          def blank_lines(logical_line, blank_lines, indent_level, line_number)
857
858       The last example above demonstrates how check plugins can request addi‐
859       tional information with extra arguments.  All attributes of the Checker
860       object are available.  Some examples:
861
862lines: a list of the raw lines from the input file
863
864tokens: the tokens that contribute to this logical line
865
866line_number: line number in the input file
867
868total_lines: number of lines in the input file
869
870blank_lines: blank lines before this one
871
872indent_char: indentation character in this file (" " or "\t")
873
874indent_level: indentation (with tabs expanded to multiples of 8)
875
876previous_indent_level: indentation on previous line
877
878previous_logical: previous logical line
879
880       Check  plugins  can also maintain per-file state. If you need this, de‐
881       clare a parameter named checker_state. You will be passed a dict, which
882       will be the same one for all lines in the same file but a different one
883       for different files. Each check plugin gets its own dict, so you  don't
884       need to worry about clobbering the state of other plugins.
885
886       The docstring of each check function shall be the relevant part of text
887       from PEP 8.  It is printed if the user  enables  --show-pep8.   Several
888       docstrings contain examples directly from the PEP 8 document.
889
890          Okay: spam(ham[1], {eggs: 2})
891          E201: spam( ham[1], {eggs: 2})
892
893       These  examples  are  verified automatically when pycodestyle.py is run
894       with the --doctest option.  You can add examples  for  your  own  check
895       functions.  The format is simple: "Okay" or error/warning code followed
896       by colon and space, the rest of the line is example  source  code.   If
897       you put 'r' before the docstring, you can use \n for newline and \t for
898       tab.
899
900       Then be sure to pass the tests:
901
902          $ python pycodestyle.py --testsuite testsuite
903          $ python pycodestyle.py --doctest
904          $ python pycodestyle.py --verbose pycodestyle.py
905
906       When contributing to pycodestyle, please observe our Code of Conduct.
907
908       To run the tests, the core developer team and GitHub Actions use tox:
909
910          $ pip install -r dev-requirements.txt
911          $ tox
912
913       All the tests should pass for all available interpreters, with the sum‐
914       mary of:
915
916          congratulations :)
917
918   Changes
919   2.9.1 (2022-08-03)
920       Changes:
921
922       • E275: fix false positive for yield expressions.
923
924   2.9.0 (2022-07-30)
925       Changes:
926
927       • E221, E222, E223, E224: add support for := operator.  PR #1032.
928
929       • Drop python 2.7 / 3.5.
930
931       • E262: consider non-breaking spaces (\xa0) as whitespace.  PR #1035.
932
933       • Improve performance of _is_binary_operator.  PR #1052.
934
935       • E275: requires whitespace around keywords.  PR #1063.
936
937       • Add support for python 3.11. PR #1070.
938
939   2.8.0 (2021-10-10)
940       Changes:
941
942       • Drop python 3.4.  PR #982.
943
944       • E712: fix false negative with multiple comparisons.  PR #987.
945
946       • E211: fix false positives with match.  PR #989.
947
948       • E772: improve performance of bare except check.  PR #992.
949
950       • Backport tokenize performance improvement from python 3.10.  PR #993.
951
952       • E225: fix for lambdas containing positional-only args.  PR #1012.
953
954       • Remove indent_size_str "setting".  PR #995.
955
956       • E402: allow __all__ to be typed.  PR #1019.
957
958       • E225: fix false positives for * in case.  PR #1003.
959
960       • E201: detect tabs as whitespace.  PR #1015.
961
962   2.7.0 (2021-03-14)
963       Changes:
964
965       • Fix physical checks (such as W191) at end of file.  PR #961.
966
967       • Add --indent-size option (defaulting to 4).  PR #970.
968
969       • W605: fix escaped crlf false positive on windows.  PR #976.
970
971   2.6.0 (2020-05-11)
972       Announcements:
973
974       • Anthony  Sottile  (@asottile)  joined  the  team as a core developer.
975         :tada:
976
977       Changes:
978
979       • E306: fix detection inside async def.  PR #929.
980
981       • E301: fix regression disallowing decorated one-liners.  PR #927.
982
983       • E714: fix false positive with chained is not.  PR #931.
984
985   2.6.0a1 (2020-04-23)
986       New checks:
987
988       • E225: require whitespace around and in is and or.  PR #847.
989
990       Changes:
991
992       • E117: fix indentation using tabs by treating as 8-space indents.   PR
993         #837.
994
995       • E721: fix false positive with names containg istype.  PR #850.
996
997       • E741: allow l as a named argument in a function call.  PR #853.
998
999       • E302: fix false-negative with decorated functions.  PR #859.
1000
1001       • W504:  ellipsis  (...) is no longer treated as a binary operator.  PR
1002         #875.
1003
1004       • E402: allow with, if, elif, else to guard imports.  PR #834.
1005
1006       • Add support for assignment expressions := (PEP 572).  PR #879.
1007
1008       • Add support for positional-only arguments  /  (PEP  570).   PR  #872,
1009         #918.
1010
1011       • Add support for python 3.8.
1012
1013       • Add support for matrix multiplication operator @ (PEP 465).  PR #897.
1014
1015       • Support  visual  indent  for  continuation  lines for with / assert /
1016         raise.  PR #912.
1017
1018       • E302: allow two blank lines after a block of one-liners.  PR #913.
1019
1020       • E302: allow two-and-fewer newlines at the top of the file.  PR #919.
1021
1022   2.5.0 (2019-01-29)
1023       New checks:
1024
1025       • E117: Over-indented code blocks
1026
1027       • W505:  Maximum  doc-string   length   only   when   configured   with
1028         --max-doc-length
1029
1030       Changes:
1031
1032       • Remove support for EOL Python 2.6 and 3.3. PR #720.
1033
1034       • Add E117 error for over-indented code blocks.
1035
1036       • Allow  W605 to be silenced by # noqa and fix the position reported by
1037         W605
1038
1039       • Allow users to omit  blank  lines  around  one-liner  definitions  of
1040         classes and functions
1041
1042       • Include  the function return annotation (->) as requiring surrounding
1043         whitespace only on Python 3
1044
1045       • Verify that only names can follow await. Previously we  allowed  num‐
1046         bers and strings.
1047
1048       • Add support for Python 3.7
1049
1050       • Fix detection of annotated argument defaults for E252
1051
1052       • Correct the position reported by W504
1053
1054   2.4.0 (2018-04-10)
1055       New checks:
1056
1057       • Add W504 warning for checking that a break doesn't happen after a bi‐
1058         nary operator. This check is ignored by default. PR #502.
1059
1060       • Add W605 warning for invalid escape sequences in string literals.  PR
1061         #676.
1062
1063       • Add  W606 warning for 'async' and 'await' reserved keywords being in‐
1064         troduced in Python 3.7. PR #684.
1065
1066       • Add E252 error for missing whitespace around equal sign in type anno‐
1067         tated function arguments with defaults values. PR #717.
1068
1069       Changes:
1070
1071       • An  internal  bisect  search has replaced a linear search in order to
1072         improve efficiency. PR #648.
1073
1074       • pycodestyle now uses PyPI trove classifiers in order to document sup‐
1075         ported python versions on PyPI. PR #654.
1076
1077       • 'setup.cfg' '[wheel]' section has been renamed to '[bdist_wheel]', as
1078         the former is legacy. PR #653.
1079
1080       • pycodestyle now handles very long lines  much  more  efficiently  for
1081         python 3.2+. Fixes #643. PR #644.
1082
1083       • You  can  now write 'pycodestyle.StyleGuide(verbose=True)' instead of
1084         'pycodestyle.StyleGuide(verbose=True,  paths=['-v'])'  in  order   to
1085         achieve verbosity. PR #663.
1086
1087       • The  distribution of pycodestyle now includes the license text in or‐
1088         der to comply with open source licenses which require this. PR #694.
1089
1090       • 'maximum_line_length' now ignores shebang ('#!') lines. PR #736.
1091
1092       • Add configuration option for the allowed number of blank lines. It is
1093         implemented  as  a top level dictionary which can be easily overwrit‐
1094         ten. Fixes #732. PR #733.
1095
1096       Bugs:
1097
1098       • Prevent a 'DeprecationWarning', and a 'SyntaxError' in future python,
1099         caused by an invalid escape sequence. PR #625.
1100
1101       • Correctly report E501 when the first line of a docstring is too long.
1102         Resolves #622. PR #630.
1103
1104       • Support variable annotation when variable start by a keyword, such as
1105         class variable type annotations in python 3.6. PR #640.
1106
1107       • pycodestyle internals have been changed in order to allow 'python3 -m
1108         cProfile' to report correct metrics. PR #647.
1109
1110       • Fix a spelling mistake in the description of E722. PR #697.
1111
1112       • 'pycodestyle --diff' now does not break if your  'gitconfig'  enables
1113         'mnemonicprefix'. PR #706.
1114
1115   2.3.1 (2017-01-31)
1116       Bugs:
1117
1118       • Fix regression in detection of E302 and E306; #618, #620
1119
1120   2.3.0 (2017-01-30)
1121       New Checks:
1122
1123       • Add E722 warning for bare except clauses
1124
1125       • Report E704 for async function definitions (async def)
1126
1127       Bugs:
1128
1129       • Fix  another E305 false positive for variables beginning with "class"
1130         or "def"
1131
1132       • Fix detection of multiple spaces between async and def
1133
1134       • Fix handling of variable annotations. Stop reporting E701  on  Python
1135         3.6 for variable annotations.
1136
1137   2.2.0 (2016-11-14)
1138       Announcements:
1139
1140       • Added Make target to obtain proper tarball file permissions; #599
1141
1142       Bugs:
1143
1144       • Fixed E305 regression caused by #400; #593
1145
1146   2.1.0 (2016-11-04)
1147       Announcements:
1148
1149       • Change all references to the pep8 project to say pycodestyle; #530
1150
1151       Changes:
1152
1153       • Report E302 for blank lines before an "async def"; #556
1154
1155       • Update  our  list  of  tested and supported Python versions which are
1156         2.6, 2.7, 3.2, 3.3, 3.4 and 3.5 as well as the nightly  Python  build
1157         and PyPy.
1158
1159       • Report  E742 and E743 for functions and classes badly named 'l', 'O',
1160         or 'I'.
1161
1162       • Report E741 on 'global' and 'nonlocal' statements, as well as prohib‐
1163         ited single-letter variables.
1164
1165       • Deprecated use of [pep8] section name in favor of [pycodestyle]; #591
1166
1167       • Report E722 when bare except clause is used; #579
1168
1169       Bugs:
1170
1171       • Fix  opt_type AssertionError when using Flake8 2.6.2 and pycodestyle;
1172         #561
1173
1174       • Require two blank lines after toplevel def, class; #536
1175
1176       • Remove accidentally quadratic computation  based  on  the  number  of
1177         colons. This will make pycodestyle faster in some cases; #314
1178
1179   2.0.0 (2016-05-31)
1180       Announcements:
1181
1182       • Repository renamed to pycodestyle; Issue #466 / #481.
1183
1184       • Added joint Code of Conduct as member of PyCQA; #483
1185
1186       Changes:
1187
1188       • Added tox test support for Python 3.5 and pypy3
1189
1190       • Added  check E275 for whitespace on from ... import ... lines; #489 /
1191         #491
1192
1193       • Added W503 to the list of codes ignored by default ignore list; #498
1194
1195       • Removed use of project level .pep8 configuration file; #364
1196
1197       Bugs:
1198
1199       • Fixed bug with treating ~ operator as binary; #383 / #384
1200
1201       • Identify binary operators as unary; #484 / #485
1202
1203   1.7.0 (2016-01-12)
1204       Announcements:
1205
1206       • Repository    moved    to    PyCQA    Organization     on     GitHub:
1207         https://github.com/pycqa/pep8
1208
1209       Changes:
1210
1211       • Reverted  the  fix  in #368, "options passed on command line are only
1212         ones accepted" feature. This has many unintended consequences in pep8
1213         and flake8 and needs to be reworked when I have more time.
1214
1215       • Added support for Python 3.5. (Issue #420 & #459)
1216
1217       • Added support for multi-line config_file option parsing. (Issue #429)
1218
1219       • Improved parameter parsing. (Issues #420 & #456)
1220
1221       Bugs:
1222
1223       • Fixed BytesWarning on Python 3. (Issue #459)
1224
1225   1.6.2 (2015-02-15)
1226       Changes:
1227
1228       • Added  check for breaking around a binary operator. (Issue #197, Pull
1229         #305)
1230
1231       Bugs:
1232
1233       • Restored config_file parameter in process_options(). (Issue #380)
1234
1235   1.6.1 (2015-02-08)
1236       Changes:
1237
1238       • Assign variables before referenced. (Issue #287)
1239
1240       Bugs:
1241
1242       • Exception thrown due to unassigned local_dir variable. (Issue #377)
1243
1244   1.6.0 (2015-02-06)
1245       News:
1246
1247       • Ian Lee <ianlee1521@gmail.com> joined the project as a maintainer.
1248
1249       Changes:
1250
1251       • Report E731 for lambda assignment. (Issue #277)
1252
1253       • Report E704 for one-liner def instead of E701.  Do  not  report  this
1254         error in the default configuration. (Issue #277)
1255
1256       • Replace  codes E111, E112 and E113 with codes E114, E115 and E116 for
1257         bad indentation of comments. (Issue #274)
1258
1259       • Report E266 instead of E265 when the block comment starts with multi‐
1260         ple #. (Issue #270)
1261
1262       • Report  E402 for import statements not at the top of the file. (Issue
1263         #264)
1264
1265       • Do not enforce whitespaces around ** operator. (Issue #292)
1266
1267       • Strip whitespace from around paths during normalization. (Issue  #339
1268         / #343)
1269
1270       • Update --format documentation. (Issue #198 / Pull Request #310)
1271
1272       • Add .tox/ to default excludes. (Issue #335)
1273
1274       • Do not report E121 or E126 in the default configuration. (Issues #256
1275         / #316)
1276
1277       • Allow spaces around the equals sign in an annotated function.  (Issue
1278         #357)
1279
1280       • Allow trailing backslash if in an inline comment. (Issue #374)
1281
1282       • If --config is used, only that configuration is processed. Otherwise,
1283         merge the user and local configurations are  merged.  (Issue  #368  /
1284         #369)
1285
1286       Bug fixes:
1287
1288       • Don't crash if Checker.build_tokens_line() returns None. (Issue #306)
1289
1290       • Don't  crash  if  os.path.expanduser()  throws an ImportError. (Issue
1291         #297)
1292
1293       • Missing space around keyword parameter  equal  not  always  reported,
1294         E251.  (Issue #323)
1295
1296       • Fix false positive E711/E712/E713. (Issues #330 and #336)
1297
1298       • Do not skip physical checks if the newline is escaped. (Issue #319)
1299
1300       • Flush  sys.stdout  to avoid race conditions with printing. See flake8
1301         bug: https://gitlab.com/pycqa/flake8/issues/17 for more details. (Is‐
1302         sue #363)
1303
1304   1.5.7 (2014-05-29)
1305       Bug fixes:
1306
1307       • Skip the traceback on "Broken pipe" signal. (Issue #275)
1308
1309       • Do not exit when an option in setup.cfg or tox.ini is not recognized.
1310
1311       • Check  the  last  line even if it does not end with a newline. (Issue
1312         #286)
1313
1314       • Always open files in universal newlines  mode  in  Python  2.  (Issue
1315         #288)
1316
1317   1.5.6 (2014-04-14)
1318       Bug fixes:
1319
1320       • Check the last line even if it has no end-of-line. (Issue #273)
1321
1322   1.5.5 (2014-04-10)
1323       Bug fixes:
1324
1325       • Fix regression with E22 checks and inline comments. (Issue #271)
1326
1327   1.5.4 (2014-04-07)
1328       Bug fixes:
1329
1330       • Fix  negative offset with E303 before a multi-line docstring.  (Issue
1331         #269)
1332
1333   1.5.3 (2014-04-04)
1334       Bug fixes:
1335
1336       • Fix wrong offset computation when error is on  the  last  char  of  a
1337         physical line. (Issue #268)
1338
1339   1.5.2 (2014-04-04)
1340       Changes:
1341
1342       • Distribute a universal wheel file.
1343
1344       Bug fixes:
1345
1346       • Report correct line number for E303 with comments. (Issue #60)
1347
1348       • Do not allow newline after parameter equal. (Issue #252)
1349
1350       • Fix line number reported for multi-line strings. (Issue #220)
1351
1352       • Fix false positive E121/E126 with multi-line strings. (Issue #265)
1353
1354       • Fix E501 not detected in comments with Python 2.5.
1355
1356       • Fix caret position with --show-source when line contains tabs.
1357
1358   1.5.1 (2014-03-27)
1359       Bug fixes:
1360
1361       • Fix a crash with E125 on multi-line strings. (Issue #263)
1362
1363   1.5 (2014-03-26)
1364       Changes:
1365
1366       • Report  E129 instead of E125 for visually indented line with same in‐
1367         dent as next logical line.  (Issue #126)
1368
1369       • Report E265 for space before block comment. (Issue #190)
1370
1371       • Report E713 and E714 when operators not in  and  is  not  are  recom‐
1372         mended. (Issue #236)
1373
1374       • Allow  long lines in multiline strings and comments if they cannot be
1375         wrapped. (Issue #224).
1376
1377       • Optionally disable physical line checks inside multiline strings, us‐
1378         ing # noqa. (Issue #242)
1379
1380       • Change  text for E121 to report "continuation line under-indented for
1381         hanging indent" instead of indentation not being a multiple of 4.
1382
1383       • Report E131 instead of E121 / E126 if the hanging indent is not  con‐
1384         sistent within the same continuation block.  It helps when error E121
1385         or E126 is in the ignore list.
1386
1387       • Report E126 instead of E121 when the  continuation  line  is  hanging
1388         with extra indentation, even if indentation is not a multiple of 4.
1389
1390       Bug fixes:
1391
1392       • Allow the checkers to report errors on empty files. (Issue #240)
1393
1394       • Fix  ignoring  too  many  checks when --select is used with codes de‐
1395         clared in a flake8 extension. (Issue #216)
1396
1397       • Fix regression with multiple brackets. (Issue #214)
1398
1399       • Fix StyleGuide to parse the local configuration if the keyword  argu‐
1400         ment paths is specified. (Issue #246)
1401
1402       • Fix a false positive E124 for hanging indent. (Issue #254)
1403
1404       • Fix a false positive E126 with embedded colon. (Issue #144)
1405
1406       • Fix a false positive E126 when indenting with tabs. (Issue #204)
1407
1408       • Fix  behaviour when exclude is in the configuration file and the cur‐
1409         rent directory is not the project directory. (Issue #247)
1410
1411       • The logical checks can return None  instead  of  an  empty  iterator.
1412         (Issue #250)
1413
1414       • Do not report multiple E101 if only the first indentation starts with
1415         a tab. (Issue #237)
1416
1417       • Fix a rare false positive W602. (Issue #34)
1418
1419   1.4.6 (2013-07-02)
1420       Changes:
1421
1422       • Honor # noqa for errors E711 and E712. (Issue #180)
1423
1424       • When both a tox.ini and a setup.cfg are present in the project direc‐
1425         tory,  merge their contents.  The tox.ini file takes precedence (same
1426         as before). (Issue #182)
1427
1428       • Give priority to --select over --ignore. (Issue #188)
1429
1430       • Compare full path when excluding a file. (Issue #186)
1431
1432       • New option --hang-closing to switch to the alternative style of clos‐
1433         ing bracket indentation for hanging indent.  Add error E133 for clos‐
1434         ing bracket which is missing indentation. (Issue #103)
1435
1436       • Accept both styles of closing bracket indentation for hanging indent.
1437         Do not report error E123 in the default configuration. (Issue #103)
1438
1439       Bug fixes:
1440
1441       • Do  not  crash when running AST checks and the document contains null
1442         bytes.  (Issue #184)
1443
1444       • Correctly report other E12 errors when E123 is ignored. (Issue #103)
1445
1446       • Fix false positive E261/E262 when the file  contains  a  BOM.  (Issue
1447         #193)
1448
1449       • Fix E701, E702 and E703 not detected sometimes. (Issue #196)
1450
1451       • Fix E122 not detected in some cases. (Issue #201 and #208)
1452
1453       • Fix false positive E121 with multiple brackets. (Issue #203)
1454
1455   1.4.5 (2013-03-06)
1456       • When  no  path is specified, do not try to read from stdin.  The fea‐
1457         ture was added in 1.4.3, but it is not supported on Windows.   Use  -
1458         filename  argument to read from stdin.  This usage is supported since
1459         1.3.4. (Issue #170)
1460
1461       • Do not require setuptools in setup.py.  It works around an issue with
1462         pip and Python 3. (Issue #172)
1463
1464       • Add __pycache__ to the ignore list.
1465
1466       • Change misleading message for E251. (Issue #171)
1467
1468       • Do  not report false E302 when the source file has a coding cookie or
1469         a comment on the first line. (Issue #174)
1470
1471       • Reorganize the tests and add tests for the API and  for  the  command
1472         line usage and options. (Issues #161 and #162)
1473
1474       • Ignore  all  checks  which are not explicitly selected when select is
1475         passed to the StyleGuide constructor.
1476
1477   1.4.4 (2013-02-24)
1478       • Report E227 or E228 instead of E225 for  whitespace  around  bitwise,
1479         shift or modulo operators. (Issue #166)
1480
1481       • Change the message for E226 to make clear that it is about arithmetic
1482         operators.
1483
1484       • Fix a false positive E128  for  continuation  line  indentation  with
1485         tabs.
1486
1487       • Fix regression with the --diff option. (Issue #169)
1488
1489       • Fix the TestReport class to print the unexpected warnings and errors.
1490
1491   1.4.3 (2013-02-22)
1492       • Hide the --doctest and --testsuite options when installed.
1493
1494       • Fix crash with AST checkers when the syntax is invalid. (Issue #160)
1495
1496       • Read from standard input if no path is specified.
1497
1498       • Initiate a graceful shutdown on Control+C.
1499
1500       • Allow changing the checker_class for the StyleGuide.
1501
1502   1.4.2 (2013-02-10)
1503       • Support AST checkers provided by third-party applications.
1504
1505       • Register new checkers with register_check(func_or_cls, codes).
1506
1507       • Allow constructing a StyleGuide with a custom parser.
1508
1509       • Accept visual indentation without parenthesis after the if statement.
1510         (Issue #151)
1511
1512       • Fix UnboundLocalError when using # noqa with continued lines.  (Issue
1513         #158)
1514
1515       • Re-order the lines for the StandardReport.
1516
1517       • Expand tabs when checking E12 continuation lines. (Issue #155)
1518
1519       • Refactor the testing class TestReport and the specific test functions
1520         into a separate test module.
1521
1522   1.4.1 (2013-01-18)
1523       • Allow sphinx.ext.autodoc syntax for comments. (Issue #110)
1524
1525       • Report E703 instead of E702 for the trailing semicolon. (Issue #117)
1526
1527       • Honor # noqa in addition to # nopep8. (Issue #149)
1528
1529       • Expose the OptionParser factory for better extensibility.
1530
1531   1.4 (2012-12-22)
1532       • Report E226 instead of E225 for optional whitespace around common op‐
1533         erators  (*,  **, /, + and -).  This new error code is ignored in the
1534         default configuration because PEP  8  recommends  to  "use  your  own
1535         judgement". (Issue #96)
1536
1537       • Lines with a # nopep8 at the end will not issue errors on line length
1538         E501 or continuation line indentation E12*. (Issue #27)
1539
1540       • Fix AssertionError when the source file contains an invalid line end‐
1541         ing "\r\r\n". (Issue #119)
1542
1543       • Read  the  [pep8] section of tox.ini or setup.cfg if present.  (Issue
1544         #93 and #141)
1545
1546       • Add   the   Sphinx-based   documentation,   and   publish    it    on
1547         https://pycodestyle.readthedocs.io/. (Issue #105)
1548
1549   1.3.4 (2012-12-18)
1550       • Fix false positive E124 and E128 with comments. (Issue #100)
1551
1552       • Fix error on stdin when running with bpython. (Issue #101)
1553
1554       • Fix false positive E401. (Issue #104)
1555
1556       • Report E231 for nested dictionary in list. (Issue #142)
1557
1558       • Catch E271 at the beginning of the line. (Issue #133)
1559
1560       • Fix false positive E126 for multi-line comments. (Issue #138)
1561
1562       • Fix  false positive E221 when operator is preceded by a comma. (Issue
1563         #135)
1564
1565       • Fix --diff failing on one-line hunk. (Issue #137)
1566
1567       • Fix the --exclude switch for directory paths. (Issue #111)
1568
1569       • Use - filename to read from standard input. (Issue #128)
1570
1571   1.3.3 (2012-06-27)
1572       • Fix regression with continuation line checker. (Issue #98)
1573
1574   1.3.2 (2012-06-26)
1575       • Revert to the  previous  behaviour  for  --show-pep8:  do  not  imply
1576         --first. (Issue #89)
1577
1578       • Add E902 for IO errors. (Issue #87)
1579
1580       • Fix false positive for E121, and missed E124. (Issue #92)
1581
1582       • Set a sensible default path for config file on Windows. (Issue #95)
1583
1584       • Allow verbose in the configuration file. (Issue #91)
1585
1586       • Show the enforced max-line-length in the error message. (Issue #86)
1587
1588   1.3.1 (2012-06-18)
1589       • Explain  which configuration options are expected.  Accept and recom‐
1590         mend the options names with hyphen instead of underscore. (Issue #82)
1591
1592       • Do not read the user configuration when used as a module  (except  if
1593         config_file=True is passed to the StyleGuide constructor).
1594
1595       • Fix wrong or missing cases for the E12 series.
1596
1597       • Fix cases where E122 was missed. (Issue #81)
1598
1599   1.3 (2012-06-15)
1600       WARNING:
1601          The internal API is backwards incompatible.
1602
1603       • Remove  global  configuration  and  refactor  the  library  around  a
1604         StyleGuide class; add the ability  to  configure  various  reporters.
1605         (Issue #35 and #66)
1606
1607       • Read  user  configuration from ~/.config/pep8 and local configuration
1608         from ./.pep8. (Issue #22)
1609
1610       • Fix E502 for backslash embedded in multi-line string. (Issue #68)
1611
1612       • Fix E225 for Python 3 iterable unpacking (PEP 3132). (Issue #72)
1613
1614       • Enable the new checkers from the E12 series in the default configura‐
1615         tion.
1616
1617       • Suggest less error-prone alternatives for E712 errors.
1618
1619       • Rewrite checkers to run faster (E22, E251, E27).
1620
1621       • Fixed  a  crash  when parsed code is invalid (too many closing brack‐
1622         ets).
1623
1624       • Fix E127 and E128 for continuation line indentation. (Issue #74)
1625
1626       • New option --format to customize the error format. (Issue #23)
1627
1628       • New option --diff to check only modified code.  The unified  diff  is
1629         read from STDIN.  Example: hg diff | pep8 --diff (Issue #39)
1630
1631       • Correctly  report  the  count  of failures and set the exit code to 1
1632         when the --doctest or the --testsuite fails.
1633
1634       • Correctly detect the encoding in Python 3. (Issue #69)
1635
1636       • Drop support for Python 2.3, 2.4 and 3.0. (Issue #78)
1637
1638   1.2 (2012-06-01)
1639       • Add E121 through  E128  for  continuation  line  indentation.   These
1640         checks are disabled by default.  If you want to force all checks, use
1641         switch --select=E,W.  Patch by Sam Vilain. (Issue #64)
1642
1643       • Add E721 for direct type comparisons. (Issue #47)
1644
1645       • Add E711 and E712 for comparisons to singletons. (Issue #46)
1646
1647       • Fix spurious E225 and E701 for function annotations. (Issue #29)
1648
1649       • Add E502 for explicit line join between brackets.
1650
1651       • Fix E901 when printing source with --show-source.
1652
1653       • Report all errors for each checker, instead  of  reporting  only  the
1654         first occurrence for each line.
1655
1656       • Option --show-pep8 implies --first.
1657
1658   1.1 (2012-05-24)
1659       • Add E901 for syntax errors. (Issues #63 and #30)
1660
1661       • Add  E271,  E272, E273 and E274 for extraneous whitespace around key‐
1662         words. (Issue #57)
1663
1664       • Add tox.ini configuration file for tests. (Issue #61)
1665
1666       • Add .travis.yml configuration file for continuous integration.   (Is‐
1667         sue #62)
1668
1669   1.0.1 (2012-04-06)
1670       • Fix inconsistent version numbers.
1671
1672   1.0 (2012-04-04)
1673       • Fix W602 raise to handle multi-char names. (Issue #53)
1674
1675   0.7.0 (2012-03-26)
1676       • Now  --first  prints  only  the  first occurrence of each error.  The
1677         --repeat flag becomes obsolete because it is the  default  behaviour.
1678         (Issue #6)
1679
1680       • Allow specifying --max-line-length. (Issue #36)
1681
1682       • Make the shebang more flexible. (Issue #26)
1683
1684       • Add testsuite to the bundle. (Issue #25)
1685
1686       • Fixes for Jython. (Issue #49)
1687
1688       • Add PyPI classifiers. (Issue #43)
1689
1690       • Fix the --exclude option. (Issue #48)
1691
1692       • Fix W602, accept raise with 3 arguments. (Issue #34)
1693
1694       • Correctly select all tests if DEFAULT_IGNORE == ''.
1695
1696   0.6.1 (2010-10-03)
1697       • Fix inconsistent version numbers. (Issue #21)
1698
1699   0.6.0 (2010-09-19)
1700       • Test  suite  reorganized and enhanced in order to check more failures
1701         with fewer test files.  Read  the  run_tests  docstring  for  details
1702         about the syntax.
1703
1704       • Fix E225: accept print >>sys.stderr, "..." syntax.
1705
1706       • Fix  E501  for  lines containing multibyte encoded characters. (Issue
1707         #7)
1708
1709       • Fix E221, E222, E223, E224 not detected in some cases. (Issue #16)
1710
1711       • Fix E211 to reject v = dic['a'] ['b']. (Issue #17)
1712
1713       • Exit code is always 1 if any error or warning is found. (Issue #10)
1714
1715--ignore checks are now really  ignored,  especially  in  conjunction
1716         with --count. (Issue #8)
1717
1718       • Blank  lines  with spaces yield W293 instead of W291: some developers
1719         want to ignore this warning and indent the blank lines to paste their
1720         code easily in the Python interpreter.
1721
1722       • Fix  E301: do not require a blank line before an indented block. (Is‐
1723         sue #14)
1724
1725       • Fix E203 to accept NumPy slice notation a[0, :]. (Issue #13)
1726
1727       • Performance improvements.
1728
1729       • Fix decoding and checking non-UTF8 files in Python 3.
1730
1731       • Fix E225: reject True+False when running on Python 3.
1732
1733       • Fix an exception when the line starts with an operator.
1734
1735       • Allow a new line before closing ), } or ]. (Issue #5)
1736
1737   0.5.0 (2010-02-17)
1738       • Changed the --count switch to print to sys.stderr and set  exit  code
1739         to 1 if any error or warning is found.
1740
1741       • E241  and  E242  are removed from the standard checks. If you want to
1742         include these checks, use switch --select=E,W. (Issue #4)
1743
1744       • Blank line is not mandatory before the first class method  or  nested
1745         function definition, even if there's a docstring. (Issue #1)
1746
1747       • Add the switch --version.
1748
1749       • Fix decoding errors with Python 3. (Issue #13 [1])
1750
1751       • Add --select option which is mirror of --ignore.
1752
1753       • Add checks E261 and E262 for spaces before inline comments.
1754
1755       • New check W604 warns about deprecated usage of backticks.
1756
1757       • New check W603 warns about the deprecated operator <>.
1758
1759       • Performance improvement, due to rewriting of E225.
1760
1761       • E225 now accepts:
1762
1763         • no whitespace after unary operator or similar. (Issue #9 [1])
1764
1765         • lambda function with argument unpacking or keyword defaults.
1766
1767       • Reserve "2 blank lines" for module-level logical blocks. (E303)
1768
1769       • Allow multi-line comments. (E302, issue #10 [1])
1770
1771   0.4.2 (2009-10-22)
1772       • Decorators on classes and class methods are OK now.
1773
1774   0.4 (2009-10-20)
1775       • Support for all versions of Python from 2.3 to 3.1.
1776
1777       • New and greatly expanded self tests.
1778
1779       • Added  --count  option  to print the total number of errors and warn‐
1780         ings.
1781
1782       • Further improvements to the handling of  comments  and  blank  lines.
1783         (Issue #1 [1] and others changes.)
1784
1785       • Check  all  py  files  in directory when passed a directory (Issue #2
1786         [1]). This also prevents an  exception  when  traversing  directories
1787         with non *.py files.
1788
1789       • E231 should allow commas to be followed by ). (Issue #3 [1])
1790
1791       • Spaces  are no longer required around the equals sign for keyword ar‐
1792         guments or default parameter values.
1793
1794       [1]  These issues refer to the previous issue tracker.
1795
1796   0.3.1 (2009-09-14)
1797       • Fixes for comments: do not count them when checking for  blank  lines
1798         between items.
1799
1800       • Added setup.py for pypi upload and easy_installability.
1801
1802   0.2 (2007-10-16)
1803       • Loads of fixes and improvements.
1804
1805   0.1 (2006-10-01)
1806       • First release.
1807
1808       • Online documentation: https://pycodestyle.pycqa.org/
1809
1810       • Source code and issue tracker: https://github.com/pycqa/pycodestyle
1811
1812Index
1813
1814Search Page
1815
1816       Created by Johann C. Rocholl.
1817
1818       Maintained by Florent Xicluna and Ian Lee.
1819
1820       The  pycodestyle  library is provided under the terms and conditions of
1821       the Expat license:
1822
1823          # Permission is hereby granted, free of charge, to any person
1824          # obtaining a copy of this software and associated documentation files
1825          # (the "Software"), to deal in the Software without restriction,
1826          # including without limitation the rights to use, copy, modify, merge,
1827          # publish, distribute, sublicense, and/or sell copies of the Software,
1828          # and to permit persons to whom the Software is furnished to do so,
1829          # subject to the following conditions:
1830          #
1831          # The above copyright notice and this permission notice shall be
1832          # included in all copies or substantial portions of the Software.
1833          #
1834          # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1835          # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1836          # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1837          # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1838          # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1839          # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1840          # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1841          # SOFTWARE.
1842

AUTHOR

1844       Johann C. Rocholl, Florent Xicluna, Ian Lee
1845
1847       2006-2022, Johann C. Rocholl, Florent Xicluna, Ian Lee
1848
1849
1850
1851
18522.9                              Aug 04, 2022                   PYCODESTYLE(1)
Impressum