TL i*ZdZddlZddlmZddlmZddlmZddlm Z ddlm Z ddl m Z dd l mZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZmZddlmZmZddlmZm Z m!Z!ddl"m#Z#ddl$m%Z%GddZ&eedZ'egdZ(dZ)dZ*dZ+GddZ, d(d Z-e%j\ed!Z/ d)d"Z0d*d#Z1d*d$Z2d%Z3d&Z4edfd'Z5y)+a :mod:`jedi.inference.imports` is here to resolve import statements and return the modules/classes/functions/whatever, which they stand for. However there's not any actual importing done. This module is about finding modules in the filesystem. This can be quite tricky sometimes, because Python imports are not always that simple. This module also supports import autocompletion, which means to complete statements like ``from datetim`` (cursor at the end would return ``datetime``). N)Path)tree)search_ancestor)debug)settings)FolderIO)get_cached_code_lines)sys_path)helpers)compiled)analysis)unite)inference_state_method_cache) ImportName SubModuleName)ValueSet NO_VALUES)import_module_decoratorcreate_stub_moduleparse_stub_module)ImplicitNSInfo)plugin_managerceZdZdZdZdZy) ModuleCacheci|_yN _name_cacheselfs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/jedi/inference/imports.py__init__zModuleCache.__init__$s c(|||j|<yyrr)r string_names value_sets r!addzModuleCache.add's  #-6D  \ * $r#c8|jj|Sr)rget)r r%s r!r)zModuleCache.get+s##L11r#N)__name__ __module__ __qualname__r"r'r)r#r!rr#s72r#r)defaultc|j}t||\}}}}|rF|D|j||d}|s.||fz}t|j|||}|j }t jd||S)NF name_contextanalysis_errorszafter import: %s)get_root_context_prepare_infer_importpy__getattribute__Importerinference_statefollowrdbg) context tree_namemodule_contextfrom_import_name import_pathlevelvaluespathimporters r! infer_importrC1s--/Nni81k5&  '.. $ %/F "&6%88#G$;$;T>SXY!* II &) Mr#c b|j}t|\}}}}|sgS|qt|Dcgc]}|j||dc}}|rt fd|Ds|S||fz} t |j | ||} | j}td|DScc}w)NFr0c3:K|]}|juywr)r;).0nr;s r! zgoto_import..XsE!Q[[I5Esc34K|]}|jywr)name)rFss r!rHzgoto_import..^s&!qvv&s) r3r4rgotoanyr6r7r8set) r:r;r<r=r>r?r@cnamesrArBs ` r! goto_importrQGs--/Nni81k5&  #    FF $ %     EuEEL.00G33T>5Q" &v& && sB,cjt|dd}|j|}d} |j}t|dzt|k(r|d}|} t |j t|||j}|t||j|jfS#t$rY]wxYw)N import_name import_from) rget_path_for_nameget_from_nameslenAttributeErrorr6r7tupler?r8)r<r; import_noder>r= from_namesrBs r!r4r4as!)]MJK// :K % //1 z?Q #k"2 2 +2 $K66k8J& (9(9;H U;/1B1BHOODU UU    sB&& B21B2ct|dr|tj|d||ytjd|zy)Nparentz import-errorzImportError without origin: )hasattrr r'rwarning)valuerJmessages r! _add_errorrdws5tX5#4 UND': 4w>?r#cDt|dz D]*}|}tjj|}||k(s*y|}g} ||k(r||fStjj |}|r2|j d|tjj|}nd|fSa)z In case the level is outside of the currently known package (something like import .....foo), we can still try our best to help the user for completions. rUNNrN)rangeosrAdirnamebasenameinsert) project_path directoryr?iolddlevel_import_pathsdir_names r!_level_to_base_import_pathrs~s 519 GGOOI. )   A  %q( (77##A&   % %a 2"A? " r#c@eZdZddZedZdZdZd dZd dZ y) r6ctjd|d|||_||_||_d|_d|_|r|jj}|t|kr/t|}|dkDr |d| dz}|t|z}||_y|j}|jjj}t|}||}ntjj!|}t#|||\} } | d|_n| g|_| |rt%||dd ||_y| |z}||_y) a An implementation similar to ``__import__``. Use `follow` to actually follow the imports. *level* specifies whether to use absolute or relative imports. 0 (the default) means only perform absolute imports. Positive values for level indicate the number of parent directories to search relative to the directory of the module calling ``__import__()`` (see PEP 328 for the details). :param import_path: List of namespaces (strings or Names). zimport  NTrUFrz3Attempted relative import beyond top-level package.)rc)rspeed_inference_stater?_module_context_fixed_sys_path_infer_possible get_value py__package__rYr[ py__file__projectrAlistrhrirsrdr>) r r7r>r<r?baserArlrmbase_import_pathbase_directorys r!r"zImporter.__init__s^  k>BC / -## !++-;;=DD !T{19 %!,D"U;%77 @'=&002#44<<AA ";/ < !-I " 5I3M )U40 ."),1D(,:+;D(#+""*KN$Y '#3["@K&r#c:td|jDS)z:Returns the import path as pure strings instead of `Name`.c3lK|],}t|tjr |jn|.ywr isinstancerNamerb)rFrJs r!rHz,Importer._str_import_path..s. %T4995DJJ4 ? 24)r[r>rs r!_str_import_pathzImporter._str_import_paths$ ((   r#c|j |jS|jj| tj|j Dcgc] }t |c}zScc}w)N)add_init_paths)rzrx get_sys_pathr check_sys_path_modificationsrystr)r is_completionps r!_sys_path_with_modificationsz%Importer._sys_path_with_modificationsso    +'' '  ! ! . .->O . P889M9MNA  sA-cz|jsp|jr^ddlm}tj j |jdf}||j||j}t|hStS|jstS|jjj|j}| t|hS|jjj|j}||S|jd}t!|j|j||j"S)NrImplicitNamespaceValuer%pathsFr)r>rzjedi.inference.value.namespacerrhrArjrxrrr{stub_module_cacher)r module_cacherimport_module_by_namesry)r rr>ns from_cacher s r!r8zImporter.follows##2R!ww//0D0DQ0GHJ +))!,..  ~% ## **<<@@AVAVW  !ZL) )**77;;Drr string_name startswithrYappendrryrrhrAjoinisdirr8api_type is_compiledsub_modules_dictr@!jedi.inference.gradual.conversionr get_filtersr?rz)r r7 only_modulesrPmodmodnameextnamedirrr@rbr both_valuesrOfilters r!completion_nameszImporter.completion_names;s ##I   $$(88113PC!ooG))(3")#h-."9 Z0D0Dg%NO P  <<4<PDC!ww||C>)@@((*U335<<>>E  ? L$~f'== $1A"#--/1011 zz//0D0DEE //11 r#)rrf)F) r*r+r,r"propertyrrr8rrr-r#r!r6r6s2D'L    3 j  /r#r6Tc ||j}td|D}dg}t|D]\}}tj|D cgc]} t ||d|dz| ||c} }|r@ddj |z} |t||| tcStj| tcS|Scc} w)Nc3lK|],}t|tjr |jn|.ywrr)rFrns r!rHz)import_module_by_names..rs. a+2rrU) prefer_stubszNo module named .) rr[ enumerater from_sets import_modulerrdrrar) r7 import_namesr r<rstr_import_namesr&rnrJparent_module_valuercs r!rrms"//1I\*4&&*3( &  !A#&#)  (  (3884D+EEG)>49  g& !" !( s B> c|dtjvr!t|||}|tSt |gSdj |}|-|j j|d||d\}}|KtS|j}|tS|j j|d||d\}}|tSt|tr>ddl m } | |t|jjd|j }n&|t|||}|tSt#|||| }|t%j&d |d|nt%j&d ||t |gS) zC This method is very similar to importlib's `_gcd_import`. rrrVT)string full_namer is_global_searchF)rrArrrrr is_packagezglobal search_module %s: %sz search_module %s in paths %s: %s)rauto_import_modules_load_builtin_modulerrrcompiled_subprocessget_module_info py__path__rrrrr[rJsplitr_load_python_modulerr9) r7rrr r module_name file_io_or_nsis_pkgrrs r!rrs A(666%o|XN > !!((<(K"!0 C C S S#!! !T!  v > #..0 =  / C C S S#!" !T!  v > -0I' }1177<=%%   %o|XN > $ ]%  " /b1A6J 4k5&Q VH r#c |j|dtjtj}ddlm}|||||t |j|j|S)NT)file_iocache diff_cache cache_pathr) ModuleValue)rr% code_linesr) parser fast_parsercache_directoryjedi.inference.valuerr grammarrA)r7rrr module_noders r!rrsc!''''++ (K1 !()@)@',,O  r#c|j}||j}|js%|j|}|Dcgc] }||vs| }}dj |}|Jt j |||}|y|Scc}w)Nr) dotted_namer )rr_load_unsafe_extensions_get_base_sys_pathrr load_module)r7rr r safe_pathsrrrs r!rrs%%G"//1  * *//@ ';!1 ?A;;((<(K  "" "  ! !/{U] ^F ~ M> " "8 , !45I 99 &&22=AN&22<3Ce3KLN %Aqc]F" _;;V ow 7,  % W%!  $$((x7IJ ! F s!EE)(E)ctj|jt|j\}}ddlm}||||jgS)Nrr)r rrrrArr)r7rrrrs r!load_namespace_from_pathrsK'@@$$& Y^^ L*F !/<)..AQ RRr#ctj|d}|d}t|jD]+\}}|j|jkDrn |dk(s'|dz}-|j|d}|dj j }|dvrT|dk(}tj|||\} } t|j| |j| jSy)N error_noder;rU)fromimportr)is_import_from until_node) rrrchildren start_posget_first_leafrbr parse_dotted_namesr6r7r3r8) r:rJr start_indexindexrGnodes first_namerr?rPs r!%follow_error_node_imports_if_possibler's%%dL9J !*"5"56 (HE1{{T^^+Cx#ai  ( ##KL11X,,.44  + +'61N"55-LE5 ''0H0H0JESSYSYS[ \ r#c#K|r*|jjD] }||||jj|D] }|||yw)zx Get the names of all modules in the search_path. This means file names and not names defined in the files. N)rget_builtin_module_namesr)r7r<rrrrJs r!rrDse#77PPR 3D^T2 2 3 33EEkR/../sAA)NNT)NFrf)6__doc__rhpathlibr parso.pythonr parso.treerjedirr jedi.file_iorjedi.parser_utilsr jedi.inferencer r r r jedi.inference.utilsrjedi.inference.cacherjedi.inference.namesrrjedi.inference.base_valuerrjedi.inference.gradual.typeshedrrr,jedi.inference.compiled.subprocess.functionsr jedi.pluginsrrrCrQr4rdrsr6rdecoraterrrrrrrr-r#r!r!s   &!3#"##&=:9**G' 2 2i01*b)'*'2V,@#6QQhDH=A<;;~7<&$+\S<", /r#