§ |<ˆji=ã óŽ—dZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z ddlm Z ddlm Z ddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZdZeje¦«ZGd„dej¦«ZGd„dej¦«Z Gd„dej¦«Z!de e e"de e e"dee"dffd„Z#de e e"dee"dfde e"de e e"dee"dff d„Z$Gd„d ¦«Z%Gd!„d"¦«Z&Gd#„d$¦«Z'dS)%z0Implementation of the StyleGuide used by Flake8.éN)ÚDict)Ú Generator)ÚList)ÚOptional)ÚSequence)ÚSet)ÚTuple)ÚUnion)Údefaults)Ú statistics)Úutils)Úbase)Ú Violation)Ú StyleGuidecó—eZdZdZdZdZdS)ÚSelectedzØÔ(ð$ ñ$ ô$ ˆÔ õ#5Ø”>ØÔ(ð# ñ# ô# ˆÔõ 'Ø”>Ý”OØ$Ô<ØÔ(ð  ñ ô ˆŒ õ &Ø”>Ý”OØ$Ô<ØÔ(ð  ñ ô ˆŒ ˆ ˆ rÚcodecó²—| |j¦«r tjS| |j¦«r tjSt jS)a˜Determine if the code has been selected by the user. :param code: The code for the check that has been run. :returns: Selected.Implicitly if the selected list is empty, Selected.Explicitly if the selected list is not empty and a match was found, Ignored.Implicitly if the selected list is not empty but no match was found. )Ú startswithr7rrr=rr©rArCs rÚ was_selectedzDecisionEngine.was_selectedksL€ð �?Š?˜4Ô3Ñ 4Ô 4ð &ÝÔ&Ð &Ø �_Š_˜Tœ]Ñ +Ô +ð &ÝÔ&Ð &åÔ%Ð %rcó²—| |j¦«r tjS| |j¦«r tjSt jS)a Determine if the code has been ignored by the user. :param code: The code for the check that has been run. :returns: Selected.Implicitly if the ignored list is empty, Ignored.Explicitly if the ignored list is not empty and a match was found, Selected.Implicitly if the ignored list is not empty but no match was found. )rEr:rrr@rrrFs rÚ was_ignoredzDecisionEngine.was_ignored}sL€ð �?Š?˜4Ô2Ñ 3Ô 3ð 'ÝÔ%Ð %Ø �_Š_˜Tœ\Ñ *Ô *ð 'ÝÔ%Ð %åÔ&Ð &rcóꇗ| ‰¦«}| ‰¦«}t d‰||¦«t |t ¦«r!t |t ¦«r t jSt |t¦«r!t |t¦«r t jS|t jur|tjur t jS|t jur|tjur t jS|tj ur|t j ur t jS|t jur|tjus|t j ur†|tj urxtˆfd„|j D¦«¦«}tˆfd„|j D¦«¦«}t|¦«t|¦«kr t jSt jStd‰›d|›d|›�¦«‚)z-Decide if code should be ignored or selected.z#The user configured %r to be %r, %rc3óF•K—|]}‰ |¦«¯|V—ŒdS©N©rE©Ú.0ÚsrCs €rú z/DecisionEngine.make_decision..±s4øèè€ÐIÐI °d·o²oÀaÑ6HÔ6HÐI˜!ÐIÐIÐIÐIÐIÐIrc3óF•K—|]}‰ |¦«¯|V—ŒdSrLrMrNs €rrQz/DecisionEngine.make_decision..²s4øèè€ÐHÐH °T·_²_ÀQÑ5GÔ5GÐH˜!ÐHÐHÐHÐHÐHÐHrz unreachable ú )rGrIÚLOGÚdebugÚ isinstancerr rrrÚnextr=r@ÚlenÚAssertionError)rArCr=r@r5r8s ` rÚ make_decisionzDecisionEngine.make_decision�sçø€à×$Ò$ TÑ*Ô*ˆØ×"Ò" 4Ñ(Ô(ˆÝ � Š Ø 1Ø Ø Ø ñ  ô ð õ �h¥Ñ )Ô )ð M­j¸Å(Ñ.KÔ.Kð MÝÔ$Ð $Ý ˜¥'Ñ *Ô *ð M­z¸'Å7Ñ/KÔ/Kð MÝÔ#Ð #à �Ô+Ð +Ð +Ø�wÔ1Ð1Ð1åÔ$Ð $à �HÔ/Ð /Ð /Ø�7Ô-Ð-Ð-åÔ#Ð #Ø �Ô+Ð +Ð +°½8Ô;NÐ0NÐ0NÝÔ#Ð #à �Ô+Ð +Ð +°½7Ô;MÐ0MÐ0Mà �Ô+Ð +Ð +°½7Ô;MÐ0MÐ0MõÐIÐIÐIÐI T¤]ÐIÑIÔIÑIÔIˆFÝÐHÐHÐHÐH T¤\ÐHÑHÔHÑHÔHˆFÝ�6‰{Œ{�S ™[œ[Ò(Ð(ÝÔ(Ð(åÔ'Ð'å Ð!K°Ð!KÐ!K°xÐ!KÐ!KÀ'Ð!KÐ!KÑLÔLÐ Lrcó´—|j |¦«}|€;| |¦«}||j|<t d||¦«|S)aÞReturn the decision for a specific code. This method caches the decisions for codes to avoid retracing the same logic over and over again. We only care about the select and ignore rules as specified by the user in their configuration files and command-line flags. This method does not look at whether the specific line is being ignored in the file itself. :param code: The code for the check that has been run. Nz"%s" will be "%s")r4ÚgetrZrTrU)rArCÚdecisions rÚ decision_forzDecisionEngine.decision_forºsX€ð”:—>’> $Ñ'Ô'ˆØ Ð Ø×)Ò)¨$Ñ/Ô/ˆHØ'ˆDŒJ�tÑ Ý �IŠIÐ)¨4°Ñ :Ô :Ð :؈r)rrrrÚargparseÚ NamespacerBÚstrr rrrGrIr rZr^rrrr1r1Js怀€€€ððð   Ô 2ð °tð ð ð ð ð4& ð&¨¨x¸Ð/@Ô)Að&ð&ð&ð&ð$' ð'¨¨h¸Ð.?Ô(@ð'ð'ð'ð'ð&(M #ð(M¨(ð(Mð(Mð(Mð(MðT ð¨ððððððrr1có—eZdZdZ ddejdejdee ddfd„Z dejde dfd „Z d e dd fd „Zejd e de dfd „¦«Z dde d e dedede dee defd„Zdee eefddfd„ZdS)ÚStyleGuideManagerz.Manage multiple style guides for a single run.Nr2Ú formatterÚdeciderr#có–—||_||_tj¦«|_|pt |¦«|_g|_t|||j|¬¦«|_ ttj |j g|  |¦«¦«¦«|_tjd¬¦«|j¦«|_dS)úSInitialize our StyleGuide. .. todo:: Add parameter documentation. )reN)Úmaxsize)r2rdr Ú StatisticsÚstatsr1reÚ style_guidesrÚdefault_style_guideÚlistÚ itertoolsÚchainÚpopulate_style_guides_withÚ functoolsÚ lru_cacheÚ_style_guide_forÚstyle_guide_for)rAr2rdres rrBzStyleGuideManager.__init__Òs΀ðˆŒ Ø"ˆŒÝÔ*Ñ,Ô,ˆŒ ØÐ9¥.°Ñ"9Ô"9ˆŒ Ø.0ˆÔÝ#-Ø �Y ¤ °Gð$ ñ$ ô$ ˆÔ õ!Ý ŒOØÔ)Ð*Ø×/Ò/°Ñ8Ô8ñ ô ñ ô ˆÔð A�yÔ2¸4Ð@Ñ@Ô@Ø Ô !ñ ô ˆÔÐÐr©rNNc#óˆK—tj|j¦«}|D]#\}}|j ||¬¦«V—Œ$dS)z÷Generate style guides from the per-file-ignores option. :param options: The original options parsed from the CLI and config file. :returns: A copy of the default style guide with overridden values. )ÚfilenameÚextend_ignore_withN)r Úparse_files_to_codes_mappingÚper_file_ignoresrlÚcopy)rAr2Úper_filerwÚ violationss rrpz,StyleGuideManager.populate_style_guides_withïsmèè€õÔ5°gÔ6NÑOÔOˆØ$,ð ð Ñ ˆH�jØÔ*×/Ò/Ø!°jð0ñôð ð ð ð ð ð rrwrcóJ‡—tˆfd„|jD¦«d„¬¦«S)z3Find the StyleGuide for the filename in particular.c3óF•K—|]}| ‰¦«¯|V—ŒdSrL)Ú applies_to)rOÚgrws €rrQz5StyleGuideManager._style_guide_for..s4øèè€Ð DÐ D�1¨Q¯\ª\¸(Ñ-CÔ-CÐ DˆQÐ DÐ DÐ DÐ DÐ DÐ Drcó.—t|jpd¦«S)NÚ)rXrw)r�s rúz4StyleGuideManager._style_guide_for..s€�#˜aœjÐ.¨BÑ/Ô/€r)Úkey)Úmaxrk©rArws `rrsz"StyleGuideManager._style_guide_forÿs:ø€åØ DÐ DÐ DÐ D˜Ô)Ð DÑ DÔ DØ/Ð/ð ñ ô ð rc#ó˜K—| |¦«}| |¦«5|V—ddd¦«dS#1swxYwYdS©z9Record the fact that we're processing the file's results.N)rtÚprocessing_file)rArwÚguides rrŠz!StyleGuideManager.processing_filesœèè€ð ×$Ò$ XÑ.Ô.ˆØ × "Ò " 8Ñ ,Ô ,ð ð ØˆKˆKˆKð ð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð s­?¿AÁArCÚ line_numberÚ column_numberÚtextÚ physical_linecó`—| |¦«}| ||||||¦«S)áþHandle an error reported by a check. :param code: The error code found, e.g., E123. :param filename: The file in which the error was found. :param line_number: The line number (where counting starts at 1) at which the error occurs. :param column_number: The column number (where counting starts at 1) at which the error occurs. :param text: The text of the error message. :param physical_line: The actual physical line causing the error. :returns: 1 if the error was reported. 0 if it was ignored. This is to allow for counting of the number of errors found that were not ignored. )rtÚ handle_error)rArCrwrŒr�rŽr�r‹s rr’zStyleGuideManager.handle_errors<€ð:×$Ò$ XÑ.Ô.ˆØ×!Ò!Ø �(˜K¨¸¸mñ ô ð rÚdiffinfocóD—|jD]}| |¦«ŒdS)a5Update the StyleGuides to filter out information not in the diff. This provides information to the underlying StyleGuides so that only the errors in the line number ranges are reported. :param diffinfo: Dictionary mapping filenames to sets of line number ranges. N)rkÚadd_diff_ranges)rAr“r‹s rr•z!StyleGuideManager.add_diff_ranges1s7€ðÔ&ð ,ð ,ˆEØ × !Ò ! (Ñ +Ô +Ð +Ð +ð ,ð ,rrL)rrrrr_r`Úbase_formatterÚ BaseFormatterrr1rBrrprarsÚ contextlibÚcontextmanagerrŠÚintr’rrr•rrrrcrcÏsˆ€€€€€Ø8Ð8ð -1ð  ð àÔ#ð ð"Ô/ð ð˜.Ô)ð  ð ð  ð ð ð ð:ØÔ)ðà Ð+Ô ,ððððð  ¨ð °ð ð ð ð ðÔðØðà Ð+Ô ,ðððñÔðð(,ð  ð  àð  ðð  ðð  ð ð  ð ð  ð  ”}ð  ð ð  ð  ð  ð  ðD ,¨¨S°#°c´(¨]Ô(;ð ,Àð ,ð ,ð ,ð ,ð ,ð ,rrccój—eZdZdZ ddejdejdej de e de e f d„Z d e fd „Z dde e d e ee d dfd „Zejde d ed fd„¦«Zde d efd„Zde d efd„Z dde de dedede de e d efd„Zdee eefd dfd„ZdS)rz#Manage a Flake8 user's style guide.Nr2rdrjrwrecó—||_||_||_|pt|¦«|_||_|jrt j|j¦«|_i|_dS)rgN) r2rdrjr1rerwr Únormalize_pathÚ _parsed_diff)rAr2rdrjrwres rrBzStyleGuide.__init__Asa€ðˆŒ Ø"ˆŒØˆŒ ØÐ9¥.°Ñ"9Ô"9ˆŒ Ø ˆŒ Ø Œ=ð @Ý!Ô0°´Ñ?Ô?ˆDŒMØ13ˆÔÐÐrr#có—d|j›d�S)z5Make it easier to debug which StyleGuide we're using.z ©rw)rAs rÚ__repr__zStyleGuide.__repr__Vs€à0˜tœ}Ð0Ð0Ð0Ð0rrxcóÔ—|p|j}tj|j¦«}|jpg|_|j |pg¦«t ||j|j|¬¦«S)z8Create a copy of this style guide with different values.r ) rwr{Údeepcopyr2r9r"rrdrj)rArwrxr2s rr{zStyleGuide.copyZsr€ð Ð,˜tœ}ˆÝ”- ¤ Ñ-Ô-ˆØ 'Ô 5Ð ;¸ˆÔØÔ×$Ò$Ð%7Ð%=¸2Ñ>Ô>Ð>ÝØ �T”^ T¤Z¸(ð ñ ô ð rruc#ózK—|j |¦«|V—|j |¦«dSr‰)rdÚ beginningÚfinishedr‡s rrŠzStyleGuide.processing_filehsCèè€ð Œ× Ò  Ñ*Ô*Ð*؈ ˆ ˆ Ø Œ×Ò Ñ)Ô)Ð)Ð)Ð)rcó`—|j€dStj||jg|›d�t¬¦«S)aCheck if this StyleGuide applies to the file. :param filename: The name of the file with violations that we're potentially applying this StyleGuide to. :returns: True if this applies, False otherwise NTz! does %(whether)smatch "%(path)s")ÚpatternsÚ log_messageÚlogger)rwr Úmatches_filenamerTr‡s rr€zStyleGuide.applies_toqsD€ð Œ=Ð Ø�4ÝÔ%Ø Ø”m�_ØÐDÐDÐDÝð  ñ ô ð rrCcó6—|j |¦«S)a”Determine if the error code should be reported or ignored. This method only cares about the select and ignore rules as specified by the user in their configuration files and command-line flags. This method does not look at whether the specific line is being ignored in the file itself. :param code: The code for the check that has been run. )rer^rFs rÚshould_report_errorzStyleGuide.should_report_errorƒs€ðŒ|×(Ò(¨Ñ.Ô.Ð.rrŒr�rŽr�cóz—|jj}|sd}t||||dz||¦«}| |j¦«t ju} | |¦«du} | |j ¦«} | r:| r8| r6|j   |¦«|j   |¦«dSdS)r‘réF)r2Ú disable_noqarr­rCr rÚis_inline_ignoredÚis_inržrdÚhandlerjÚrecord) rArCrwrŒr�rŽr�r°ÚerrorÚerror_is_selectedÚis_not_inline_ignoredÚis_included_in_diffs rr’zStyleGuide.handle_error‘sã€ð:”|Ô0ˆ ðð ØˆMÝØ Ø Ø Ø ˜AÑ Ø Ø ñ  ô ˆð × $Ò $ U¤ZÑ 0Ô 0µHÔ4EÐ Eð ð!&× 7Ò 7¸ Ñ EÔ EÈÐ NÐØ#Ÿkšk¨$Ô*;Ñ<Ô<ÐØ ð Ð!6ð Ð;Nð Ø ŒN× !Ò ! %Ñ (Ô (Ð (Ø ŒJ× Ò ˜eÑ $Ô $Ð $Ø�1؈qrr“có—||_dS)a(Update the StyleGuide to filter out information not in the diff. This provides information to the StyleGuide so that only the errors in the line number ranges are reported. :param diffinfo: Dictionary mapping filenames to sets of line number ranges. N)rž)rAr“s rr•zStyleGuide.add_diff_rangesÆs€ð%ˆÔÐÐr)NNrL)rrrrr_r`r–r—r rirrar1rBr¡rr{r˜r™rrŠÚboolr€r r­ršr’rrr•rrrrr>sö€€€€€Ø-Ð-ð#'Ø,0ð 4ð4àÔ#ð4ð"Ô/ð4ðÔ$ð 4ð ˜3”-ð 4ð ˜.Ô)ð 4ð4ð4ð4ð*1˜#ð1ð1ð1ð1ð #'Ø6:ð  ð  à˜3”-ð  ð% X¨c¤]Ô3ð  ð ð  ð  ð  ð  ðÔð*Øð*à Ð+Ô ,ð*ð*ð*ñÔð*ð  3ð ¨4ð ð ð ð ð$ /¨ð /°ð /ð /ð /ð /ð*(,ð3ð3àð3ðð3ðð 3ð ð 3ð ð 3ð  ”}ð3ð ð3ð3ð3ð3ðj %¨¨S°#°c´(¨]Ô(;ð %Àð %ð %ð %ð %ð %ð %rr)(rr_r˜r{ÚenumrqrnÚloggingÚtypingrrrrrrr r Úflake8r r r Úflake8.formattingrr–Úflake8.violationrÚ__all__Ú getLoggerrrTÚEnumrrr rar+r/r1rcrrrrúrÄs*ðØ6Ð6Ø€€€ØÐÐÐØ € € € Ø € € € ØÐÐÐØÐÐÐØ€€€ØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐàÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐØ4Ð4Ð4Ð4Ð4Ð4Ø&Ð&Ð&Ð&Ð&Ð&à €à€gÔ˜Ñ!Ô!€ð'ð'ð'ð'ð'ˆtŒyñ'ô'ð'ð&ð&ð&ð&ð&ˆdŒiñ&ô&ð&ð ð ð ð ð ˆtŒyñ ô ð ð,à �T˜#”YÔ ð,ð �T˜#”YÔ ð,ð ˆ3�ˆ8„_ð ,ð,ð,ð,ð ,à �T˜#”YÔ ð ,ð�3˜�8Œ_ð ,ð˜3”ið ,ð �T˜#”YÔ ð ,ð  ˆ3�ˆ8„_ð ,ð ,ð ,ð ,ðBðBðBðBðBñBôBðBðJl,ðl,ðl,ðl,ðl,ñl,ôl,ðl,ð^Q%ðQ%ðQ%ðQ%ðQ%ñQ%ôQ%ðQ%ðQ%ðQ%r