bgMh dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddl mZ ddlmZddlmZn#e$r ddlmZYnwxYwejdkr3eeed dre eje_d Zd Zd Z ejd krejdZnCej ej!dpejddZn #e$rdZYnwxYwdZ"ej ej#e$dZ%dZ&dddZ'dZ(dZ)dddZ*dZ+e,gdZ-e,ej.dd gze-z Z/e,gd!Z0e,gd"Z1e12gd#Z3ejd$krd%gngZ4e,gd&e4zZ5e,d'Z6e,ej7ej8gZ8e82ej9ej:gZ;e;2ej<ej=gZ>gd(Z?ej@d)ZAej@d*ZBej@d+ZCej@d,ZDej@d-ZEej@d.ZFej@d/ZGej@d0ZHej@d1ZIej@d2ZJej@d3d4 e/zZKej@d5ZLej@d6ZMej@d7ZNej@d8ZOej@d9ZPej@d:Qd4 d;dZTiiid?ZUd@ZVddAZWeWdBZXeWdCZYeWdDZZeWdEZ[eWdFZ\dGZ]eWdHZ^eWdIZ_eWdJZ`eWdKZaeWdLZbeWdMZceWdNZdeWdOZeeWdPZfeWdQZgeWdRZheWdSZieWdTZjeWdUZkeWdVZleWdWZmeWdXZne,dYe,dZzZod[Zpd\ZqeWd]ZreWd^ZseWd_ZteWd`ZueWdaZveWdbZweWdcZxeWddZyeWdeZzeWdfZ{eWdgZ|eWdhZ}eWdiZ~eWdjZdkZdlZe dmej@dnejjZdoZdpZddrZejfdsZdduZdvZdwZGdxdyZGdzd{ZGd|d}eZGd~deZGddeZGddZdefdZdZ ddZddZdZedkr edSdS)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)RawConfigParser) TextIOWrapper) _compilez2.9.1z'.svn,CVS,.bzr,.hg,.git,__pycache__,.toxz&E121,E123,E126,E226,E24,E704,W503,W504win32z~\.pycodestyleXDG_CONFIG_HOMEz ~/.config pycodestyle)z setup.cfgztox.ini testsuiteO) top_levelmethodHz+%(path)s:%(row)d:%(col)d: %(code)s %(text)sz%%(path)s:%(row)d: [%(code)s] %(text)s)defaultpylinti)FalseNoneTrueprintasync)>>***+-)rr /z//r!r"@)^&|z<<>z%=z^=z&=z|===z<=z>=z<<=z>>==andinisorz->u  ) directoriesfiles logical linesphysical linesz([ \t]*)zraise\s+\w+\s*,zraise\s+\w+\s*,.*,\s*\w+\s*$z\b[A-Z]\d{3}\bz u?r?["\']z[\[({][ \t]|[ \t][\]}),;:](?!=)z[,;:]\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\s+|def\s+|class\s+|@)z ^\s*({})\bc#BK|]}|ddVdS) z\s+N)replace).0ss \/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pycodestyle.py r>s@""Q!))C"8"8"""""")defz async defforz async forifelifelsetryexceptfinallywithz async withclasswhilez-^__([^\s]+)__(?::\s*[a-zA-Z.0-9_\[\]\"]+)? = z except\s*:) physical_line logical_linetreecldtj|jDS)Nc<g|]}|j|jk|jS)kindPOSITIONAL_OR_KEYWORDname)r; parameters r= z#_get_parameters..s: B B B~!@@@ NA@@r?)inspect signature parametersvalues)functions r=_get_parametersr[sC B B **5<<>> B B BBr?cbd}tj|rSt|}|rA|ddvr7|!t|jpd}|||d||nDtj|r0t|jddddgkr||d|d|S) zRegister a new check object.c|t|vr0t||d|pgdS|pdg|ft||<dS)Nr)_checksextend)checkrQcodesargss r= _add_checkz"register_check.._add_checks\ GDM ! ! DM%  # * *5;B 7 7 7 7 7$)MbT4#8GDM% r?r)rKrLNr^rselfrM)rV isfunctionr[ERRORCODE_REGEXfindall__doc__isclass__init__)rarbrdrcs r=register_checkrls999 %  3u%%  4DG@@@}'// 0CDD Jud1gud 3 3 3   3 5> * *2A2 .662B B B JufeT 2 2 2 Lr?ct|d}t|D]\}}||kr|dfcSdS)aDNever 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 E101: if a == 0:\n a = 1\n\tb = 1 rz/E101 indentation contains mixed spaces and tabsN) INDENT_REGEXmatchgroup enumerate)rK indent_charindentoffsetchars r=tabs_or_spacesrvsp   . . 4 4Q 7 7F!&))MM  ;  LL L L L MMr?ct|d}d|vr|ddfSdS)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)rnrorpindex)rKrss r= tabs_obsoleterzsM   . . 4 4Q 7 7F v~~||D!!#CCC~r?c|d}|d}|d}|d}||kr|rt|dfSdSdS)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 zW291 trailing whitespace)rz#W293 blank line contains whitespaceNrstriplen)rKstrippeds r=trailing_whitespacers"((..M!((..M!((00M##G,,H   <x=="<< <;; ! r?c||kr8|d}|r|sdS||krt|ddfSdSdS)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 filezW292 no newline at end of fileNr)rKlines line_number total_linesstripped_last_lines r=trailing_blank_linesrsjk!!*11&99  7!3 766  . .uRy>>#CC C "! / .r?c|}t|}||kr|s|dkr|drdS|}t|dkr|st|dkr:|ddkr.t|t|dz |dz krdS||kr |d ||fzfSdSdSdS) 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#rz'E501 line too long (%d > %d characters))rr startswithsplit)rKmax_line_length multilinernoqalinelengthchunkss r=maximum_line_lengthrs    ! !D YYF  !   5 5  F [[A  )  [[A  &)s"2"2D Cr OO+o.AAA F O # ##&+.4o-F&GH H  $ #r?cPt|sdS|dz }|dkrd}nt||dz }||krdS|t|krb||}|dst|rn|dz }|t|kbdS|dz}|t|kr3||rn|dz }|t|k3dSt|||kS)NFrrr$T)STARTSWITH_TOP_LEVEL_REGEXro expand_indentrstripr)rL indent_levelrrline_idx prev_indentrnext_idxs r= _is_one_linerr.sA % + +L 9 9uQH!|| #E(Q,$788 \!!u SZZ  X$$&&s## (B(H(H(N(N   MH SZZ  u!|H SZZ   ? " "   MH SZZ   t x ) )\ 99r?c #pKtd} td} |s|| krdS|dr |rdVdSdS|| ks |r|| dzkr dd|zfVdSt|rt ||||r|dkrdS|r|| ks||kst |s|} d } ||| z dd D]n} | rXt| | krEt| } t| } | s| dkrno| r dd | d fVdSdd | fVdSdSdSdS|| kr dd| |fzfVdSdS|r*|s*|| kr&|drdd| |fzfVdSdSdSdSdS)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)FrzE306 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_CONFIGrrrorDOCSTRING_REGEXrrSTARTSWITH_DEF_REGEXlstripformat)rL blank_linesrr blank_beforeprevious_logical previous_unindented_logical_lineprevious_indent_levelrtop_level_lines method_linesancestor_levelnestedrs r=rrQsB)5O%h/L   > >""3''-/  GF F F F F F G G  ' '  ()\A-===1K??????? # ) ), 7 7&/ , e[ I I  A   F  / L00)L88#))*:;;9"."+"?"C"CD""Dzz||" d(;(;n(L(L)6t)<)<!5!;!;DKKMM!J!J!"^q%8%8!E&!8D GGGGGGGCJJ$&&&&&&&&%108888&_ , ,=A/// / / / / /- , // O + + , 7 78J K K ,58/// / / / / / //// + + + +r?c#TK|}t|D]}|}|}|}|dr |dzd|zfVe||dz dkr|dvrdnd}||d|d fVd S) aHAvoid 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 rrzE201 whitespace after '%s',}])E202E203z whitespace before ''N)EXTRANEOUS_WHITESPACE_REGEXfinditerrprstartisspace)rLrrotextrufoundcodes r=extraneous_whitespacers( D,55d;; > >{{}}zz||  8     >!)9D@@ @ @ @ @ %!)_ # #"emmFFDD==d==== = = = > >r?c#Kt|D]}|\}}d|vr|ddfVn,t |dkr|ddfVd|vr|ddfVt |dkr|ddfVdS) zAvoid extraneous whitespace around keywords. Okay: True and False E271: True and False E272: True and False E273: True and\tFalse E274: True\tand False rxrzE274 tab before keywordz#E272 multiple spaces before keywordrzE273 tab after keywordz"E271 multiple spaces after keywordN) KEYWORD_REGEXrgroupsrrrLrobeforeafters r=whitespace_around_keywordsrs'' 55 G G   6>>++a..";; ; ; ; ; [[1__++a.."GG G G G 5==++a..":: : : : : ZZ!^^++a.."FF F F F G Gr?c#FKt||ddD]\}}|j|jkrptj|jrW|jt vrI|jdvr@|jdkr |jdks*|jdkr |jdks|jdvr |jd fVdS) 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 rNrawaitrFr yield)z: z%E275 missing whitespace after keyword)zipendrkeyword iskeywordstring SINGLETONS)rLtokenstok0tok1s r= missing_whitespace_after_keywordrs&&*-- D D d H " "!$+.. # :-- #555[H,,1C1C[G++ s0B0B 5(((CC C C C D Dr?c#K|}tt|dz D]}||}||dz}|dvr|tvr|d|}|dkrY|d|dkr-|d|dkr|dkr|d kr|dkr|d krt jd kr|d |zfVdS) zEach comma, semicolon or colon should be followed by whitespace. Okay: [a, b] Okay: (3,) Okay: a[1:4] Okay: a[:4] Okay: a[1:] Okay: a[1:4:2] E231: ['a','b'] E231: foo(bar,baz) E231: [{'a':'b'}] rz,;:N:[]{rrr/r)z"E231 missing whitespace after '%s')ranger WHITESPACEcountrfindsys version_info)rLrryru next_charrs r=missing_whitespacers Ds4yy1}%% E EE{O 5==Yj88&5&\Fs{{v||C006<<3D3DDDLL%% S(9(999s{{yC//s{{yC//C4D4N4N=DD D D D E Er?c#4K|rdnd}|rdnd}||zrd|d|zdt|zfzfV|d}|r||krd|d|zd fzfVn|s||krd|d|zd fzfV|r |d krd nd } || z} || kr d|dzfVdSdSdS)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 rr zE11%d %szE11%d %s (comment)rz!indentation is not a multiple of rrzexpected an indented blockzunexpected indentationrxr*r)rz over-indentedN)strendswith) rLrrrrr indent_sizectmpl indent_expectexpected_indent_amountexpected_indent_levels r= indentationrsM, qA% ?::+?Dk!  E /#k2B2B B      %--c22M:)>>>Q <======= :|.CCCQ 89999991&1T&9&9q 58N N / / /T000 0 0 0 0 0 11 0 /r?c #X K|ddd}d|dddz|z } |s| dkrdS|d} dx} } |dkr|fn||dzf} dg| z}dg| z}dgg}dg}i}|dd}d}d}|dg}|d kr0td |dd z|D]\}}}}}| |d|z k}|r|d|z } | o|tv}|r|}|d kr$td |zt ||z || <|t jko|d v}t|| D]}|| ||z }|| v} | rn|| r ||| k} | o |dko||d}|r!|| r|d|| kr|dfVn|r |s |r|dfVn|| r|d|| kr |dur|dfVny| s| r|| d|zkr|r|s|dfV||| <nV|dur |d|| <nF||tfvrn:|dkrd}!n(|| rd}!n|s || rd}!n||| <||krd}!nd}!|d|!zfV|| rZ|t j t j fvr@|| s8|d|| <d||d<|d krtd| d|dn|t j t j fvs|dvrt||d<nu| s| s|dvrd||ddz<n^|s| s| s|dkrd||ddz<nC|dkr=||dd r|| | |t jkr|dvr| dz } |d|dt|| kr|g|| | || xxdz cc<|d kr$td| d|dd || n|d!vr| dkr|p|d}"|t#| D]}#||#|"krd||#<t%|D] }$|$|"kr||$= || dzd=| dz} | r d||| <t#| ddD]}%||%r||%xxdzcc<nt|| dzksJ|d|vr |||d<|d|dk}|r|| ||d|z <| r;t |||zkr'|d|d|zf}&|rd"}'nd#}'|&d$|'zfVdSdSdS)%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) rrrrNrrxFr z>>> 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 )uurbbr)assertraiserHrB([{z seen, col z, visual min = )]}zE129 visually indented linezE125 continuation linez(%s with same indent as next logical line)rrrNEWLINErtokenizeOPreversedgetrNLCOMMENTSTRINGrappendrpoprlist)(rLrr hang_closingrrrrverbose first_rownrows indent_nextrowdepth valid_hangsparens rel_indent open_rowshangsindent_chances last_indent visual_indentlast_token_multiliners token_typerrrrnewline close_bracketopen_rowhanghanging_indenterrorrdindidxposrs( r=continued_indentationr ?s":q ! QI r 1 a 9 ,E uzz '',,KOC%$/4$7$7;..;? +S5[FuJI FEN)A,KM !n F!|| fvay|**,,,---.4G=G=* D%da9,,  M(Y&C..L:W3LG C ?K!||ft{{}},---,D11L@JsO(8;6H45=M%Yu%566  !#H)==!%!4!EU| 8"&%,"6!..:4!8:+//a99 + ?+ ?8ve},, #01111& ?t& ? O!NNNNN! ?58fUm#;#; ,, #>???? ?K ?$.sOq;$F$F DD #CDDDD#e $&& %au 4+--199FEEE] LEEE&L5<LBEE#'E%Lk)) J K6>>>>> 3K )8;0@"AAA5MB!!HF5M'+N58 $!||CuCCqCCDDDX_h.>???,,,'*N58 $ $ )U )t/J'J'J)-N3q6A: & & ) )E )ddll)-N3q6A: & & S[[T#a&'']2244[ e  # #C ( ( (  $ $u}}  a    T"""y>>U**$$R(((% '',,,s q a<<E 55%(((F5MM;<<<5199$jjll>++a.."<< < < < < [[1__++a.."HH H H H 5==++a..";; ; ; ; ; ZZ!^^++a.."GG G G G H Hr?c#*Kd}d}tj}dx}}tjtjf}|D]`\}} } } } |tvr| dvr|dz }n | dkr|dz}|r| |kr|dur|ds |ddfVd}n| d kr|d vrn|d kr| d vs |dkr| d krn|dus|dr|dfVn7|dkr1d\} }|dkrd\} }n|tvrd\} }|d| d|dfVd}n||vr|| dkr|rnt| t vrd}nh| t vrT|tjkr|dvs=|tjkr/|tvr&tj dkstj |sd}n | tvrd}| || |kf}n|r| |kr|dfVd}|}| }| }bdS)aVSurround operators with a single space on either side. - 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). - 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] 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) rFN)(lambdarrTz'E225 missing whitespace around operatorr-)r,r"r#>rrrrr)E226 arithmeticr()E228modulo)E227zbitwise or shiftz missing whitespace around z operatorr/rr#) rrr% SKIP_COMMENTS ARITHMETIC_OPWS_NEEDED_OPERATORSUNARY_OPERATORSKEYWORDSrrrr&WS_OPTIONAL_OPERATORS)rLrr  need_spacer'r(r*operator_typesrrrrrroptypes r="missing_whitespace_around_operatorr@Ns<FJ IIk8=1N.4MM* D%d  & &  ? " " aKFF S[[ aKF C #  T))*Q-)%a=DFFFF" j!8!8$$)@)@$$%%A%"$MMMMMM$&LD& C'''7 ff"-77'A f%a=3744+ABBBB" > ) )h.Bs{{v{,,,! (( ++ U0B0B,,X--(611#1)<<2"&J...! !'(9:  # 1 1 IIIII"   [MMr?c#(K|}t|D]r}|dz}d|vr"|d|dzfVQ|d|dzfVsdS)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) rrxzE242 tab after '%s'rzE241 multiple spaces after '%s'N)WHITESPACE_AFTER_COMMA_REGEXrrrp)rLrmrs r=whitespace_around_commarDs D ) 2 24 8 8JJ A  17799  .1== = = = =:QWWYYq\II I I I I JJr?c#Kd}d}d}d}d}tt|}d}d} |D]\} } } } }| tjkr|rd}| |kr||fV|rd}| |kr|| fV| tjkre| dvr|dz }nW| dvr|dz}nM|r| d kr |dkrd }n<|dkr | d krd}n-|r+| d kr%|r|dkrd }| |kr|| fVnd }| |kr||fV|sd}| }dS) 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): rFNz8E251 unexpected spaces around keyword / parameter equalsz/E252 missing whitespace around parameter equalsr"rz)]rTrr/)boolrrorrr)rLrr no_space require_spacer*annotated_func_argin_defmessagemissing_messagerrrrrs r=(whitespace_around_named_parameter_equalsrMs*FHMH &,,\:: ; ;FHGGO.4  * D%d  $ $   *H  ))))  2!M  1111  $ $t||! !  2DCKKFaKK%)""1%*"" 2DCKK%2&A++$(M(('9999#H(('1111 +%*"A  r?c#Kd}|D]\}}}}}|tjkr|d|d}|r-|d|dkr|d|ddzkr|dfV|d\} } } | dvo| d ddpd } |r| s| ddt vr|d fV| r'| d ks |ddkr| d kr|d fV| r|d fV|tjkr|}dS)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 commentr9z#:rz*E262 inline comment should start with '# '!z)E265 block comment should start with '# 'z+E266 too many leading '#' for block comment)rrr partitionrrr) rLrr*rrrrrinline_commentsymbolspcomment bad_prefixs r=whitespace_before_commentrVs.H.4* D%d ) ) )!)58)_2244N MA;%(**uQx(1+//I/I#KMMMM"&.."5"5 FBt+Os1C1CBQB1G1N3J ON! !:!:!MMMMM Os!2!2eAhll$$!LLLLLLO!NNNNN 8; & &H%r?c#K|}|dr/|d}d|krd|d|vr |dfVdSdSdSdS)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 rr;Nz!E401 multiple imports on one line)rfind)rLrrs r=imports_on_separate_linesr[Csx D y!!= # ::#T&5&\11<< < < < < <== :11r?c#Kd}d}|rdS|sdS|rdS|dsdr|ddrdVdSdStjtrdSt fd |DrdS|r$|d drd |d<dSd |d <dSd |d<dS) 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 Okay: try:\n\timport x\nexcept ImportError:\n\tpass\nelse:\n\tpass\nimport y Okay: try:\n\timport x\nexcept ImportError:\n\tpass\nfinally:\n\tpass\nimport y 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 c|ddvr |dd}|r|ddvr |dd}|o|ddkp |ddkS)NruUbBrrR"rrP)rs r=is_string_literalz8module_imports_on_top_of_file..is_string_literalms_ 7f  8D  DGtOO8D:aC947c>:r?)rErFrDrGrHrBrCNrXzfrom seen_non_importsF)rz+E402 module level import not at top of filec3BK|]}|VdSNr)r;kwrs r=r>z0module_imports_on_top_of_file..s/ < z'compound_statements..s + + +$dA + + +r?z{}[]()rr}rrr0rr)r/N)rz1E731 do not assign a lambda expression, use a def)rz*E704 multiple statements on one line (def)z,E701 multiple statements on one line (colon)rYz0E702 multiple statements on one line (semicolon)z$E703 statement ends with a semicolon)rrZ update_countsrr LAMBDA_REGEXsearchrrr isidentifierrro!STARTSWITH_INDENT_STATEMENT_REGEX)rLr last_charr prev_foundcounts lambda_kwrs r=compound_statementsr{so< DD A I IIcNNEJ + +( + + +F u y d:e+,f555 C[F3K ' ' C[F3K ' ' C[F3K ' '!V++eaiC''$++D!U;;I 0y000188::"##;#%%&"+*;*;*=*=*J*J*L*L%%%%%#))$// LEEEEE288>> LKKKKK  #uqy))' u y ( IIcNNE u** 9  KK K K K K?? ? ? ? #uqy)) u******r?c#Kdx}x}}d}d}|D]\}}} } } |tjkrd}| d|kr |r |r|s|dfV| d|krh| ddr3| dt | dd z f}nd}| dx}}n| d}|tjkr|d vr|d z }|d vr|d z}dS) 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\rrrr)rrrrr splitlinesr) rLr prev_startr*r rT backslashrrrrrs r=explicit_line_joinrs7$&'&J&FGI.4* D%d ) ) )G 8z ! !f ! !7 !OO O O O q6X  {{6""++D11 ! VS):):2)>%?%?!%CD  $'F *JqJ  $ $u}}! ! #r?z()[]{},:.;@=%~)z...c<|tjkp|dvo|tvS)N>r3r0)rr _SYMBOLIC_OPS)rrs r=_is_binary_operatorrs-hk!    M! r?c#Kd}d}d}d}|D]I\}}}}} |tjkrd|vsd|vr|tjkrd}4|||||||fV|dv}d}|}|}JdS)zPrivate function to reduce duplication. This factors out the shared details between :func:`break_before_binary_operator` and :func:`break_after_binary_operator`. FTNr|r}z([{,;)rrr) r line_break unary_contextprevious_token_type previous_textrrrrrs r=_break_around_binary_operatorsr sJMM.4 ! !* D%d ) ) )  DLLDDLLjHO.K.KJJt%8-}e5 5 5 5 GOMJ",  MM ! !r?c#Kt|D]6}|\}}}}}}} t||r|r|st||s| dfV7dS)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) rLrcontextrrrrrrrs r=break_before_binary_operatorr$s(2&99BB-4 +T. ]E  D 1 1 Bj B! B'(;(577 BAA A A ABBr?c#Kd}t|D]8}|\}}}}}} } t||r|r| st||s|dfV| }9dS)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) rLrrrrrrrrrrs r=break_after_binary_operatorrBs.J1&99-4 +T. ]E  3] C C F F! F( D99 FEE E E E r?c#xK|rdSt|D]}|dp|d}|ddk}d|rdnd|zz}|d vrd }nd }|d kr|p|d ko| }|d|rdndzz }|d|d|d|fVdS)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! Nrr rr.z'if cond is %s:'r^znot )rE711E712rrz or 'if %scond:'z comparison to z should be )COMPARE_SINGLETON_REGEXrrpr)rLrro singletonsamemsgrnonzeros r=comparison_to_singletonres$ (11,?? 7 7KKNN4ekk!nn  A$& 4%;RRVy$HI  ! !DDD!V+4;!W,9T  %w)BFC CCkk!nn $iii 67 7 7 7 7 7 7r?c#Kt|}|r>|d}|ddkr|dfVdS|dfVdSdS)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 rrr1z+E713 test for membership should be 'not in'z0E714 test for object identity should be 'is not'N)COMPARE_NEGATIVE_REGEXrtrrp)rLrors r=comparison_negativers # ) ), 7 7E Jkk!nn ;;q>>T ! !DD D D D D DII I I I I I JJr?c#Kt|}|rR|sR|d}|r|r |tvrdS|dfVdSdSdS)aObject type comparisons should always use isinstance(). Do not compare types directly. Okay: if isinstance(obj, int): E721: if type(obj) is type(1): When checking if an object is a string, keep in mind that it might be a unicode string too! In Python 2.3, str and unicode have a common base class, basestring, so you can do: Okay: if isinstance(obj, basestring): Okay: if type(a1) is type(b1): rNz-E721 do not compare types, use 'isinstance()')COMPARE_TYPE_REGEXrtrprurr)rLrroinsts r=comparison_typers  % %l 3 3E MTM{{1~~  D%%'' D ,B,B FkkmmLLLLLLL MMMMr?c#~K|rdSt|}|r|dfVdSdS)zWhen catching exceptions, mention specific exceptions when possible. Okay: except Exception: Okay: except BaseException: E722: except: NzE722 do not use bare 'except')BLANK_EXCEPT_REGEXror)rLrros r= bare_exceptrsZ   $ $\ 2 2E =kkmm<<<<<<<==r?c#Kd}d}d}|d\}}}}} |ddD]\} } } } }dx}}|dkrd}|dkr)|tjkr| tjkr | dkrd}n-|dkr'| tjkr| dkr|dz }n | d kr|dz}| tjkrd | vr|dkr||vr|}|}|d vr| |vr| }| }|r| |vr| }| }|d kr | |vr | d | zfV|dkr | |vr | d| zfV|r |d|zfV| }| }| }dS)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, '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: for a in foo(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): E742: class I(object): E743: def l(x): Fr)lOIrNr@Tr0rr/)asrAglobalnonlocalrIz$E742 ambiguous class definition '%s'z'E743 ambiguous function definition '%s'z!E741 ambiguous variable name '%s')rr%r)rLr is_func_defparameter_parentheses_levelidents_to_avoidr'r(rr*r)rrrrridentrs r=ambiguous_identifierrsDK"#%O5;AY2Iy*h.4QRRj++* D%d   K &! + +X]**hk))dckk*+ ' ' (1 , ,hk))s{{+q0+++q0+  $ $+q00O++!  ; ; ;&&  &&   &&CdJJJJJ   &&FMMMMM  C:UBB B B B   W++r?c#XK|d}|dkr |s |dfVdSdSdS)zThe {}.has_key() method is removed in Python 3: use the 'in' operator. Okay: if "alph" in d:\n print d["alph"] W601: assert d.has_key('alph') z .has_key(rz'W601 .has_key() is deprecated, use 'in'NrZ)rLrrs r=python_3000_has_keyrsK   K ( (C Rxxx<<<<<<<xxxr?c#Kt|}|r7t|s|dz dfVdSdSdS)zWhen raising an exception, use "raise ValueError('message')". The older form is removed in Python 3. Okay: raise DummyError("Message") W602: raise DummyError, "Message" rz)W602 deprecated form of raising exceptionN)RAISE_COMMA_REGEXroRERAISE_COMMA_REGEXr)rLros r=python_3000_raise_commar*sw  # #L 1 1E K(..|<<KiikkAoJJJJJJJKKKKr?c#PK|d}|dkr|dfVdSdS)zNew code should always use != instead of <>. The older syntax is removed in Python 3. Okay: if a != 'no': W603: if a <> 'no': r+rz!W603 '<>' is deprecated, use '!='NrrLrs r=python_3000_not_equalr8sC   D ! !C Rxx6666666xr?c#PK|d}|dkr|dfVdSdS)zfUse repr() instead of backticks in Python 3. Okay: val = repr(1 + 2) W604: val = `1 + 2` `rz+W604 backticks are deprecated, use 'repr()'Nrrs r=python_3000_backticksrFsC   C C Rxx@@@@@@@xr?c#K|rdSgd}|D]\\}}}}}|tjkrB|\} } |dddvr |ddn|d} || } |d| } | t | z}||t |  }d| vr|d}|dkr|d z }|||vrw| |d d|z}|| kr&| t | zt | z|z}n||d d|z d z }||d z fd ||zfV|d|d z}|dk^dS) zsInvalid escape sequences are deprecated in Python 3.6. Okay: regex = r'\.png$' W605: regex = '\.png$' N)r|r}rr`arfnrtv01234567xNrUz"""z'''rrr}rrr|z"W605 invalid escape sequence '\%s')rrrylowerrrZrr)rLrrvalidrrrrr start_line start_colquote quote_posprefixrrcols r=#python_3000_invalid_escape_sequencerRs    E*/555* D%d  ( ($) !J !%bccn! %d characters))setr7unionrraddr SKIP_TOKENSr~rqrrrMAX_DOC_LENGTH)rLmax_doc_lengthrr prev_token skip_linesrrrrrrline_numrKrr doc_errors r=maximum_doc_lengthrs'JJ.4!!* D%d ]00(/1BCC C C NN4 .4  * D%d  ( (Z (  (/8+;< < <!Z;%>%>))/8/?/?;;+HmQx(*a//DOOD4I4I/ //F*0022F!X%555KK1,, &VBZ 8> I I$6{{a''HqL3u::,E,EKK1,, &VBZ 8> I I$..%*1X%8.$I (+A"(.!9+:;;;; 5  r?cB tj|5}|cdddS#1swxYwYdS#ttt f$rCt|d5}|cdddcYS#1swxYwYYdSwxYw)zRead the source code.Nzlatin-1)encoding)ropen readlines LookupError SyntaxError UnicodeError)filenamers r=rr s3! ]8 $ $ !;;== ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! l 3!!! (Y / / / !1;;== ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !!sPA7 A;A;A(B,B BB BB BBcfttjjdS)zRead the value from stdin.ignore)errors)rrstdinbufferreadrPr?r=stdin_get_valuers& )( ; ; ; @ @ B BBr?iz# no(?:qa|pep8)\bc|d}d|vr1t|t|z Sd}|D] }|dkr |dzdzdz}|dkr|dz } |S)zReturn the amount of indentation. Tabs are expanded to the next multiple of 8. >>> expand_indent(' ') 4 >>> expand_indent('\t') 8 >>> expand_indent(' \t') 8 >>> expand_indent(' \t') 16 z rxrr*r9r)rrr)rresultrus r=rrs ;;v  D 44yy3t{{}}---- F 4<<q[1_q(FF S[[ aKFF  Mr?c||ddz}t|dz }|dddvr |dz }|dz}|d|d||z zz||dzS)zReplace contents with 'xxx' to prevent syntax matching. >>> mute_string('"abc"') '"xxx"' >>> mute_string("'''abc'''") "'''xxx'''" >>> mute_string("r'abc'") "r'xxx'" rrrNrrr)ryr)rrrs r= mute_stringr9s{ JJtBx 1 $E d))a-C BCCyN""   q <#u- -STT ::r?.cLi}dx}}|D]}|r|dddkr|dz}|dddkrht|}d|D\}}||t |||z|dddkrK|ddd dd }|dd d vr |d d}t||<fd |DS)z&Return a dictionary of matching lines.Nrr"r z@@ c38K|]}t|pdVdS)rN)int)r;gs r=r>zparse_udiff..Zs,GGaCSMMGGGGGGr?z+++rrxrr)zb/zw/zi/c|i|]8\}}|t|tj||9SrP)filename_matchospathjoin)r;filepathrowsparentpatternss r=rpzparse_udiff..csY    Xt  #8X66   VX&&   r?) r~ HUNK_REGEXrorupdaterrritems) diffr r rvrrr hunk_matchr s `` r= parse_udiffrMs_ BD5!!  BQBx3   8u  #))$//JGG:3D3D3F3FGGGLS% tHOOE#sU{33 4 4 4 4 "1"X  8>>$**1-DBQBx---ABBxuuBtH      "    r?cj|sgSt|tr|Sg}|dD]}|}d|vr=tjtj||}|| d|S)zQParse a comma-separated list of paths. Return a list of absolute paths. rr#) isinstancerrrrrabspathrrr)valuer pathsrs r=normalize_pathsrjs  % E C  ''zz|| $;;7??27<<#=#=>>D T[[%%&&&& Lr?TcB|s|Stfd|DS)z{Check if patterns contains a pattern that matches filename. If patterns is unspecified, this always returns True. c38K|]}t|VdSrdr)r;patternrs r=r>z!filename_match..s-BBgwx))BBBBBBr?)rj)rr rs` r=rr|s5  BBBBBBB B BBr?c8|D]}||vr||xxdz cc<dS)z^Adds one to the counts of each appearance of characters in s, for characters in countsrNrP)r<ryrus r=rrrrs= 6>> 4LLLA LLLr?c|dtvp1|d|ddddkS)Nrrr rz\ )rr)tokens r= _is_eol_tokenrs< 8w  K%(58A;<<"8"?"?"A"AV"KKr?cbeZdZdZ ddZdZdZdZdZdZ d Z d Z d Z d Z d ZddZdS)Checkerz;Load a Python source file, tokenize it, check coding style.Nc |t|j}n|rJd|_|j|_|j|_|j|_|j |_ |j |_ |j |_ d|_ |j |_ |j |_ |j|_||_i|_|d|_|pg|_n|dkr.d|_t%d|_ne|\ t)||_nM#t*$r9t-jdd\}}|jd||_g|_Yn wxYw||_|jr~t3|jdd}|dvrZ|d kr|jdd d|jd<n6|jddd d kr|jdd d|jd<|p|j|_|jj|_d|_dS) NFrr"Tr: r)r%rr u) StyleGuideoptions _io_errorphysical_checks_physical_checkslogical_checks_logical_checks ast_checks _ast_checksrrrrrrr_checker_statesrrr~rOSErrorrexc_info__name__ordreportr report_errorr) rerrr'r4kwargsexc_typeexcord0s r=rkzChecker.__init__s ? ((0GG  : ' 7&5"-&6%4".#0".   !  #DM"DJJ __#DM(**55d;;DJJ ] &x00    "%,..!"43$,$5!>!>!>!>  DJ : 6tz!}Q'((D~%%6>>$(JqM!""$5DJqMMZ]2A2&.88$(JqM!""$5DJqM.  K- s.DAEEc Ntjdd\}}t|jdkr+|jd}t|dkr |dd}nd}||d|dpdd|jd|jd|jdS) zCheck if the syntax is valid.Nrrr )rrrzE901 r#)rr1rrcr5r2report_invalid_syntax)rer7r8rts r=r;zChecker.report_invalid_syntaxs,..!,3 sx==1  Xa[F6{{Q!F &)VAY^!D("3DDsx{DD4 6 6 6 6 6r?c|j|jkrdS|j|j}|xjdz c_|j|ddtvr |d|_|S)z(Get the next line from the input buffer.r^rNr)rrrrrr)rers r=readlinezChecker.readlinesg  t/ / /2z$*+ A   #RaRJ(>(>#AwD  r?c`g}|D]%}|t||&||S)zRun a check plugin.)rgetattr)reraargument_names argumentsrSs r= run_checkzChecker.run_checksD " 2 2D   WT400 1 1 1 1ui  r?cRd|vr"|j|i|_dSdS)z5Prepare custom state for the specific checker plugin.rkN)r/ setdefaultrk)rerSr@s r=init_checker_statezChecker.init_checker_states6 n , ,!%!5!@!@r!J!JD    - ,r?c||_|jD]q\}}}||||||}|=|\}}||j||||dddkr |d|_rdS)z,Run all physical checks on a raw input line.NrE101r)rKr*rErBr5rrr)rerrSrar@rrtrs r=check_physicalzChecker.check_physicals!+/+@ / / 'D%  # #D. 9 9 9^^E>::F!!'!!$"2FD%HHH8v%%'+AwD$ / /r?cg}g}d}dx}x}}|jD]\}}} } } |tvr|sd| fg}|tjkr||?|tjkrt |}|rK| \} } || kr-|j|dz |dz }|dks|dvr |dvrd|z}n|| kr | || |z}|||t|z }||| f| \}}d ||_ |o!td ||_ |S) z!Build a logical line from tokens.rNrrz{[(rr9r^) rrrrrrrrrrrLr)relogicalcommentsrprev_rowprev_colmappingrrrrr start_rowrr(s r=build_tokens_linezChecker.build_tokens_lines(,,,8g26+ ' ' .JeS$[(( 'u:,X---%%%X_,,"4(( ;).&Iy(( $ 8a< 8A FI C''IU,B,B,0,=,="Tz** 23d:D NN4 c$ii F NNFC= ) ) )#& XxxGGG,,8bggh&7&7!8!8 r?c|j|}|sdSd|D}|dd\}}|j|dz }t |d||_|j|jkr |j|_|jdkr.t|j dd |j D]\}}}|jdkrtd|z| |||||pd D]r\} } t| t s4|t#j|| \} } | d| d| z| z f} || d| d| |s|j r+|j|_|j |_|js |j |_d|_g|_dS) z:Build a line from tokens and run all logical checks on it.Ncg|]\}}|SrPrP)r;rt_s r=rUz)Checker.check_logical..s;;;ifa6;;;r?rrrPrz rP)r4increment_logical_linerPrrrrrrrrLrr,rErBrtuplebisect bisect_leftr5rrrr) rerNmapping_offsetsrOrrrSrar@rtr token_offsetrs r= check_logicalzChecker.check_logicals **,,,((**  F;;7;;;!(AIZ A . )*ZiZ*@AA  t/ / / $ 0D  <1   $#CRC(//11 2 2 2+/+? E E 'D%|q  edl###  # #D. 9 9 9 $un E E K E E !&%00F)00B'1111)2%L#!!fc!fvo &DEF!!&)VAYeDDDD E   J)-):D &$($5D !$ J8<8I5 r?c td|jddt}n1#tt t f$r|cYSwxYw|jD]o\}}}|||j }| D]C\}}}} |jrt|j|dz s| |||| DpdS)z,Build the file's AST and run all AST checks.r^execrN) compilerr PyCF_ONLY_AST ValueErrorr TypeErrorr;r.rrunrr5) rerMrSclsr)checkerlinenortrras r= check_astzChecker.check_ast;s 02774:..FMJJDDK3 0 0 0--// / / / 0!- C CMD#rc$ ..G/6{{}} C C+ezCdj!.D)E)EC%%ffdEBBB C C Cs/2+A A c#K|jr%|ddd|jzttj|j} d}|D]`}|dd|jkrdS|dot|d|_||||V|d}adS#ttj f$r| YdSwxYw)z9Tokenize file, run physical line checks and yield tokens.rrzE902 %sr^rNr) r(r5rrgenerate_tokensr=rrmaybe_check_physicalr TokenErrorr;)retokengen prev_physicalrs r=rhzChecker.generate_tokensGs > K   aI$> J J J+DM:: )M! ) )8A;!111FF!!H7eAh ))%??? %a  ) )X01 ) ) )  & & ( ( ( ( ( ( )s B0)AB00*CCcBt|r@|ddkr||dS||ddS|dtjkrd|dvrt |drdSd|_|dd|_|\}}\}}}}|j|jdz d||z}|ddd D]*}||dz|xjdz c_+d |_dSdSdS) z9If appropriate for token, check current physical line(s).rr^rr|rNTrrF) rrHrrrrrrr)rerrlrSsrcrtrs r=rizChecker.maybe_check_physicalXsJ   ! #Qx2~~##M22222##E!H----- 1X ( (TU1X-=-= E!H~~ !DN$Qx{D (- %AsKQA*T-127F7;cAC $, & &##D4K000  A%   "DNNN3) (-=-=r?rc |j|j|j||t |j|_|jr|d|_d|_ dx|_ |_ d|_ d|_ g|_dx|_|_d}|D]t}|j||dd\}}|jdkr|dd|ddkr1d|ddpd|dd}nd|ddz}t+d |ddd |d t,j|dd ||t,jkr|d vr|dz }|d vr|dz}|s||t2vrs|t,jkr|d|_.t |jdkr|xjdz c_|jd=`|v|jr4||jd ||jS)z!Run all checks on the input file.rNr^rr z[{}:{}]rzl.%szl.rxrrr)r4 init_filerrrrr.rfrrrrrrrrrrrhrrrrrtok_namerrr[rHget_file_results)reexpected line_offsetr rrrrs r= check_allzChecker.check_alls dmTZ;OOOtz??    NN   9::D6 "02- /004,))++ - -E K  u % % %$QqSz J|q  8A;%(1+--#**58A;+<"eAhqkJJCC 58A;.CQx{{{CCC):58)D)D)DddLMMMX[((5==aKFFU]]aKF -((!X%555**,,,,-))T[))Q..((A-(( KNN**,,, ; !    2 / / /    {++---r?)NNNNNr)r2 __module__ __qualname__rirkr;r=rBrErHrPr[rfrhrirurPr?r=r!r!sEE,0&*,,,,\ 6 6 6!!!KKK / / /B!!!F C C C)))"&#&#&#P+.+.+.+.+.+.r?r!c^eZdZdZdZdZdZdZdZdZ dZ d Z dd Z dd Z dd ZdZdS) BaseReportz"Collect the results of the checks.Fc|j|_|j|_d|_d|_t |jd|_i|_ dSrv) benchmark_keys_benchmark_keys ignore_code _ignore_codeelapsed total_errorsdictfromkeyscountersmessages)rer's r=rkzBaseReport.__init__sJ&5#/  d&:A>>  r?c6tj|_dS)zStart the timer.N)time _start_timeres r=rzBaseReport.starts9;;r?cFtj|jz |_dS)zStop the timer.N)rrrrs r=stopzBaseReport.stopsy{{T%55 r?c||_||_|pd|_||_d|_|jdxxdz cc<|jdxxt |z cc<dS)Signal a new file.rPrr5rr7N)rrrsrt file_errorsrr)rerrrsrts r=rpzBaseReport.init_filest    B & g!# &'''3u::5'''''r?c0|jdxxdz cc<dS)zSignal a new logical line.r6rN)rrs r=rUz!BaseReport.increment_logical_lines& o&&&!+&&&&&r?cX|dd}||rdS||jvr|j|xxdz cc<nd|j|<|dd|j|<||jvrdS|jr|jst |j|xjdz c_|xjdz c_|S)&Report an error, according to options.Nrr) rrrrsprint_filenamerrrr)rerrtrrars r=rzBaseReport.errorsBQBx   T " "  F 4= M$   1 $    "#DM$ "&qrr(DM$  4= F   !t'7 ! $-  A Q r?c|jS)z6Return the count of errors and warnings for this file.)rrs r=rrzBaseReport.get_file_resultss r?r^cHtfdjDS)z.Return the total count of errors and warnings.c3\K|]&}|j|V'dSrd)rrr;keyrres r=r>z'BaseReport.get_count..sWGGs~~f/E/EG4=%GGGGGGr?)sumrrers``r= get_countzBaseReport.get_countsNGGGGG"mGGGGG Gr?cHfdtjDS)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 c|g|]8}|j|dd|dj|9S)rr9)rrrrs r=rUz-BaseReport.get_statistics..seLLLCNN64J4JL c 2 2 2 2CCCs9K9KLLLLr?)sortedrrs``r=get_statisticszBaseReport.get_statisticssGLLLLL!$-00LLL Lr?cT||D]}t|dS)z9Print overall statistics (number of errors and warnings).N)rr)rerrs r=print_statisticszBaseReport.print_statisticss6''//  D $KKKK  r?ctd|jd|jr=|jD]7}td|j||jz ||j|fz6dSdS)zPrint benchmark numbers.z {:<7.2f} {}zseconds elapsedz%-7d %s per second (%d total)N)rrrr}r)rers r=print_benchmarkzBaseReport.print_benchmarks m""4<1BCCDDD < ,+ , ,5}S)DL8#}S)++,,,, , , , ,r?Nr^)r2rwrxrirrkrrrprUrrrrrrrrPr?r=rzrzs,,N'''666666,,,&   GGGG L L L L ,,,,,r?rzceZdZdZdZdS) FileReportz:Collect the results of the checks and print the filenames.TN)r2rwrxrirrPr?r=rr sDDNNNr?rc<eZdZdZfdZfdZfdZdZxZS)StandardReportz,Collect and print the results of the checks.c t|t|j|j|_|j|_|j |_ |j |_ dSrd) superrk REPORT_FORMATrrr_fmtrepeat_repeat show_source _show_source show_pep8 _show_pep8rer' __class__s r=rkzStandardReport.__init__ si !!!!%%gn&:&:&<&<&-n66 ~ #/!+r?cZg|_t||||S)r)_deferred_printrrp)rerrrsrtrs r=rpzStandardReport.init_file s0!ww  eX{44 4r?ct||||}|rD|j|dks|jr,|j||||dd|jf|S)rrrN)rrrrrrri)rerrtrrarrs r=rzStandardReport.error szww}}[&$>>  FT]4(A---  ' 'fdDHemD F F F r?c X|j|jD]\}}}}}t|j|j|j|z|dz||dz|jrz|t|jkrd}n|j|dz }t| ttj dd|d|dz|j r&|r$td| ztj|jS) z9Print results and return the overall count for this file.r)rr rrrr^z\Sr9Nr%z )rsortrrrrtrrrrrhsubrrrstdoutflushr)rerrtrrdocrs r=rrzStandardReport.get_file_results' s8 !!###484H   0KtS $) '+5fqjd      ?TZ00DD:kAo6Ddkkmm$$$bfUCgvg77#=>>> ,3 ,fsyy{{*+++ J      r?) r2rwrxrirkrprrr __classcell__rs@r=rr s66,,,,,44444        r?rc,eZdZdZfdZfdZxZS) DiffReportz9Collect and print the results for the changed lines only.cbt||j|_dSrd)rrkselected_lines _selectedrs r=rkzDiffReport.__init__G s) !!! /r?cx||j|jvrdSt||||Srd)rrrr)rerrtrrars r=rzDiffReport.errorK s8 dnT]; ; ; Fww}}[&$>>>r?)r2rwrxrirkrrrs@r=rrD sWCC00000?????????r?rcJeZdZdZdZd dZd dZd dZdZd d Z d Z d Z dS)r&z-Initialize a PEP-8 instance with few options.cX|dt|_|dd}|dd}|dd}t|i|}|rdn|dd}|dd}t |||||\} |_|r+| j|d|vr |d|_|j |_ | |_ | j s| j rtnt| _ t!| jpd| _| jsI| jsB| js;| js4t*r-t!t*d | _n"| jrd nt!| j| _t.dd| _|j| _|d | _|d | _|d | _|dS)N checker_class parse_argvF config_fileparserrrrPrrrKrLrM)rr!rrrprocess_optionsr__dict__r  input_filerunnerr'reporterquietrzrrVselectrrdoctestDEFAULT_IGNORErBENCHMARK_KEYSr|r~ get_checksr)r+r- init_report) rercr6rrr options_dictarglistrr's r=rkzStyleGuide.__init__T s#ZZAAZZ e44 jj66 Hd++T,V,, $I$$,*:*:7D*I*I""9d33- Zfg??  3   # #L 1 1 1,&&)'2 o   O-4]NzzG w~344 P'. P! P%,_ P:H P#>#7#7#<#<==GNN'.nOUU%:O:OGN!/!2"."&///"B"B!%!@!@!__V44 r?Ncf|p |jj|j|j_|jjS)zInitialize the report instance.)r'rr4)rers r=rzStyleGuide.init_reportz s-@x@4<+@$,OO |""r?c||j}|jj}|j}| |D]W}t j|r||7| |s ||Xn#t$rtdYnwxYw| |S)zRun all checks on the paths.Nz ... stopped) rr'r4rrrrisdir input_direxcludedKeyboardInterruptrr)rerr4rrs r= check_fileszStyleGuide.check_files s =JE$  ! ! !7==&&!NN4((((t,,!F4LLL  ! ! ! ! ! -  !  sAB B)(B)rc|jjrtd|z||||j}|||S)z'Run all checks on a Python source file.z checking %s)rr')rsrt)r'rrrru)rerrrsrtfcheckers r=rzStyleGuide.input_file s^ <  , -(* + + +%% E4<&99!!8!MMMr?cx|d}||rdS|jjj}|jj}|jj}|j}tj |D]\}}}|rtd|z|dxxdz cc<t|D]-} || |r| | .t|D]Q} t| |r?|| |s)|tj|| RdS)z9Check all files in this directory and all subdirectories.r#rz directory r4rN)rrr'r4rrrrrwalkrrremoverrr) redirnamerr filepatternsrrootdirsr5subdirrs r=rzStyleGuide.input_dir sZ..%% == ! ! 1<&/,&|, !#!1!1 9 9 D$ +lT)*** ] # # #q ( # # # ,, ( (==..(KK'''"5MM 9 9#8\::9 h559F27<<h77888  9 9 9r?cJ|jjsdStj|}t ||jjrdS|r tj||}tj|}t ||jjS)zxCheck if the file should be excluded. Check if 'options.exclude' contains a pattern matching filename. FT)r'excluderrbasenamerrr)rerr rs r=rzStyleGuide.excluded s |# 57##H-- (DL$8 9 9 4  6w||FH55H7??8,,h (<===r?ctdkr'tfd|jjDrdS|jjo|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. rc3BK|]}|VdSrdre)r;r<rs r=r>z)StyleGuide.ignore_code.. sC!?!?%&"#d!3!3!?!?!?!?!?!?r?F)rrjr'rrr)rers `r=r~zStyleGuide.ignore_code s t99q==S!?!?!?!?*.,*=!?!?!???=5 3449OODL$7888 :r?cg}t|D]B\}}|\}}tfd|Dr||j||fCt |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. c3HK|]}|o| VdSrd)r~)r;rres r=r>z(StyleGuide.get_checks.. s9KKT7!1!1$!7!78KKKKKKr?)r_rrjrr2r)re argument_namechecksraattrsrbrcs` r=rzStyleGuide.get_checks s #M288:: = =LE5!MUDKKKKUKKKKK = u~ud;<<<f~~r?rd)NNr) r2rwrxrirkrrrrrr~rrPr?r=r&r&Q s77$$$L#### $NNNN9990 > > > > : : :     r?r&ct||d}gd|_|ddddd |d d ddd |d dddd |dddd|ddtd|dddd|ddd d!|d"dd d#tz|d$dd%&|d'dd(&|d)dd*&|d+dd,&|d-d.d/t d01|d2d.d/d3d41|d5d.d/t d61|d7dd8&|d9d:d;d<|d=dd>&|d?}tj tr0|d@dAdBC|dDddE&|dFddG&|S)Hz"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 --excluder z[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--selectrr^z&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))typerrrz--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 --testsuitedirzrun regression tests from dir)rrz --doctestzrun doctest on myselfz --benchmarkzmeasure processing speed) rconfig_options add_optionDEFAULT_EXCLUDErMAX_LINE_LENGTH INDENT_SIZEadd_option_grouprrexistsTESTSUITE_PATH)rrrrps r= get_parserr  s tW ;===FFFFF dK7EGGG dIqHJJJ dJ\NPPP i H@BBB k:JKKK lJ1222 j(BCEEE j(B+-;<=== ol<>>> mL/000 n\6888 i /000 )s-1222 (uc"ABBB oE3)1222 &|CDDD j(IKMMM h|@AAA  # #$5 6 6E w~~n%%7 =  ? ? ? \5  7 7 7 ]<4666 Mr?c ~t}|j}tj}tr\tjtr8|jrtdtz| t|o;tj tj |x}|rf| fdtDr}|jrtdzn$tj \}|f|rMtj|r.|jrtd|z| |d}||jr|j}n+|drd}t!jd|r`d|jD} |g\} } ||D]} | d d |jvrtd | z3|jd kr7td | ||| | d d } | | }|dvr||| }nG|dvr||| }n,||| }| dkrt7||}t9| | |||| \}} dx|_|_|S)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: %sc3XK|]$}tj|V%dSrd)rrr)r;fnr s r=r>zread_config..9 s3IIBrw||FB//IIIIIIr?zlocal configuration: in %szcli configuration: %sNpep8z0[pep8] section is deprecated. Use [pycodestyle].c6i|]}|j|jp|jSrP)rrrr;os r=rpzread_config..M s%NNNaqvqv1NNNr?rSr"z unknown option '%s' ignoredrz {} = {})rr)rrr)rYF)rconfigrcurdir USER_CONFIGrisfilerrrr commonprefixPROJECT_CONFIGr has_sectionrwarningswarn option_list parse_argsr'r:rrrgetint getbooleanrsetattrrr)r'rcrrrcli_conf local_dirtailpycodestyle_sectionr new_optionsr)optnormalized_optopt_typerr s @r= read_configr)! sc  F~H I!rw~~k22! ? : *[8 9 9 9 K   HRW__RW-A-A$-G-GHHHFT / ;;IIII.III I I I =2V;<<< v.. /BGNN8,, ? 6 )H4 5 5 5 H &+&&J$k   F # #J$ HIIIGNN6;MNNN #--b11b>>"566 8 8C{{3$$F,AAA5;<<<""k(()/4G)M)MOOPPP [[c22N">2H+++ &93??:::))*=sCC #6<<!Y..+E9==E K 7 7 7 7))'+)FF "*//GOg' Nr?Fc 4|st}|dsT|dd|jdd|jd}|dd|d |s|sg}||\}}d |_|||_ | d d r| |j n| dd sm|r@|s>|j stdtDrdg}n|dt#||||}|o|jdkot&|_t)|j|_t-|j|_t)|j|_t)|j|_|j rOt4|_t7}t9||j|d|_t=|j}||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, r) descriptionrzuser config file locationrNrFrc3TK|]#}tj|V$dSrd)rrr )r;rSs r=r>z"process_options.. sD#?#?'+$&7>>$#7#7#?#?#?#?#?#?r?zinput not specifiedrr)r  has_optionrrrrrrrr ensure_valuerrrrjrrr)rr_parse_multi_optionsrrrrrrrrrr) rrrrrrpr'rcrs r=rrl sN    Z ( (;''[[[$))F$9:::: <(>> V[9  ; ; ; :''00OWdG!K// L G%&&&&  ! !)U 3 3L  4d 4| 4s#?#?/=#?#?#? ? ? 4u 2333gtWf==%K'-1*<K+G,<==G%go66GO)'.99GN)'.99GN|.%!!!,UG4Dd1g!N!Ng,-- D=r?rcH|rd||DS|S)zgSplit and strip and discard empties. Turns the following: A, B, into ["A", "B"] c^g|]*}||+SrP)rrs r=rUz(_parse_multi_options.. s-KKKaK KKKr?)r)r' split_tokens r=r0r0 s1KK7==#=#=KKKKr?c`ddl} ||jdn#t$rYnwxYwtd}|j}|js|jrddlm}||}n| }|j r| |j r| |jr|js||jrQ|jr4t$jt+|jdzt%jddSdS) z.Parse options and run checks on Python source.rNc*tjdS)Nr)rexit)signumframes r=z_main.. sCHQKKr?T)r) run_testsr|r)signalSIGPIPEAttributeErrorr&r'rrtestsuite.supportr:rrr benchmarkrr print_resultsrrrstderrwriterr6)r; style_guider'r:r4s r=_mainrD seMMM  fn&G&GHHHH      ---K!G+'++//////;''((**"!!!!     = > J  S!455< = = =  s # 00__main__rd)Nr)T)NFNNN)r)rirWrVrrrhrrrrr functoolsroptparser configparserrior ImportError ConfigParserrcallabler?r __version__rrplatformr expanduserrrgetenvrr__file__r rrrrrr_ frozensetrkwlistr;r:r8rr<ASSIGNMENT_EXPRESSION_OPr9rrrINDENTDEDENTrr ERRORTOKENr7rr^rnrrrgrrrBrrrrr-rsr rrrrvrirr_r[rlrvrzrrrrrrrrrrr r+r.r@rDrMrVr[rmr{rrrrrrrrrrrrrrrrrrrrrrtrrrrrrrrrrr!rzrrrr&r r)rr0rDr2rPr?r=rXs` 8*  !!!!!!-,,,,,,       ---,,,,,,,,- 7"":t4455 #$ H$566H ;9  |wg(():;; gll BI' ( ( KBG,>,>{,K,K   KKK*bgooh77EE   <5  Y000 1 1 9W^w&88 9 9J F)77788 ???@@ %++,L,L,LMM%(%5%?%?D66Ri!#!#!# ! Yy ! ! )X[("23 4 4mmX_ho>?? !!8#3X5H"IJJ LLLrz+&& BJ122 bj!@AA"*.//"*\**(bj)KLL)rz*>??$"*&FGG#%122RZ!?@@ 2TYYx5H5HHII IJJrz-(( RZE F F !rz"9::'RZ(NOO$.BJ""C""" % %!rzJKK RZ ..B ? ?BBB.MMM(DDD<<<* D D D HHHJ : : :FR/R/R/j>>>@GGG.DDD,EEE:&1&1&1RKEKEKE\$$$NHHH.ooodJJJ$>>>B)))X===&717171t<*<*<*~%%%V *++ii.A.AA !!!4BBB:D!7!7!7HJJJ*MMM. = = = PPPf = = = K K K 7 7 7AAA858585vB B B L, , , h!!!CCC yy~~jbj!5rt<<CDD8;;;(:#%)$CCCCLLLT.T.T.T.T.T.T.T.nW,W,W,W,W,W,W,W,t 3 3 3 3 3 Z3 3 3 l ? ? ? ? ? ? ? ?GGGGGGGGT";CCCCLHHHVAE)-4444n     D z EGGGGGs$ A AAA)DDD