K ip dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZddlmZej"dkr'eee ddree j(e _dZd Zd Z ej0d k(rej2j5d ZnIej2j9ej:d xsej2j5ddZdZdZ dddZ!dZ"dZ#dddZ$dZ%e&gdZ'e&ejPdgze'z Z)e&gdZ*e&gdZ+e+jYgdZ-e&gd Z.e&d!Z/e&e j`e jbgZ1e1jYe jde jfgZ4e4jYe jje jlgZ7gd"Z8ejrd#Z:ejrd$Z;ejrd%Z<ejrd&Z=ejrd'Z>ejrd(Z?ejrd)Z@ejrd*ZAejrd+ZBejrd,d-j9e)zZCejrd.ZDejrd/ZEejrd0ZFejrd1ZGejrd2ZHejrd3ZIejrd4jd-j9d5d6DZKejrd7ZLejrd8ZMej"d9k\r%e jZNe jZOe jZPnd:xZNxZOZPej"d;k\r%e jZQe jZRe jZSnd:xZQxZRZSiiid<ZTd=ZUdd>ZVeVd?ZWeVd@ZXeVdAZYeVdBZZeVdCZ[dDZ\eVdEZ]eVdFZ^eVdGZ_eVdHZ`eVdIZaeVdJZbeVdKZceVdLZdeVdMZeeVdNZfeVdOZgeVdPZheVdQZieVdRZjeVdSZkeVdTZle&dUe&dVzZmdWZndXZoeVdYZpeVdZZqeVd[ZreVd\ZseVd]ZteVd^ZueVd_ZveVd`ZweVdaZxdbZydcZzeddejrdeejjZ}dfZ~dgZddhZejfdiZddjZdkZdlZGdmdnZGdodpZGdqdreZGdsdteZGdudveZGdwdxZdefdyZdzZ dd{Zdd|Zd}Zed~k(reyy#e$rdZYwxYw)a Check Python source code formatting, according to PEP 8. For usage and a list of options, try this: $ python pycodestyle.py -h This program and its regression test suite live here: https://github.com/pycqa/pycodestyle Groups of errors and warnings: E errors W warnings 100 indentation 200 whitespace 300 blank lines 400 imports 500 line length 600 deprecation 700 statements 900 syntax error Nfnmatch) lru_cache) OptionParser) _compilez2.14.0z'.svn,CVS,.bzr,.hg,.git,__pycache__,.toxz&E121,E123,E126,E226,E24,E704,W503,W504win32z~\.pycodestyleXDG_CONFIG_HOMEz ~/.config pycodestyle)z setup.cfgztox.iniO) top_levelmethodHz+%(path)s:%(row)d:%(col)d: %(code)s %(text)sz%%(path)s:%(row)d: [%(code)s] %(text)s)defaultpylinti)FalseNoneTrueprint)>>***+-)rr/z//rr@)^&|z<z%=z^=z&=z|===z<=z>=z<<=z>>==andinisorz->:=u  ) directoriesfiles logical linesphysical linesz([ \t]*)z\b[A-Z]\d{3}\bz u?r?["\']z[\[({][ \t]|[ \t][\]}),;:](?!=)z@\sz[,;:]\s*(?: |\t)z?(\bNone|\bFalse|\bTrue)?\s*([=!]=)\s*(?(1)|(None|False|True))\bz*\b(?%&^]+|:=)(\s*)z \blambda\bz*^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$z^(async\s+def|def)\bz%^(async\s+def|def|class|type)\s+\w+\[z#^(async\s+def\s+|def\s+|class\s+|@)z ^\s*({})\bc#@K|]}|jddyw) z\s+N)replace).0ss Q/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pycodestyle.py r8s"Q!))C"8"s)defz async defforz async forifelifelsetryexceptfinallywithz async withclasswhilez-^__([^\s]+)__(?::\s*[a-zA-Z.0-9_\[\]\"]+)? = z except\s*:)r )r) physical_line logical_linetreectj|jjDcgc]'}|j|j k(r |j )c}Scc}wN)inspect signature parametersvalueskindPOSITIONAL_OR_KEYWORDname)function parameters r7_get_parametersrUsX  *55<<> B~~!@!@@ NN BB Bs,AcBd}tj|rIt|}|r:|ddvr3|#tj |j xsd}|||d|||Stj |r(t|jddddgk(r ||d|d|S) zRegister a new check object.c|t|vr#t||dj|xsgy|xsdg|ft||<y)Nr)_checksextend)checkrPcodesargss r7 _add_checkz"register_check.._add_checksG GDM ! DM%  # * *5;B 7$)MbT4#8GDM% r)rGrHNrXrselfrI)rL isfunctionrUERRORCODE_REGEXfindall__doc__isclass__init__)r[r\r^r]s r7register_checkrgs9 % u% DG@@}'// 0CD ud1gud 3 L   5>> *2A .662B B ufeT 2 Lr_ctj|jd}t|D]\}}||k7s |dfcSy)aNever mix tabs and spaces. The most popular way of indenting Python is with spaces only. The second-most popular way is with tabs only. Code indented with a mixture of tabs and spaces should be converted to using spaces exclusively. When invoking the Python command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended! Okay: if a == 0:\n a = 1\n b = 1 rz/E101 indentation contains mixed spaces and tabsN) INDENT_REGEXmatchgroup enumerate)rG indent_charindentoffsetchars r7tabs_or_spacesrqsM   . 4 4Q 7F!&)M  ; LL LMr_cztj|jd}d|vr|jddfSy)zOn new projects, spaces-only are strongly recommended over tabs. Okay: if True:\n return W191: if True:\n\treturn r zW191 indentation contains tabsN)rirjrkindex)rGrns r7 tabs_obsoleterus@   . 4 4Q 7F v~||D!#CCCr_cr|jd}|jd}||k7r|r t|dfSyy)aTrailing whitespace is superfluous. The warning returned varies on whether the line itself is blank, for easier filtering for those who want to indent their blank lines. Okay: spam(1)\n# W291: spam(1) \n# W293: class Foo(object):\n \n bang = 12 z z zW291 trailing whitespace)rz#W293 blank line contains whitespaceNrstriplen)rGstrippeds r7trailing_whitespacer{sG"((4M##G,H x="<< <; !r_cf||k(r,|jd}|r|sy||k(rt|ddfSyy)zTrailing blank lines are superfluous. Okay: spam(1) W391: spam(1)\n However the last line should end with a new line (warning W292).  )rzW391 blank line at end of filerEzW292 no newline at end of fileNrw)rGlines line_number total_linesstripped_last_lines r7trailing_blank_linesrsLk!*11&9 !36  .uRy>#CC C / "r_cD|j}t|}||kDr|s}|dk(r|jdry|j}t|dk(r|st|dk(r)|ddk(r!t|t|dz |dz kry||kDr |d ||fzfSyyy) aLimit all lines to a maximum of 79 characters. There are still many devices around that are limited to 80 character lines; plus, limiting windows to 80 characters makes it possible to have several windows side-by-side. The default wrapping on such devices looks ugly. Therefore, please limit all lines to a maximum of 79 characters. For flowing long blocks of text (docstrings or comments), limiting the length to 72 characters is recommended. Reports error E501. r#!Nrr#rEz'E501 line too long (%d > %d characters))rxry startswithsplit)rGmax_line_length multilinernoqalinelengthchunkss r7maximum_line_lengthrs    !D YF  !  5  [A ) [A &)s"2D Cr O+o.AA  O ##&+.4o-F&GH H $)-r_ctj|sy|dz }|dkrd}nt||dz }||kDry|t|krN||j }|j dstj|rn|dz }|t|krNy|dz}|t|kr(||j rn|dz }|t|kr(yt|||kS)NFrrr T)STARTSWITH_TOP_LEVEL_REGEXrj expand_indentrystripr)rH indent_levelr~rline_idx prev_indentrnext_idxs r7 _is_one_linerr8s % + +L 9QH!| #E(Q,$78 \! SZ X$$&s#(B(H(H(N  MH SZ !|H SZ  ? "  MH SZ   x )\ 99r_c #Ktd} td} |s|| kry|jdr|rdyy|| kDs |r|| dzk(r dd|zfytj|rt ||||r|dk(ry|r|| k(s||kst j|s|} d } ||| z dd D]Y} | j st| | ks#t| } tj| j} | s| dk(sYn| r dd | d fydd j| fy|| k7r dd| |fzfyyyyy|r'|s$|| k7r|jdr dd| |fzfyyyyyw)aOSeparate top-level function and class definitions with two blank lines. Method definitions inside a class are separated by a single blank line. Extra blank lines may be used (sparingly) to separate groups of related functions. Blank lines may be omitted between a bunch of related one-liners (e.g. a set of dummy implementations). Use blank lines in functions, sparingly, to indicate logical sections. Okay: def a():\n pass\n\n\ndef b():\n pass Okay: def a():\n pass\n\n\nasync def b():\n pass Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass Okay: default = 1\nfoo = 1 Okay: classify = 1\nfoo = 1 E301: class Foo:\n b = 0\n def bar():\n pass E302: def a():\n pass\n\ndef b(n):\n pass E302: def a():\n pass\n\nasync def b(n):\n pass E303: def a():\n pass\n\n\n\ndef b(n):\n pass E303: def a():\n\n\n\n pass E304: @decorator\n\ndef a():\n pass E305: def a():\n pass\na() E306: def a():\n def b():\n pass\n def c():\n pass rrNr )rz/E304 blank lines found after function decoratorrrzE303 too many blank lines (%d)FrEzE306 expected z/ blank line before a nested definition, found 0z$E301 expected {} blank line, found 0z&E302 expected %s blank lines, found %d)zdef zclass zIE305 expected %s blank lines after class or function definition, found %d) BLANK_LINES_CONFIGrrrjrDOCSTRING_REGEXrrSTARTSWITH_DEF_REGEXlstripformat)rH blank_linesrr blank_beforeprevious_logical previous_unindented_logical_lineprevious_indent_levelr~top_level_lines method_linesancestor_levelnestedrs r7rr[sB)5O%h/L   >""3' F F   ' k\A-==1K??? # ) ), 7 , e[ I A    L0)L8#))*:;!-"+"?"C"CD"Dzz| d(;n(L)6t)<!5!;!;DKKM!J!^q%8! " 8DGGGCJJ$&&& _ ,=A/// /-%<91.  O + , 7 78J K58/// / L , sB9E&<E& 5E&A%E&c#XK|}tj|D]r}|j}|j}|j }|dj r |dzd|zfS||dz dk7s_|dvrdnd}||d|d ftt j|rd y y w) atAvoid extraneous whitespace. Avoid extraneous whitespace in these situations: - Immediately inside parentheses, brackets or braces. - Immediately before a comma, semicolon, or colon. Okay: spam(ham[1], {eggs: 2}) E201: spam( ham[1], {eggs: 2}) E201: spam(ham[ 1], {eggs: 2}) E201: spam(ham[1], { eggs: 2}) E202: spam(ham[1], {eggs: 2} ) E202: spam(ham[1 ], {eggs: 2}) E202: spam(ham[1], {eggs: 2 }) E203: if x == 4: print x, y; x, y = y , x E203: if x == 4: print x, y ; x, y = y, x E203: if x == 4 : print x, y; x, y = y, x Okay: @decorator E204: @ decorator rErzE201 whitespace after '%s',}])E202E203z whitespace before '')rz#E204 whitespace after decorator '@'N)EXTRANEOUS_WHITESPACE_REGEXfinditerrkrstartisspace WHITESPACE_AFTER_DECORATOR_REGEXrj)rHrrjtextrpfoundcodes r7extraneous_whitespacers. D,55d; >{{}zz|  8   !)9D@@ @ %!)_ #"emFDD6!5dV1== = >(--l;66++a.";; ; [1_++a."GG G 5=++a.":: : Z!^++a."FF F G BB,B,c#Kt||ddD]\}}|j|jk(s |jtj k(s>t j|js^|jtvsq|jdk(r|jdk(r|jdk(r|jdk(r|jdvs|jdfyw) zKeywords should be followed by whitespace. Okay: from foo import (bar, baz) E275: from foo import(bar, baz) E275: from importable.module import(bar, baz) E275: if(foo): bar rNr?ryield)z: z%E275 missing whitespace after keyword) zipendrtypetokenizeNAMEkeyword iskeywordstring SINGLETONS)rHtokenstok0tok1s r7 missing_whitespace_after_keywordrs&&*- D d HH " X]]*!!$++. :-[[H,1C[[G+ s0B 5(((CC C Ds./C#C#C#0C#C#"C#C#C#c#K|rdnd}|rdnd}||zrd|d|zdt|zfzf|jd}|r||krd|d|zd fzfn|s||kDrd|d|zd fzf|r|d k(rd nd } || z} || kDr d|dzfyyyw)aUse indent_size (PEP8 says 4) spaces per indentation level. For really old code that you don't want to mess up, you can continue to use 8-space tabs. Okay: a = 1 Okay: if a == 0:\n a = 1 E111: a = 1 E114: # a = 1 Okay: for item in items:\n pass E112: for item in items:\npass E115: for item in items:\n# Hi\n pass Okay: a = 1\nb = 2 E113: a = 1\n b = 2 E116: a = 1\n # b = 2 rrzE11%d %szE11%d %s (comment)rz!indentation is not a multiple of :rzexpected an indented blockzunexpected indentationrsr)rz over-indentedN)strendswith) rHrrmrr indent_sizectmpl indent_expectexpected_indent_amountexpected_indent_levels r7 indentationrs,qA%:+?Dk! E /#k2B B    %--c2M)>>Q <==== |.CCQ 89999&1T&9q 58N N / /T000 0 0sB B c #n K|ddd}d|dddz|z } |s| dk(ry|jd} dx} } |dk7r|fn||dzf} dg| z}dg| z}dgg}dg}i}|dd}d}d}|dg}|d k\r"td |dd jz|D]\}}}}}| |d|z k}|r|d|z } | xr|tv}|rJ|}|d k\rtd |jzt ||z || <|t j k(xr|d v}t|| D]}|| ||z }|| v} | sn|| r|| k(} | xrdkDxr|j|d}|r|| r|d|| k7r|dfn|r s |r|dfn|| r|d|| kr |durp|dfni s | r|| d|zk(r|r|s|df|| <nJ|dur |d|| <n=||tfvrn2dkrd}!n!|| rd}!n|s|| rd}!n||| <||kDrd}!nd}!|d|!zf|| rQ|t jt jfvr/|| s*|d|| <d||d<|d k\rtd| d|dn|t jt jtthvr t||d<nZ| s| s|dvr d||ddz<nF|s| s| s|dk(r d||ddz<n/|dk(r*||ddjr|| j!| |t j k(rQ|dvr| dz } |j!d|j!dt#|| k(r|j!g|| j!| || xxdz cc<|d k\rtd| d|dd|| n|d vr| dkDr|j%xs|d}"|j%t'| D]}#||#|"kDs d||#<t)|D] }$|$|"k\s ||$= || dzd=| dz} | rd||| <t'| ddD]}%||%s ||%xxdzcc<nt#|| dzk(sJ|d|vr|||d<|d|dk7}|s|| ||d|z <| r0t ||zk(rd|d|zf}&|rd!}'nd"}'|&d#|'zfyyyw)$a2Continuation lines indentation. Continuation lines should align wrapped elements either vertically using Python's implicit line joining inside parentheses, brackets and braces, or using a hanging indent. When using a hanging indent these considerations should be applied: - there should be no arguments on the first line, and - further indentation should be used to clearly distinguish itself as a continuation line. Okay: a = (\n) E123: a = (\n ) Okay: a = (\n 42) E121: a = (\n 42) E122: a = (\n42) E123: a = (\n 42\n ) E124: a = (24,\n 42\n) E125: if (\n b):\n pass E126: a = (\n 42) E127: a = (24,\n 42) E128: a = (24,\n 42) E129: if (a or\n b):\n pass E131: a = (\n 42\n 24) rrrrENrrsFrz>>> rz... z]})z6E124 closing bracket does not match visual indentationz+E133 closing bracket is missing indentationTz7E128 continuation line under-indented for visual indentzIE123 closing bracket does not match indentation of opening bracket's line)E122z missing indentation or outdented)E127zover-indented for visual indent)E131zunaligned for hanging indent)E126z over-indented for hanging indent)E121z!under-indented for hanging indentz%s continuation line %szbracket depth z indent to )assertraiserAr;([{z seen, col z, visual min = )]}zE129 visually indented linezE125 continuation linez(%s with same indent as next logical line)rrrxNEWLINErrOPreversedgetrNLCOMMENTSTRING FSTRING_START TSTRING_STARTrappendrypoprangelist)(rHrr hang_closingrmrrverbose first_rownrows indent_nextrowdepth valid_hangsparens rel_indent open_rowshangsindent_chances last_indent visual_indentlast_token_multilinern token_typerrrrnewline close_bracketopen_rowhanghanging_indenterrorrdindidxposrs( r7continued_indentationr 1sT:q ! QI r 1 a 9 ,E uz '',KOC%$/4$7;.;? +S5[FuJI FEN)A,KM !n F!| fvay|**,,-.4K=* D%da9,, (Y&C..L:W3LG K!|ft{{},-,D1L@JsO(8;;6H45=M%Yu%56 !#H)==!%!4!   U|"&%,"6!..:4!8:+//a9 8ve}, #011t !NNN58fUm#; , #>??K$.sOq;$F  #CDD#e $& %au 4+-19FEE]EE&5<BE#'E%Lk) J K6>>> 3K8;;0@0@"AA5M!!HF5M'+N58 $!|ug[q CD      (+N58 $Ut/J'J)-N3q6A: &Eddl)-N3q6A: & S[T#a&']224 e  # #C (  $u}  a  T"y>U*$$R(% '',s q a< %(F5M;<519$jjl1R50?R51AR5c#tK|d\}}}}}tdt|D]}||\}}} } }|tjk(rk|dvrg| |k7rb|tjk(s|dvrK|dks||dz ddk7r8t j |s#|dk(st j|s |d|zf|}|}| }y w) aAvoid extraneous whitespace. Avoid extraneous whitespace in the following situations: - before the open parenthesis that starts the argument list of a function call. - before the open parenthesis that starts an indexing or slicing. Okay: spam(1) E211: spam (1) Okay: dict['key'] = list[index] E211: dict ['key'] = list[index] E211: dict['key'] = list [index] rr([rrrBrzE211 whitespace before '%s'N)rryrrrrr issoftkeyword) rHr prev_type prev_text__prev_endrtrrrrs r7whitespace_before_parametersrs .4AY*Iy"hq#f+&+1%=( D%b (++ % DL X  (-- '9+= QY&+A.'9!!),V#)))49D@@ @  )sB6B8c#\Ktj|D]}|j\}}d|vr|jddfn#t |dkDr|jddfd|vr|jddfmt |dkDs||jddfyw) zAvoid extraneous whitespace around an operator. Okay: a = 12 + 3 E221: a = 4 + 5 E222: a = 4 + 5 E223: a = 4\t+ 5 E224: a = 4 +\t5 rsrzE223 tab before operatorz$E221 multiple spaces before operatorrzE224 tab after operatorz#E222 multiple spaces after operatorN)OPERATOR_REGEXrrrryrs r7whitespace_around_operatorr,s ((6 H   6>++a."<< < [1_++a."HH H 5=++a.";; ; Z!^++a."GG G Hrc#Kd}tj}dx}}tjtjf}g}|D]\}} } } } |tjk(r| dvr|j| n|tk(r|jdn|t k(r|jdn|tjk(r| dk(r|jdn|r|tjk(r| dvr|j nd|tk(r|j nJ|tk(r|j n0|d dk(r(|tjk(r| d k(r|j |tvr+|tjk(r`| d vr\| | d | d d z} | tvrF| d vrB| d k(r |d ddgk(rn3| d k(r |ddddgk(rn#| d k(r |ddddgk(rn| dk(r| dvrn | d| f|rs| |k7r|dur|d s |ddfd}n |dk(r| dvs |dk(r| d k(rn|dus|d r|dfn1|dk7r,d\}}|dk(rd\}}n |tvrd\}}|d|d|d fd}n||vr|| d!k(r'|d ddgk(s|d dd"gk(s|ddddgk(s |ddddgk(rng| tvrd}n\| tvrJ|tjk(r|d#vs0|tjk7r*|tvr"tj |s d}n | t"vrd}||| |k7f}n|r | |k(r|dfd}|}| }| }yw)$aZSurround operators with the correct amount of whitespace. - Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <=, >=, in, not in, is, is not), Booleans (and, or, not). - Each comma, semicolon or colon should be followed by whitespace. - If operators with different priorities are used, consider adding whitespace around the operators with the lowest priorities. Okay: i = i + 1 Okay: submitted += 1 Okay: x = x * 2 - 1 Okay: hypot2 = x * x + y * y Okay: c = (a + b) * (a - b) Okay: foo(bar, key='word', *args, **kwargs) Okay: alpha[:-i] Okay: [a, b] Okay: (3,) Okay: a[3,] = 1 Okay: a[1:4] Okay: a[:4] Okay: a[1:] Okay: a[1:4:2] E225: i=i+1 E225: submitted +=1 E225: x = x /2 - 1 E225: z = x **y E225: z = 1and 1 E226: c = (a+b) * (a-b) E226: hypot2 = x*x + y*y E227: c = a|b E228: msg = fmt%(errno, errmsg) E231: ['a','b'] E231: foo(bar,baz) E231: [{'a':'b'}] FN>([{ftlambdal>r]}rEr>rr;rr}rrr)]zE231 missing whitespace after Trz'E225 missing whitespace around operatorr>rrrrr)E226 arithmeticr$)E228modulo)E227zbitwise or shiftz missing whitespace around z operatorr(rr)rrrrrrr FSTRING_END TSTRING_END SKIP_COMMENTS WHITESPACE ARITHMETIC_OPWS_NEEDED_OPERATORSUNARY_OPERATORSKEYWORDSrrWS_OPTIONAL_OPERATORS)rHr need_spacerrroperator_types brace_stackrrrrr next_charroptypes r7missing_whitespacer9DsTJ IIkk8==1NK.4v* D%d  $)@   t $ = (   s # = (   s # 8== (TX-=   s # X[[(T_-D!{*!{*!Os*(++-CK!  &   $)@SVCFQJ/I *y/F3;;rs#3u#<S[[%5#s%CS[[%5#s%CS[Y$%6#A$!JJJ  T)*Q-%a=DFF" $)@$%A"$MMM$LD& C''7 f"-7'A f%a=37+ABB" > )h.BCK#BC(SE1#BC(SE1#BC(S#J6#BC(S#J6,,! ( + U0B,X---i8!%J..! !'(9:  1 III"   mvsL L c#K|}tj|D]\}|jdz}d|jvr|d|jdzfC|d|jdzf^yw)zAvoid extraneous whitespace after a comma or a colon. Note: these checks are disabled by default Okay: a = (1, 2) E241: a = (1, 2) E242: a = (1,\t2) rrszE242 tab after '%s'rzE241 multiple spaces after '%s'N)WHITESPACE_AFTER_COMMA_REGEXrrrk)rHrmrs r7whitespace_around_commar=s| D ) 2 24 8J A  1779 .1== =:QWWYq\II I JsA8A:c#ZKg}d}d}d}d}ttj|}ttj|}d} d} |D]\} } } }}| tj k(r|r d}| |k7r|| f|r d}| |k(r|| f| tj k(r| dvr|j| no| dvr|r|jnX| dk(r |r |dgk(rd }nHt|d k(r| d k(rd}n2|r0| d k(r+|r|d gk(s|r|dgk(rd }| |k(r|| fn d }| |k7r|| f|sd}|}yw)acDon't use spaces around the '=' sign in function arguments. Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value, except when using a type annotation. Okay: def complex(real, imag=0.0): Okay: return magic(r=real, i=imag) Okay: boolean(a == b) Okay: boolean(a != b) Okay: boolean(a <= b) Okay: boolean(a >= b) Okay: def foo(arg: int = 42): Okay: async def foo(arg: int = 42): E251: def complex(real, imag = 0.0): E251: return magic(r = real, i = imag) E252: def complex(real, image: float=0.0): FNz8E251 unexpected spaces around keyword / parameter equalsz/E252 missing whitespace around parameter equalsrr%rrTrrr(r) boolrrjSTARTSWITH_GENERIC_REGEXrrrrrry)rHr paren_stackno_space require_spacerannotated_func_argin_def in_genericmessagemissing_messagerrrrrs r7(whitespace_around_named_parameter_equalsrIs~*KHMH &,,\: ;F.44\BCJHGGO.4(* D%d  $  H )) !M 11  $t|""4(+!KC5,@%)"[!Q&43;%*" $ u(<+ u0D$(M('99#H('11%*"Q(sD)D+c#Kd}|D]\}}}}}|tjk(r|d|dj}|r|d|dk(r|d|ddzkr|df|jd\} } } | dvxr| j d ddxsd } |r| s | ddt vs|d f| s| d k7s |ddkDs| d k7r|d f| s|d f|tj k7s|}yw)uSeparate inline comments by at least two spaces. An inline comment is a comment on the same line as a statement. Inline comments should be separated by at least two spaces from the statement. They should start with a # and a single space. Each line of a block comment starts with a # and one or multiple spaces as there can be indented text inside the comment. Okay: x = x + 1 # Increment x Okay: x = x + 1 # Increment x Okay: # Block comments: Okay: # - Block comment list Okay: #  - Block comment list E261: x = x + 1 # Increment x E262: x = x + 1 #Increment x E262: x = x + 1 # Increment x E262: x = x + 1 #  Increment x E265: #Block comment E266: ### Block comment )rrNrrrz.E261 at least two spaces before inline commentr3z#:rz*E262 inline comment should start with '# '!z)E265 block comment should start with '# 'z+E266 too many leading '#' for block comment)rrr partitionrr.r) rHrrrrrrrinline_commentsymbolspcomment bad_prefixs r7whitespace_before_commentrRJs%.H.4* D%d )) )!)58_224NA;%(*uQx(1+//I#KMM"&.."5 FBt+Os1CBQ1G1N3J! !:!MMMs!2eAhl$!LLL!NNN 8;; &H%s$BC$ C$' C$5C$C$C$c#~K|}|jdr&|jd}d|krd|d|vr|dfyyyyw)a Place imports on separate lines. Okay: import os\nimport sys E401: import sys, os Okay: from subprocess import Popen, PIPE Okay: from myclas import MyClass Okay: from foo.bar.yourclass import YourClass Okay: import myclass Okay: import foo.bar.yourclass import rrEr#Nz!E401 multiple imports on one line)rfind)rHrrs r7imports_on_separate_linesrVwsR D y! # :#T&5\1<< <2:"s;=c#XKd}d}|ry|sy|ry|jdsjdr|jddrdyytjtryt fd |Dry|r|jd drd |d<yd |d <yd |d<yw) aPlace imports at the top of the file. Always put imports at the top of the file, just after any module comments and docstrings, and before module globals and constants. Okay: import os Okay: # this is a comment\nimport os Okay: '''this is a module docstring'''\nimport os Okay: r'''this is a module docstring'''\nimport os E402: a=1\nimport os E402: 'One string'\n"Two string"\nimport os E402: a=1\nfrom sys import x Okay: if x:\n import os cb|ddvr|dd}|r |ddvr|dd}|xr|ddk(xs|ddk(S)NruUbBrrR"r)rs r7is_string_literalz8module_imports_on_top_of_file..is_string_literalsQ 7f 8D DGtO8D:aC947c>:r_)r>r?r=r@rAr;r<NrTzfrom seen_non_importsF)rz+E402 module level import not at top of filec3@K|]}j|ywrKr)r5kwrs r7r8z0module_imports_on_top_of_file..s KKK  #uqy)) u y * IIcNE u* 9 KK K?? ? #uqy) u*/,s(F  FD F AF F c#Kdx}x}}d}d}|D]\}}} } } |tjk(rd}| d|k7r |r |r|s|df| d|k7rd}| d|k7rO| jdjdr%| dt | j dd z f}nd}| dx}}n| d}|tj k(s|d vr|d z }|d vs|d z}yw) aBAvoid explicit line join between brackets. The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation. E502: aaa = [123, \\n 123] E502: aaa = ("bbb " \\n "ccc") Okay: aaa = [123,\n 123] Okay: aaa = ("bbb "\n "ccc") Okay: aaa = "bbb " \\n "ccc" Okay: aaa = 123 # \\ rFNTz0E502 the backslash is redundant between bracketsr}\rErrr)rrrxrry splitlinesr) rHr prev_startrrrP backslashrrrrrs r7explicit_line_joinrzs $&'&J&FGI.4* D%d )) )G 8z !f7OO O 8z !G q6X {{6"++D1 VS):2)>%?!%CD  $'F *JqJ  $u}! ! 'sB8C;C Cz()[]{},:.;@=%~)z...cH|tjk(xs|dvxr|tvS)N>r,r))rr _SYMBOLIC_OPS)rrs r7_is_binary_operatorr}4s/hkk!    M! r_c#Kd}d}d}d}|D]O\}}}}} |tjk(rd|vsd|vr|tjk7rd};|||||||f|dv}d}|}|}Qyw)zPrivate function to reduce duplication. This factors out the shared details between :func:`break_before_binary_operator` and :func:`break_after_binary_operator`. FTN  z([{,;)rrr) r line_break unary_contextprevious_token_type previous_textrrrrrs r7_break_around_binary_operatorsr=sJMM.4 !* D%d )) )  DLDDLjHOO.KJt%8-}e5 5 GOMJ",  M !sAA c#Kt|D]2}|\}}}}}}} t||s|s|r t||r-| df4yw)a Avoid breaks before binary operators. The preferred place to break around a binary operator is after the operator, not before it. W503: (width == 0\n + height == 0) W503: (width == 0\n and height == 0) W503: var = (1\n & ~2) W503: var = (1\n / -2) W503: var = (1\n + -1\n + -2) Okay: foo(\n -x) Okay: foo(x\n []) Okay: x = '''\n''' + '' Okay: foo(x,\n -y) Okay: foo(x, # comment\n -y) z&W503 line break before binary operatorNrr}) rHrcontextrrrrrrrs r7break_before_binary_operatorrWs_(2&9B-4 +T. ]E  D 1j!'(;(57AA ABs%AAA A Ac#Kd}t|D]0}|\}}}}}} } t||r|r| st||s|df| }2yw)aF Avoid breaks after binary operators. The preferred place to break around a binary operator is before the operator, not after it. W504: (width == 0 +\n height == 0) W504: (width == 0 and\n height == 0) W504: var = (1 &\n ~2) Okay: foo(\n -x) Okay: foo(x\n []) Okay: x = '''\n''' + '' Okay: x = '' + '''\n''' Okay: foo(x,\n -y) Okay: foo(x, # comment\n -y) The following should be W504 but unary_context is tricky with these Okay: var = (1 /\n -2) Okay: var = (1 +\n -1 +\n -2) Nz%W504 line break after binary operatorr) rHrrxrrrrrrrrs r7break_after_binary_operatorruse.J1&9-4 +T. ]E  3] C!' D9EE E sAAc#\K|rytj|D]}|jdxs|jd}|jddk(}d|rdnd|zz}|d vrd }n#d }|d k(xr|xs |d k(xr| }|d|rdndzz }|jd|d|d|fyw)aXComparison to singletons should use "is" or "is not". Comparisons to singletons like None should always be done with "is" or "is not", never the equality operators. Okay: if arg is not None: E711: if arg != None: E711: if None == arg: E712: if arg == True: E712: if False == arg: Also, beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context! Nrrrr'z'if cond is %s:'rXznot )rE711E712rrz or 'if %scond:'z comparison to z should be )COMPARE_SINGLETON_REGEXrrkr)rHrrj singletonsamemsgrnonzeros r7comparison_to_singletonrs$ (11,? 7KKN4ekk!n  A$& 4RVy$HI  !DD!V+4;!W,9T  %wFC CCkk!n $i 67 7 7sB*B,c#Ktj|}|r3|jd}|jddk(r|dfy|dfyyw)aGNegative comparison should be done using "not in" and "is not". Okay: if x not in y:\n pass Okay: assert (X in Y or X is Z) Okay: if not (X in Y):\n pass Okay: zz = x is not y E713: Z = not X in Y E713: if not X.B in Y:\n pass E714: if not X is Y:\n pass E714: Z = not X.B is Y rrr*z+E713 test for membership should be 'not in'z0E714 test for object identity should be 'is not'N)COMPARE_NEGATIVE_REGEXrmrrk)rHrjr s r7comparison_negativersU # ) ), 7E kk!n ;;q>T !DD DII I  sA Ac#Ktj|}|rD|sA|jd}|r|jr |tvry|j dfyyyw)zObject type comparisons should `is` / `is not` / `isinstance()`. Do not compare types directly. Okay: if isinstance(obj, int): Okay: if type(obj) is int: E721: if type(obj) == type(1): rNzgE721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`)COMPARE_TYPE_REGEXrmrkrnrr)rHrrjinsts r7comparison_typersa  % %l 3E T{{1~ D%%'D ,B  KKM 5  usAAc#jK|rytj|}|r|jdfyyw)zWhen catching exceptions, mention specific exceptions when possible. Okay: except Exception: Okay: except BaseException: E722: except: NzE722 do not use bare 'except')BLANK_EXCEPT_REGEXrjr)rHrrjs r7 bare_exceptrs8   $ $\ 2E kkm<<< s13c#Kd}d}d}d}|d\}}}} } tdt|D]} || \} } }}}dx}}|dvr|}d}n| | dk(r||k(rd}| d vr|dz }n | d vr|dz}| d k(s | d k(r |dk(r||vr|}|}|d vr| |vr| }|}|,|s*| t|dz kr|| dzddvr |dvr| |vr| }|}|dk(r | |vr |d| zf|dk(r | |vr |d| zf|r |d|zf| }|}yw)aNever use the characters 'l', 'O', or 'I' as variable names. In some fonts, these characters are indistinguishable from the numerals one and zero. When tempted to use 'l', use 'L' instead. Okay: L = 0 Okay: o = 123 Okay: i = 42 E741: l = 0 E741: O = 123 E741: I = 42 Variables can be bound in several other contexts, including class and function definitions, lambda functions, 'global' and 'nonlocal' statements, exception handlers, and 'with' and 'for' statements. In addition, we have a special handling for function parameters. Okay: except AttributeError as o: Okay: with lock as L: Okay: foo(l=12) Okay: foo(l=I) Okay: for a in foo(l=12): Okay: lambda arg: arg * l Okay: lambda a=l[I:5]: None Okay: lambda x=a.I: None Okay: if l >= 12: E741: except AttributeError as O: E741: with lock as l: E741: global I E741: nonlocal l E741: def foo(l): E741: def foo(l=12): E741: l = foo(l=12) E741: for l in range(10): E741: [l for l in lines if l] E741: lambda l: None E741: lambda a=x[1:5], l: None E741: lambda **l: E741: def f(**l): E742: class I(object): E743: def l(x): NFr)r OIr>r9rrTrrr-r()asr:globalnonlocalz:,=)>rrrrrrBz$E742 ambiguous class definition '%s'r9z'E743 ambiguous function definition '%s'z!E741 ambiguous variable name '%s')rry)rHr func_depth seen_colon brace_depthidents_to_avoidrrrxrrrtrrrrridentr s r7ambiguous_identifierrsXJJK%O5;AY2Iy*hq#f+&0-3E]* D%d ) )$JJ& z)J 5= 1 K U] 1 K 4yw) zsInvalid escape sequences are deprecated in Python 3.6. Okay: regex = r'\.png$' W605: regex = '\.png$' N)rrvrr[abrnrrv01234567xNuUrErrvrrrzW605 invalid escape sequence '\r)rrrrrrtlowerFSTRING_MIDDLETSTRING_MIDDLErUcountrfindr+r,r)rHrrvalidprefixesrrr_ start_line start_colr rcols r7#python_3000_invalid_escape_sequencer^sk  E*H)/% D%A (//=-H H OOD!6$**T"X"67==? @ (//>>J J(2,&(-% IiioQh1HCCy-)DJJtQ,DD:-"+c/C"% 4C(@"@1"DC!37O>tCykK))D#'2CQh (//; D D LLN1sDEE:Ec#PK||ryd}t}|D]@\}}}} } |tjtjgvs0|j | B|D]F\}}}} } |tjk(r|r |tjtj fvr||tvr| j} t| D]\} } |d| zdk(r| jdryt| }| j}|tj k(r't|dk(r|t|dz tkrzt|dk(r8| dzt| kr't|dk(r|t|dz tkr||kDs|d| z|f}|d||fzf|}Iyw)zLimit all doc lines to a maximum of 72 characters. For flowing long blocks of text (docstrings or comments), limiting the length to 72 characters is recommended. Reports warning W505 NrrrrrEz+W505 doc line too long (%d > %d characters))setr-unionrraddr SKIP_TOKENSrwrlrryrMAX_DOC_LENGTH)rHmax_doc_lengthrr prev_token skip_linesrrrrrr~line_numrGrr doc_errors r7maximum_doc_lengthrsJJ.4!* D%d ]00(//1BC C NN4 !/5 * D%d  (Z  (//8+;+;< <!Z;%>)/8/?;+HmQx(*a/DOOD4I /F*002F!X%5%55K1, &VBZ 8> I$6{a'HqL3u:,EK1, &VBZ 8> I$.%*1X%8.$I (+A"(.!9+:;;;$ 5 sAF&EF& F&c tj|5}|jcdddS#1swYyxYw#ttt f$r7t|d5}|jcdddcYS#1swYYyxYwwxYw)zRead the source code.Nzlatin-1)encoding)ropen readlines LookupError SyntaxError UnicodeError)filenamers r7rrsr! ]]8 $ !;;= ! ! ! l 3! (Y / !1;;= ! ! !!s;=1 =:==!BA:. B:B ?BBc|tjtjjdj S)zRead the value from stdin.ignore)errors)io TextIOWrappersysstdinbufferreadr\r_r7stdin_get_valuers(  CII,,X > C C EEr_iz# no(?:qa|pep8)\bc|jd}d|vr%t|t|jz Sd}|D] }|dk(r |dzdzdz}|dk(r|dz }|S|S)zXReturn the amount of indentation. Tabs are expanded to the next multiple of 8. z rsrrr3r)rxryr)rresultrps r7rrs ;;v D 44y3t{{}--- F 4<q[1_q(F S[ aKF  M Mr_c|j|ddz}t|dz }|dddvr |dz }|dz}|d|d||z zz||dzS)z7Replace contents with 'xxx' to prevent syntax matching.rErN)z"""z'''rr)rtry)rrrs r7 mute_stringrsm JJtBx 1 $E d)a-C BCyN"   q <#u- -ST ::r_c*i}dx}}|jD]}|r|dddk7r|dz}|dddk(rQtj|}d|jD\}}||j t |||zl|dddk(su|ddj d dd }|dd d vr|d d}t||<|jD cic]4\} } | r-t| |r!tjj|| | 6c} } Scc} } w) z&Return a dictionary of matching lines.Nrrrz@@ c3:K|]}t|xsdyw)rN)int)r5gs r7r8zparse_udiff..sGaCSMGsz+++rrsrr)zb/zw/zi/) rw HUNK_REGEXrjrupdaterrritemsfilename_matchospathjoin) diffpatternsparentrvrrr hunk_matchrfilepathrowss r7 parse_udiffrs1 BD5! BQx3   8u #))$/JG:3D3D3FGLS% tHOOE#sU{3 4 "1X 8>>$*1-DBQx--ABxuBtH$!#   Xt N8X6  VX&,  s9DcD|sgSt|tr|Sg}|jdD]s}|j}d|vr=tj j tj j||}|j|jdu|S)zQParse a comma-separated list of paths. Return a list of absolute paths. rr) isinstancerrrrrabspathrrrx)valuerpathsrs r7normalize_pathsrs  % E C 'zz| $;77??277<<#=>D T[[%& ' Lr_c4|s|Stfd|DS)z{Check if patterns contains a pattern that matches filename. If patterns is unspecified, this always returns True. c36K|]}t|ywrKr)r5patternrs r7r8z!filename_match..8sBgwx)Bs)rf)rrrs` r7rr1s  BB BBr_c6|D]}||vs||xxdz cc<y)z^Adds one to the counts of each appearance of characters in s, for characters in countsrNr\)r6rrrps r7rkrk;s( 6> 4LA Lr_cZ|dtvxs|d|dddjdk(S)Nrrrrz\ )rr)tokens r7 _is_eol_tokenr Cs7 8w  K%(58A;<"8"?"?"AV"KKr_c`eZdZdZ ddZdZdZdZdZdZ d Z d Z d Z d Z d ZddZy)Checkerz;Load a Python source file, tokenize it, check coding style.Nc z|t|j}n|rJd|_|j|_|j |_|j|_|j|_ |j|_ |j|_ dx|_ |_ d|_|j|_|j|_ |j |_||_i|_|d|_|xsg|_nF|dk(r&d|_t)j+d|_n| t-||_n||_|j&rxt7|j&dd}|dvrY|d k(r |j&dd d|j&d<n4|j&ddd d k(r|j&dd d|j&d<|xs |j8|_|j8j:|_d|_y#t.$r:t1j2dd\}}|j4d||_g|_YwxYw) NrFrrTr: )rrru) StyleGuideoptions _io_errorphysical_checks_physical_checkslogical_checks_logical_checks ast_checks _ast_checksrrr fstring_start tstring_startrrrr_checker_statesr~rrwrOSErrorrexc_info__name__ordreportr report_errorr) r`rr~rr"kwargsexc_typeexcord0s r7rfzChecker.__init__Os  ? (00G : ' 7 7&55"--&66%44"..233T/#00"..   !  #DM"DJ _#DM(*55d;DJ ] &x0 DJ ::tzz!}Q'(D~%6>$(JJqM!"$5DJJqMZZ]2A&.8$(JJqM!"$5DJJqM.  KK--  "%,,.!"43$,$5$5#6b!>  s#G77AH:9H:c <tjdd\}}t|jdkDr#|jd}t|dkDr|dd}nd}|j |d|dxsdd|j d|jd|j y) zCheck if the syntax is valid.Nrrr)rrrzE901 r)rrryr]r#r report_invalid_syntax)r`r%r&ros r7r)zChecker.report_invalid_syntax~s,,.!,3 sxx=1 XXa[F6{Q!F &)VAY^!!("3"3!4Bsxx{mD44 6r_c|j|jk\ry|j|j}|xjdz c_|j|ddtvr |d|_|S)z(Get the next line from the input buffer.rXrNr)rrr~rmr.)r`rs r7readlinezChecker.readlinesh   t// /zz$**+ A    #RaJ(>#AwD  r_cH|Dcgc]}t||}}||Scc}w)zRun a check plugin.)getattr)r`r[argument_namesrR argumentss r7 run_checkzChecker.run_checks-5CDTWT4(D Di  EscPd|vr"|jj|i|_yy)z5Prepare custom state for the specific checker plugin.rgN)r setdefaultrg)r`rRr.s r7init_checker_statezChecker.init_checker_states* n ,!%!5!5!@!@r!JD  -r_c||_|jD]c\}}}|j|||j||}|.|\}}|j |j ||||dddk(sZ|d|_ey)z,Run all physical checks on a raw input line.NrE101r)rGrr3r0r#rrm)r`rrRr[r.rrors r7check_physicalzChecker.check_physicals!+/+@+@ / 'D%  # #D. 9^^E>:F!!'!!$"2"2FD%H8v%'+AwD$ /r_cg}g}d}dx}x}}|jD]'\}}} } } |tvr|sd| fg}|tjk(r|j |?|tj k(r t |}nO|tthvrA|jd|jdz} dt|| zz}| d| d| zf} |rB| \} }|| k7r+|j|dz |dz }|dk(s|dvr|d vrd |z}n ||k7r| |||z}|j ||t|z }|j || f| \}}*d j||_ |xrtd j||_|S) z!Build a logical line from tokens.rNrr"rrrz{[(rr3rX)rrrrrrrrrrryr~rrHr)r`logicalcommentsrprev_rowprev_colmappingrrrrr brace_count start_rowrrs r7build_tokens_linezChecker.build_tokens_lines(,,,8g26++ ' .JeS$[(u:,X---%X__,"4(??"jjo 3? c$i+561vs1v 34).&Iy( $ 8a< 8A FI C'IU,B,0,="Tz*3d:D NN4 c$i F NNFC= )#& Xx7 '8GGG,8bggh&7!8 r_c|jj|j}|sy|Dcgc]\}}| }}}|dd\}}|j|dz }t |d||_|j |jkr|j|_|jdk\r&t|jddj|jD]\}} } |jdk\rtd|z|j|| |j| | xsdD][\}} t|t s,|t#j$||\} } | d| d|z| z f}|j'|d|d| | ]|jr?|j |_|j|_|j s|j|_d|_g|_ycc}}w) z:Build a line from tokens and run all logical checks on it.NrrrPrz r\)r"increment_logical_liner?r~rrrrrrrHrxrr3r0rtuplebisect bisect_leftr#rrrr)r`r<rormapping_offsetsr>rrrRr[r.r token_offsetr s r7 check_logicalzChecker.check_logicals **,((* 3:;ifa6;;!(AIZZ A . )*Zi*@A   t// / $ 0 0D  <<1  $##CR(//1 2+/+?+? E 'D%||q edl#  # #D. 9 $un E K E !&%0)00B0B'11)2%L#!!fc!fvo &DEF!!&)VAYeD E E   )-):):D &$($5$5D !$$8<8I8I5 5>   aI$> J++DMM: )M! )8A;!1!11!!H7eAh ))%? %a  )X001 )  & & ( )s6ACB*1C27B*)C*)CCCCc~|jtk(r|jd|_y|jtk(r|jd|_yt |r=|jdk(r|j|y|j|jy|jtjk(rd|jvs&|jtk(s|jtk(rt|jry|jtk(r |j}n/|jtk(r |j }n|jd}|jd}d|_||_t%||D];}|j|j&|dz dz|xj"dz c_=d|_yy)z9If appropriate for token, check current physical line(s).rrXrNTrF)rrrrrrr rr6rrrr+r,rrrrrr~)r`r rYrrrs r7rVzChecker.maybe_check_physicalsc :: &!&QD  ZZ= (!&QD  5 !zzR##M2##EJJ/ hoo-$%,,2F k) k)"EJJzz[(**{*** A))A,C!DN$D $UC0 & ##DJJ{Q$?$$FG  A%  &#DNA*r_c |jj|j|j||t |j|_|j r|jd|_d|_ dx|_ |_ d|_ d|_ g|_dx|_|_d}|j#D]Q}|jj%||dd\}}|j&dk\rp|dd|ddk(r#dj)|ddxsd|dd}n d|ddz}t+d |ddd |d t,j.|dd ||t,j0k(r|d vr|dz }|d vs|dz}|r|t2vs|t,j2k(r|j5d|_t |jdk(r$|xjdz c_|jd=B|j5T|jr.|j7|jd |j5|jj9S)z!Run all checks on the input file.rNrXrrz[{}:{}]rzl.%szl.rsrrrE)r" init_filerr~ryrrrSrrmrrrrrrrrUrrrrrtok_namerrrHr6get_file_results)r`expected line_offsetrr rrr s r7 check_allzChecker.check_allGs' dmmTZZ;Otzz?    NN 9::D6 "02- /004,))+ -E KK  u %$Qqz J||q 8A;%(1+-#**58A;+<"eAhqkJC 58A;.CQx{C):):58)DdLMX[[(5=aKFU]aKF(!X%5%55**,,-)T[[)Q.((A-( KKN**,3 -4 ;;    2 /    {{++--r_)NNNNNr)r  __module__ __qualname__rdrfr)r+r0r3r6r?rHrSrUrVrar\r_r7r r LsME,0&*-^ 6! K /$L!F C)"4#l+.r_r c\eZdZdZdZdZdZdZdZdZ dZ d Z dd Z dd Z dd Zd Zy) BaseReportz"Collect the results of the checks.Fc|j|_|j|_d|_d|_t j|jd|_i|_ yrb) benchmark_keys_benchmark_keys ignore_code _ignore_codeelapsed total_errorsdictfromkeyscountersmessages)r`rs r7rfzBaseReport.__init__zsL&55#//  d&:&:A>  r_c6tj|_y)zStart the timer.N)time _start_timer`s r7rzBaseReport.starts99;r_cPtj|jz |_y)zStop the timer.N)rsrtrlrus r7stopzBaseReport.stopsyy{T%5%55 r_c||_||_|xsd|_||_d|_|j dxxdz cc<|j dxxt |z cc<y)Signal a new file.r\rr/rr1N)rr~r_r` file_errorsrpry)r`rr~r_r`s r7r\zBaseReport.init_filesX    B & g!# &'3u:5'r_c2|jdxxdz cc<y)zSignal a new logical line.r0rN)rprus r7rBz!BaseReport.increment_logical_lines o&!+&r_c|dd}|j|ry||jvr|j|xxdz cc<n!d|j|<|dd|j|<||jvry|jr!|j st |j|xj dz c_|xjdz c_|S)&Report an error, according to options.Nrr) rkrprqr_print_filenamerzrrrm)r`rrorr[rs r7rzBaseReport.errorsBQx   T "  4== MM$ 1 $ "#DMM$ "&qr(DMM$  4==    t'7'7 $--  A Q r_c|jS)z6Return the count of errors and warnings for this file.)rzrus r7r^zBaseReport.get_file_resultssr_cDtfdjDS)z.Return the total count of errors and warnings.c3^K|]$}|jrj|&ywrK)rrp)r5keyprefixr`s r7r8z'BaseReport.get_count..s/Gs~~f/E==%G*-)sumrq)r`rs``r7 get_countzBaseReport.get_counts%G"mmGG Gr_c t|jDcgc]8}|j|r%|j|dd|d|j|:c}Scc}w)a Get statistics for message codes that start with the prefix. prefix='' matches all errors and warnings prefix='E' matches all errors prefix='W' matches all warnings prefix='E4' matches all errors that have to do with imports rr3)sortedrqrrp)r`rrs r7get_statisticszBaseReport.get_statisticssU"$--0LCNN64J!% c 2Cs9KLL LLs=AcF|j|D] }t|y)z9Print overall statistics (number of errors and warnings).N)rr)r`rrs r7print_statisticszBaseReport.print_statisticss#''/ D $K r_ctdj|jd|jrJ|jD]:}td|j||jz ||j|fz<yy)zPrint benchmark numbers.z {:<7.2f} {}zseconds elapsedz%-7d %s per second (%d total)N)rrrlrirp)r`rs r7print_benchmarkzBaseReport.print_benchmarksu m""4<<1BCD <<++ ,5}}S)DLL8#}}S)++, , r_NrX)r rcrdrdrrfrrwr\rBrr^rrrrr\r_r7rfrfusC,N'66,& G L ,r_rfceZdZdZdZy) FileReportz:Collect the results of the checks and print the filenames.TN)r rcrdrdrr\r_r7rrs DNr_rc<eZdZdZfdZfdZfdZdZxZS)StandardReportz,Collect and print the results of the checks.ct||tj|jj |j|_|j|_|j|_ |j|_ yrK) superrf REPORT_FORMATrrr_fmtrepeat_repeat show_source _show_source show_pep8 _show_pep8r`r __class__s r7rfzStandardReport.__init__s^ !!%%gnn&:&:&<&-nn6 ~~ #//!++r_c6g|_t| ||||S)ry)_deferred_printrr\)r`rr~r_r`rs r7r\zStandardReport.init_files&!w eX{4 4r_ct|||||}|rK|j|dk(s |jr-|jj ||||dd|j f|S)r}rr~N)rrrprrrrd)r`rrorr[rrs r7rzStandardReport.errorsbw}[&$> T]]4(A-  ' 'fdDHemmD F r_c p|jj|jD]\}}}}}t|j|j|j |z|dz||dz|j rl|t|jkDrd}n|j|dz }t|jttjdd|d|dz|jr|rtd|jztjj!|j"S) z9Print results and return the overall count for this file.r)rrrrrrXz\Sr3Nr!z )rsortrrrr`rryr~rxrdsubrrrstdoutflushrz)r`rrorrdocrs r7r^zStandardReport.get_file_resultss !!#484H4H  0KtS $)) ''+5fqjd    TZZ0D::kAo6Ddkkm$bffUCgv7#=>3fsyy{*+ JJ   - .r_) r rcrdrdrfr\rr^ __classcell__rs@r7rrs6,4  r_rc,eZdZdZfdZfdZxZS) DiffReportz9Collect and print the results for the changed lines only.cFt|||j|_yrK)rrfselected_lines _selectedrs r7rfzDiffReport.__init__ s ! //r_c`||j|jvryt| ||||SrK)rrrr)r`rrorr[rs r7rzDiffReport.error s0 dnnT]]; ; w}[&$>>r_)r rcrdrdrfrrrs@r7rr sC0??r_rcHeZdZdZdZd dZd dZd dZdZd dZ d Z d Z y) rz-Initialize a PEP-8 instance with few options.c|jdt|_|jdd}|jdd}|jdd}t|i|}|rdn|j dd}|j dd}t |||||\} |_|r)| jj|d|vr |d|_|j|_ | |_ | js| jrtnt| _ t!| j"xsd| _| j"s6| j$s*t&r$t!t&j)d | _n(| j"rd nt!| j$| _t*dd| _|j.| _|j1d | _|j1d | _|j1d | _|j9y)N checker_class parse_argvF config_fileparserrrr\rrrGrHrI)rr rrnrprocess_optionsr__dict__r input_filerunnerrreporterquietrfrrCselectrDEFAULT_IGNORErBENCHMARK_KEYSrhrj get_checksrrr init_report) r`r]r$rrr options_dictarglistrrs r7rfzStyleGuide.__init__ s#ZZAZZ e4 jj6 Hd+T,V, $$,*:*:7D*I""9d3- Zfg?     # #L 1,&)'2 oo  -4]]zG w~~34'..n">#7#7#<=GN'.nnU%:OGN!/!2".."&///"B!%!@!__V4 r_Nc|xs|jj|j|j_|jjS)zInitialize the report instance.)rrr")r`rs r7rzStyleGuide.init_report@ s8@x@4<<+@+@$,,O ||"""r_c| |j}|jj}|j}|j  |D]M}t j j|r|j|4|j|rF||O |j|S#t$rtdY(wxYw)zRun all checks on the paths.z ... stopped) rrr"rrrrisdir input_direxcludedKeyboardInterruptrrw)r`rr"rrs r7 check_fileszStyleGuide.check_filesE s =JJE$$  ! !77==&NN4(t,4L  !   ! ! -  !sAB' B''B>=B>c|jjrtd|z|j|||j}|j ||S)z'Run all checks on a Python source file.z checking %s)r~r)r_r`)rrrrra)r`rr~r_r`fcheckers r7rzStyleGuide.input_fileW sR <<   -(* +%% E4<<&9!!8!MMr_c|jd}|j|ry|jjj}|jj }|jj }|j}tj|D]\}}}|rtd|z|dxxdz cc<t|D]&} |j| |s|j| (t|D]H} t| |s|j| |r#|tjj|| Jy)z9Check all files in this directory and all subdirectories.rrz directory r.rN)rxrrr"rprrrrwalkrrremoverrr) r`dirnamerpr filepatternsrrootdirsr/subdirrs r7rzStyleGuide.input_dir_ s ..% == !<<&&//,,&&||,, !#!1 9 D$lT)* ] #q ( # , (==.KK' (#5M 9#8\: h5277<<h78  9 9r_cr|jjsytjj |}t ||jjry|r tjj ||}tjj|}t ||jjS)zxCheck if the file should be excluded. Check if 'options.exclude' contains a pattern matching filename. FT)rexcluderrbasenamerrr)r`rrrs r7rzStyleGuide.excludedw s ||##77##H- (DLL$8$8 9 ww||FH5H77??8,h (<(<==r_c tdkr)tfd|jjDryj |jj xr&j |jj S)zCheck if the error code should be ignored. If 'options.select' contains a prefix of the error code, return False. Else, if 'options.ignore' contains a prefix of the error code, return True. rc3@K|]}|jywrKr`)r5r6rs r7r8z)StyleGuide.ignore_code.. s"!?%&"#d!3!?rbF)ryrfrrrr)r`rs `r7rjzStyleGuide.ignore_code sj t9q=S!?*.,,*=*=!?? 3 349OODLL$7$788 :r_cg}t|jD]=\}}|\}}tfd|Ds |j|j||f?t |S)zGet all the checks for this category. Find all globally visible functions where the first argument name starts with argument_name and which contain selected tests. c3JK|]}|xrj| ywrK)rj)r5rr`s r7r8z(StyleGuide.get_checks.. s$KT7!1!1$!78Ks #)rYrrfrr r)r` argument_namechecksr[attrsr\r]s` r7rzStyleGuide.get_checks se #M288: =LE5!MUDKUKK u~~ud;< =f~r_rK)NNr) r rcrdrdrfrrrrrrjrr\r_r7rr s/7#J# $N90 > : r_rct||d}gd|_|jddddd |jd d ddd |jd dddd |jdddd|jddtd|jdddd|jddd d!|jd"dd d#tz|jd$dd%&|jd'dd(&|jd)dd*&|jd+dd,&|jd-d.d/t d01|jd2d.d/d3d41|jd5d.d/t d61|jd7dd8&|jd9d:d;d<|jd=dd>&|jd?}|jd@ddA&|S)Bz"Create the parser for the program.z%prog [options] input ...)progversionusage)rrrrzmax-line-lengthzmax-doc-lengthz indent-sizez hang-closingrrrz show-pep8z show-source statisticsrz-vz --verboserrz(print status messages, or debug with -vv)ractionhelpz-qz--quietz+report only file names, or nothing with -qqz-rz--repeatT store_truez1(obsolete) show all occurrences of the same errorz--first store_falserz#show first occurrence of each error)rdestrz --excluderz[exclude files or directories which match these comma separated patterns (default: %default)metavarrrz --filenamez*.pyzjwhen parsing directories, only check filenames matching these comma separated patterns (default: %default)z--selectrrXz&select errors and warnings (e.g. E,W6)z--ignorez2skip errors and warnings (e.g. E4,W) (default: %s)z --show-sourcezshow source code for each error)rrz --show-pep8z3show text of PEP 8 for each error (implies --first)z --statisticszcount errors and warningsz--countzgprint total number of errors and warnings to standard error and set exit code to 1 if total is not nullz--max-line-lengthrrz3set maximum allowed line length (default: %default))rrrrz--max-doc-lengthNzSset maximum allowed doc line length and perform these checks (unchecked if not set)z --indent-sizez9set how many spaces make up an indent (default: %default)z--hang-closingzNhang closing bracket instead of matching indentation of opening bracket's linez--formatrrz.set the error format [default|pylint|]z--diffzSreport changes only within line number ranges in the unified diff received on STDINzTesting Optionsz --benchmarkzmeasure processing speed)rconfig_options add_optionDEFAULT_EXCLUDErMAX_LINE_LENGTH INDENT_SIZEadd_option_group)rrrrks r7 get_parserr s tW ;=FFF dK7EG dIqHJ dJ\NP i H@B k:JK lJ12 j(BCE j(B+-;<= ol<> mL/0 n\68 i /0 )s-12 (uc"AB oE3)12 &|CD j(IKM h|@A  # #$5 6E ]<46 Mr_c dtj}|j}tj}t rVtj jt r3|jrtdt z|jt |xr<tj jtj j|x}|r`|jfdtDr}|jrtdzn%tj j\}|r`|rJtj j|r+|jrtd|z|j|d}|j|j r |j }n(|jdrd}t#j$d|rX|j&D cic]'} | j(| j*xs | j,)} } |j/g\} } |j1|D]} | j3dd |j4vrtd | z0|jd kDr+td j7| |j9|| | j3d d}| |}|d vr|j;|| }n:|dvr|j=|| }n#|j9|| }|dk(r t?||}tA| |||j/|| \}} |Scc} w)a{Read and parse configurations. If a config file is specified on the command line with the "--config" option, then only it is used for configuration. Otherwise, the user configuration (~/.config/pycodestyle) and any local configurations in the current directory or above will be merged together (in that order) using the read method of ConfigParser. zuser configuration: %sc3^K|]$}tjj|&ywrK)rrr)r5fnrs r7r8zread_config.. s IBrww||FB/Irzlocal configuration: in %szcli configuration: %sNpep8z0[pep8] section is deprecated. Use [pycodestyle].rrz unknown option '%s' ignoredrz {} = {})rr)rrr)rO)! configparserRawConfigParserconfigrcurdir USER_CONFIGrisfilerrrr commonprefixPROJECT_CONFIGr has_sectionrwarningswarn option_listrrr parse_argsrr4rrrgetint getbooleanrsetattr)rr]rrrcli_conf local_dirtailpycodestyle_sectionor new_optionsroptnormalized_optopt_typerrs @r7 read_configr s ) ) +F~~H Irww~~k2 ?? *[8 9 K HRWW__RWW-A-A$-GHHFT  ;;I.I II2V;< v. BGGNN8, ?? )H4 5 H &++&$kk   F #$ HI;A;M;MNaqvvqvv11N N#--b1b>>"56 8C{{3$F,A,AA5;<"k(()/4G)MOP [[c2N">2H++ &93?::))*=sC #6<!Y.+E9=E K 7# 8())'+)F " N7Os!,L-c |s t}|jdsR|jdd|jddj |j d}|j dd|d |s|sg}|j|\}}d |_|||_ |r9|s7|jstd tDrdg}n|jd t||||}|xr|jdk(xrt |_t#|j$|_t'|j(|_t#|j*|_t#|j,|_|jrIt.|_t1}t3||j$|d|_t7|j4}||fS)zProcess options passed either via arglist or command line args. Passing in the ``config_file`` parameter allows other tools, such as flake8 to specify their own options to be processed in pycodestyle. z--config Configurationz'The project options are read from the [z] section of the tox.ini file or the setup.cfg file located in any parent folder of the path(s) being processed. Allowed options are: z, .) descriptionrzuser config file locationrNc3ZK|]#}tjj|%ywrK)rrexists)r5rRs r7r8z"process_options..J s%;#' "ww~~d3;s)+zinput not specifiedrr)r has_optionrrrrrrrrrrfrrrrr_parse_multi_optionsrrrrrrrrrr) rrrrrrkrr]rs r7rr, s    Z (''[[$))F$9$9: <(> V[9  ; :''0OWdG!$ <<3;+9;;5D LL. /'4&9G!Ggmmq&8GZG+G,<,<=G%goo6GO)'..9GN)'..9GN||%!!,UG4D4Dd1g!Ng,,- D=r_c|r>|j|Dcgc]#}|js|j%c}S|Scc}w)zgSplit and strip and discard empties. Turns the following: A, B, into ["A", "B"] )rr)r split_tokenr s r7rr` s:#*==#=Ka KKLs AAcddl} |j|jdtd}|j}|j }|j r|j|jr|j|jrW|jr5tjjt|jdztj dyy#t$rYwxYw)z.Parse options and run checks on Python source.rNc,tjdS)Nr)rexit)signumframes r7z_main..v sCHHQKr_T)rrr)signalSIGPIPEAttributeErrorrrrrr benchmarkrrmrrstderrwriterr)r  style_guiderr"s r7_mainr'p s  fnn&GH-K!!G  $ $ &F!   == JJ  S!4!45< =      sC'' C32C3__main__rK)Nr)T)NFNNN)r)rdrDrrLrrrrdrrsrrr functoolsroptparser version_infocallabler-r __version__rrplatformr expanduserrrgetenv ImportErrorrrrrrrrL frozensetrkwlistr2r1r/rr3r0r.rrINDENTDEDENTrr ERRORTOKENr-rrKrirbrrrr;rrrrrrlrrr@rrrorerrrr+rrr,rYrUrgrqrur{rrrrrrrrr rrr9r=rIrRrVrirtrzr|r}rrrrrrrrrrrrrrmrrrrrrrrkr r rfrrrrrrrrr'r r\r_r7r7s8*  ! 7":t45!("3"34H ;9  ||wgg(():; ggll BII' ( KBGG,>,>{,K  *   <5  0 1 W^^wi/ 0: =78?@ %++,LM!)*y ! X[[("2"23 4mmX__hoo>? !!8#3#3X5H5H"IJ Lrzz+& "**./"**\*(bjj)KL#-2::f#5 )rzz*>?$"**&FG#%12RZZ< 2TYYx5HHI IJrzz-( RZZE F !rzz"9:%2::&NO'RZZ(NO$.BJJ"C" %!rzzJK RZZ .w**M,,N&&K355M5N[w**M,,N&&K355M5N[B ?B.MM&DD<<. D D HHJ :FR/R/j#7#7LGG.DD,&1&1ROEOEd$$NHH.ddNJJ$GGT))X==&3131l=*=*@''Z*+i.AA !4BB:D!7!7HJJ*  * = = ``F88x, , h!F y~jbjj!5rtt<CCD& ;:#%))$CLf.f.R W,W,t 3 Z3 l ? ?FFR";>BGTAE)-1h  6 z GqQKs>A4V**V54V5