bgO &UddlmZddlmZmZddlZddlmZddlm Z ddl m Z m Z m Z mZmZddlmZddlmZmZerdd lmZGd d eZid ed ddedddedddedddedddedddedddedddeddd ed!dd"ed#dd$ed%dd&ed'dd(ed)dd*ed+dd,ed-dd.ed/did0ed1dd2ed3dd4ed5dd6ed7dd8ed9dd:ed;dd<ed=dd>ed?dd@edAddBedCddDedEddFedGddHedIddJedKddLedMddNedOddPedQdedRdedSdedTdedUdedVdedWddXZdYedZ<ed[eDZd\ZGd]d^eZGd_d`e ZdfdeZdS)g) annotations) TYPE_CHECKING NamedTupleN)nodes) BaseChecker)in_type_checking_block"is_node_in_type_annotation_contextis_postponed_evaluation_enabledonly_required_for_messages safe_infer)TYPING_NORETURN)HIGH INFERENCE)PyLinterc$eZdZUded<ded<dS) TypingAliasstrnameboolname_collisionN)__name__ __module__ __qualname____annotations__i/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pylint/extensions/typing.pyrrs' IIIrrz typing.TupletupleFz typing.Listlistz typing.Dictdictz typing.Setsetztyping.FrozenSet frozensetz typing.Typetypez typing.Dequezcollections.dequeTztyping.DefaultDictzcollections.defaultdictztyping.OrderedDictzcollections.OrderedDictztyping.Counterzcollections.Counterztyping.ChainMapzcollections.ChainMapztyping.Awaitablezcollections.abc.Awaitableztyping.Coroutinezcollections.abc.Coroutineztyping.AsyncIterablezcollections.abc.AsyncIterableztyping.AsyncIteratorzcollections.abc.AsyncIteratorztyping.AsyncGeneratorzcollections.abc.AsyncGeneratorztyping.Iterablezcollections.abc.Iterableztyping.Iteratorzcollections.abc.Iteratorztyping.Generatorzcollections.abc.Generatorztyping.Reversiblezcollections.abc.Reversibleztyping.Containerzcollections.abc.Containerztyping.Collectionzcollections.abc.Collectiontyping.Callablezcollections.abc.Callableztyping.AbstractSetzcollections.abc.Setztyping.MutableSetzcollections.abc.MutableSetztyping.Mappingzcollections.abc.Mappingztyping.MutableMappingzcollections.abc.MutableMappingztyping.Sequencezcollections.abc.Sequenceztyping.MutableSequencezcollections.abc.MutableSequenceztyping.ByteStringzcollections.abc.ByteStringztyping.MappingViewzcollections.abc.MappingViewztyping.KeysViewzcollections.abc.KeysViewztyping.ItemsViewzcollections.abc.ItemsViewztyping.ValuesViewzcollections.abc.ValuesViewz!contextlib.AbstractContextManagerz&contextlib.AbstractAsyncContextManagerz re.Patternzre.Matchzcollections.abc.Hashablezcollections.abc.Sized)ztyping.ContextManagerztyping.AsyncContextManagerztyping.Patternz typing.Matchztyping.Hashablez typing.Sizedzdict[str, TypingAlias]DEPRECATED_TYPING_ALIASESc#LK|]}|ddV dS).N)split).0keys r r,Ms1OOc #q)OOOOOOr)OptionalUnionc<eZdZUded<ded<ded<dZded<d S) DeprecatedTypingAliasMsgnodes.Name | nodes.AttributenoderqnamealiasFrparent_subscriptN)rrrrr5rrrr0r0QsB&&&&JJJJJJ"""""""rr0ceZdZUdZdZddddddd Zd d d d ddffZded< ded< dAfd ZdBdZ dCdZ e dddd d!dDd#Z e dddd d!dEd%Z e d&dFd(ZedGd+ZdHd,ZedId.Z dJdKd5ZdLd7ZdMd:ZdNd;Ze dddOd=ZdNd>ZdNd?ZdPd@ZxZS)Q TypingCheckerz4Find issue specifically related to type annotations.typing)z$'%s' is deprecated, use '%s' insteaddeprecated-typing-aliasz/Emitted when a deprecated typing alias is used.)z@'%s' will be deprecated with PY39, consider using '%s' instead%sconsider-using-aliasz|Only emitted if 'runtime-typing=no' and a deprecated typing alias is used in a type annotation context in Python 3.7 or 3.8.)z9Consider using alternative Union syntax instead of '%s'%s!consider-alternative-union-syntaxznEmitted when 'typing.Union' or 'typing.Optional' is used instead of the alternative Union syntax 'int | None'.)z;'NoReturn' inside compound types is broken in 3.7.0 / 3.7.1broken-noreturnz``typing.NoReturn`` inside compound types is broken in Python 3.7.0 and 3.7.1. If not dependent on runtime introspection, use string annotation instead. E.g. ``Callable[..., 'NoReturn']``. https://bugs.python.org/issue34921)zo'collections.abc.Callable' inside Optional and Union is broken in 3.9.0 / 3.9.1 (use 'typing.Callable' instead)broken-collections-callablez``collections.abc.Callable`` inside Optional and Union is broken in Python 3.9.0 and 3.9.1. Use ``typing.Callable`` for these cases instead. https://bugs.python.org/issue42965)zVType `%s` is used more than once in union type annotation. Remove redundant typehints.redundant-typehint-argumentziDuplicated type arguments will be skipped by `mypy` tool, therefore should be removed to avoid confusion.)W6001R6002R6003E6004E6005R6006zruntime-typingTynzauSet to ``no`` if the app / library does **NOT** need to support runtime introspection of type annotations. If you use type annotations **exclusively** for type checking of an application, you're probably fine. For libraries, evaluate if some users want to access the type hints at runtime first, e.g., through ``typing.get_type_hints``. Applies to Python versions 3.7 - 3.9)defaultr#metavarhelpr_should_check_typing_alias&_should_check_alternative_union_syntaxlinterrreturnNonect|d|_t|_g|_g|_dS)zInitialize checker instance.rKFN)super__init___found_broken_callable_locationr!_alias_name_collisions_deprecated_typing_alias_msgs_consider_using_alias_msgs)selfrK __class__s rrQzTypingChecker.__init__sH '''5:,03#MO*JL'''rc.|jjj}|dk|_|dk|_|dk|_|jp|jo|jjjdu|_|jp|jo|jjjdu|_|dk|_ |dk|_ dS)N))rY )rY F)rYrZ)rYr[r]) rKconfig py_version _py37_plus _py39_plus _py310_plusruntime_typingrIrJ_should_check_noreturn_should_check_callable)rVr_s ropenzTypingChecker.opens['2 $.$.%0*./+ O J 2 AU J '7;6F7 O J 2 AU J 3'19&<#&09&<###rr2 nodes.NodeNGrcN|jsd|jvrdSdS)z3Message hint if postponed evaluation isn't enabled.rz2. Add 'from __future__ import annotations' as well)rbrootfuture_importsrVr2s r_msg_postponed_eval_hintz&TypingChecker._msg_postponed_eval_hints-   } 0JJJ2CCrr9r:r;r<r= nodes.Namec^|jr#|jtvr|||jr)|jt vr|||j|jr |jdkr|||j r"|jdkr| |dSdSdSNNoReturnCallable) rIr ALIAS_NAMES_check_for_typing_aliasrJ UNION_NAMES#_check_for_alternative_union_syntaxrd_check_broken_noreturnre_check_broken_callablerls r visit_namezTypingChecker.visit_names  * /tyK/G/G  ( ( . . .  6 F49 ;S;S  4 4T49 E E E  & .49 +B+B  ' ' - - -  & .49 +B+B  ' ' - - - - - . .+B+Brnodes.Attributec^|jr#|jtvr|||jr)|jt vr|||j|jr |jdkr|||j r"|jdkr| |dSdSdSrp) rIattrnamersrtrJrurvrdrwrerxrls rvisit_attributezTypingChecker.visit_attributes  * /t} /K/K  ( ( . . .  6 J4=K;W;W  4 4T4= I I I  & .4=J+F+F  ' ' - - -  & .4=J+F+F  ' ' - - - - - . .+F+Frr>nodes.AnnAssignc|j}||dr5||r|d|dtdS||dr,t |jtjr |jj }n-| |r| |}ndS| ||dS)Nr-r>rMr2args confidencer.) annotation_is_deprecated_union_annotation_is_optional_none_annotation add_messager isinstanceslicerTupleelts_is_binop_union_annotation_parse_binops_typehints_check_union_types)rVr2rtypess rvisit_annassignzTypingChecker.visit_annassigns_  / / J G G 00<<   1## ! F  / / G D D   ekJ J  $)EE  , ,Z 8 8 00<r)r! as_stringrradd)rVrr types_settypehint typehint_strs rrz TypingChecker._check_union_typessEE  , ,H#--//Ly((  1#&# ! l++++ , ,rr1rct|}t|tjr|dvs9t|t jjr|dksdS|jst|sdS| d||| |ftdS)zCheck if alternative union syntax could be used. Requires - Python 3.10 - OR: Python 3.7+ with postponed evaluation in a type annotation context  typing.Uniontyping.Optionaltyping._SpecialFormNr;r) r rr FunctionDefr3astroidbasesInstancerbr rrmr)rVr2rinferreds rrvz1TypingChecker._check_for_alternative_union_syntax-sd## x!2 3 3   $GGG(GM$:;;H  $999 F  $Ft$L$L  F  /55d;;<      rc >t|}t|tjsdSt|d}|dS|jrv|dkr||rd|_ |j t|||j dSt|sVt|jtjr7|jdur,|j|dS|j t|||j t|jtjdS)aCheck if typing alias is deprecated or could be replaced. Requires - Python 3.9 - OR: Python 3.7+ with postponed evaluation in a type annotation context For Python 3.7+: Only emit message if change doesn't create any name collisions, only ever used in a type annotation context, and can safely be replaced. Nr$T)r rrClassDefr%getr3ra_broken_callable_locationrRrTrr0rr parentrrrSrrU)rVr2rr4s rrtz%TypingChecker._check_for_typing_aliasJsd##(EN33  F)--hnn.>.>EE = F ? ~~#4449W9W::48<4  . 5 5(NN$$J    F2$77 J K= =  #t+++//0@0@AAA F '.. $   4;88        r nodes.Modulec.|jrM|jD]D}|jr |jdkr|d|j|j|jftEnn|jrg| |}|j D]J}|j|j vr|d|j|j|j|j r|ndftKd|_|j |j |j dS)zAfter parsing of module is complete, add messages for 'consider-using-alias' check. Make sure results are safe to recommend / collision free. r$r9rr:riFN)rarTrRr3rr2r4rr`rmrUrSr5clear)rVr2msgmsg_future_imports r leave_modulezTypingChecker.leave_module~s] ? 9  8 %666  -)SY/( ! _  $ = =d C C 6  9 ;;;  *  -0-AI))r )!    05, *00222 #))+++ '--/////rcLt|jtjsdSt |st |rt |rdS|D]}t|tjtj fr| tvs[t|tj jr\t|jtj r=|j dkr |d|t"dSdS)z+Check for 'NoReturn' inside compound types.Nrr<r2r)rrr BaseContainerrr r inferrrr3r rr BaseInstance_proxiedrrrVr2rs rrwz$TypingChecker._check_broken_noreturns$+u':;;  F #4 ( ( .t44 3488  F  H8e&7%HII NN$$77h (BCC8x0%.AA8%++--1FFF  !2) TTT  rct|}t|tjr-|dkr||sdS|d|tdS)z?Check for 'collections.abc.Callable' inside Optional and Union.z_collections_abc.CallableNr=r)r rrrr3rrrrs rrxz$TypingChecker._check_broken_callablesyd## x 0 0   $???..t44@ F 6TiXXXXXrcrt|st|rt|rdSt|jt jrut|jjt jrQt|jjj dkr/t|jjj dt j sdS|jj}t|t j r|j}t|t jr+t|j t jt jfsdSt!|j }t|t jr|dvs9t|t&jjr|dksdSdS)zFCheck if node would be a broken location for collections.abc.Callable.Fr]rrrT)rr r rrrrrrlenrListrrr Attributer rr3rrr)rVr2r5inferred_parents rrz'TypingChecker._broken_callable_locations #4 ( ( .t44 3488  5 t{EO 4 4 4;,ek:: DK%*++q004;,1!4ejAA15 ;- &(; < < 7/6  ' 9 9 +1EJ3PQQ 5$%5%;<< (9 : : %%''+NNN/7=+ABBO%%''+@@@5trrKrrLrM)rLrM)r2rgrLr)r2rnrLrM)r2rzrLrM)r2r~rLrM)rrgrrrLr)rrgrLr)rrrLrr)rrrrrLr)rrrrgrLrM)r2r1rrrLrM)r2r1rLrM)r2rrLrM)r2r1rLr)rrr__doc__rmsgsoptionsrrQrfrmr ryr}r staticmethodrrrrrrvrtrrwrxr __classcell__)rWs@rr7r7Xs>> D      G) ) DX %;   G(%$$$1000MMMMMM==== DDDD  !+% .... !+% ....  =>>---?>-,   \        \ TX     ,,,,     :2 2 2 2 h  68QRR(0(0(0SR(0T4 Y Y Y Y%%%%%%%%rr7rKrrLrMcJ|t|dSr)register_checkerr7rOs rregisterrs$ M&1122222rr) __future__rr8rr astroid.basesrrpylint.checkersrpylint.checkers.utilsrr r r r pylint.constantsr pylint.interfacesrr pylint.lintrrr%rr"rsrur0r7rrrrrs #"""""",,,,,,,,''''''-,,,,,--------%$$$$$$* +5KK//+5;;vu--+5;;vu--+5++eU++ +5  K77 +5 ;;vu-- +5KK 3T::+5++&?FF+5++&?FF+5kk"7>>+5{{#94@@+5 $?FF+5 $?FF+5KK(GNN+5KK(GNN+5 [[)I4PP!+5"{{#=tDD#+5+5${{#=tDD%+5& $?FF'+5(%A4HH)+5* $?FF++5,%A4HH-+5.{{#=tDD/+50++&;UCC1+52%A4HH3+54kk";TBB5+56[[)I4PP7+58{{#=tDD9+5:kk*KTRR;+5<%A4HH=+5>++&CTJJ?+5@{{#=tDDA+5B $?FFC+5D%A4HHE+5+5F)[)LeTT"-+0%##"k,55K D11"{#=tDDK 7>>U+5+5+5++++ZiOO5NOOOOO # #####z###\\\\\K\\\~ 333333r