TL i CddlmZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z mZmZddlmZmZdd lmZmZdd lmZdd lmZdd lmZGd dZGddeZGddZGddeeZGddeeZGddeeZ GddeeZ!GddeeZ"GddeZ#Gdd e#Z$d!Z%d"Z&y#)$)abstractmethod)contextmanager)Path)Optional)search_ancestor)Name)ParserTreeFilter MergedFilterGlobalNameFilter)AnonymousParamNameTreeNameDefinition) NO_VALUESValueSet)get_parent_scope)debug) parser_utilsceZdZdZeddZdZ ddZdZdZ dZ d Z d Z d Z d Zd ZdZedZdZedZdZdZedZy)AbstractContextc ||_i|_yN)inference_statepredefined_names)selfrs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/jedi/inference/context.py__init__zAbstractContext.__init__s. "NctrNotImplementedErrorruntil_position origin_scopes r get_filterszAbstractContext.get_filters!!rcddlm}t|t|tr|nd|}|j ||}t jd||||S)Nr)finderzcontext.goto %s in (%s): %s)jedi.inferencer&_get_global_filters_for_name isinstancer filter_namerdbg)r name_or_strpositionr&filtersnamess rgotozAbstractContext.gotosM). K!>+D( ""7K8 /dEJ rc ||}|j||}t|tr |jn|}d}|jrst|trc|}|_t j |sJ|j}|jdvr |j|} | |} | }n|t j |sJ|>|r tuple of line, column N)if_stmtfor_stmtcomp_for sync_comp_forr) flow_analysis)context value_scopenodec3<K|]}|jywr)infer).0names r z5AbstractContext.py__getattribute__..Ms'G 'Gs)analysisz$NameError: name '%s' is not defined.z name-errorz context.names_to_types: %s -> %s)r0r)rvaluerris_scopeparenttypeKeyErrorr'r6reachability_check tree_node UNREACHABLErr from_setsr?addrr+_check_for_additional_knowledge)rr, name_contextr-analysis_errorsr/ string_namefound_predefined_typesr9 name_dicttypesr6checkvaluesr?messages rpy__getattribute__z"AbstractContext.py__getattribute__&s  L +x0+5k4+Hk''k "&  Z T%BD"<+@+@+F{{99 TT$($9$9$$? )+ 627."<+@+@+F " -% 4!44 NN 5E  111"/'''G'GGFV+t,3AKO \<gN 4eVD M33KxXX9$! !sE55 FFc|xs|}t|trf|jsV|}|jg}t d|Drt Sddlm} t|d}|||||}||S||vr t S(t S)Nc38K|]}|jdvyw)r4r5N)rC)r<bs rr>zBAbstractContext._check_for_additional_knowledge..asOq166::Osr)check_flow_informationT) include_flows) r)r is_instancerFanyrjedi.inference.finderrYr)rr,rKr- flow_scope base_nodesrYns rrJz/AbstractContext._check_for_additional_knowledgeZs#+t k4 (1I1I1K$J&001JOJOO  D-jM *<+6B=H+rcB|j}||S|jSr)parent_contextget_root_context)rrbs rrcz AbstractContext.get_root_contextns',,  !K..00rcyNFrs r is_modulezAbstractContext.is_moduletrcyrerfrgs ris_builtins_modulez"AbstractContext.is_builtins_modulewrircyrerfrgs ris_classzAbstractContext.is_classzrircyrerfrgs ris_stubzAbstractContext.is_stub}rircyrerfrgs rr[zAbstractContext.is_instancerircyrerfrgs r is_compiledzAbstractContext.is_compiledrircyrerfrgs ris_bound_methodzAbstractContext.is_bound_methodrirctrrrgs r py__name__zAbstractContext.py__name__r$rctrrrgs r get_valuezAbstractContext.get_values!!rcyrrfrgs rr=zAbstractContext.namesrcy)Nrfrfrgs rget_qualified_namesz#AbstractContext.get_qualified_namesrcy)Nrfrgs r py__doc__zAbstractContext.py__doc__r|rc#NK|j}|||< d||=y#||=wxYwwr)r)rr^dct predefineds rpredefine_nameszAbstractContext.predefine_namess3** !$ : ' :& :&s%%"%NN)NNT)__name__ __module__ __qualname__rrr#r0rTrJrcrhrkrmror[rrrtrvrxpropertyr=r{rrrrfrrrrs#""KO+/2Yh(1 """''rrceZdZdZfdZedZedZdZdZ dZ dZ d Z d Z d Zd Zed ZdZdZdZdZxZS) ValueContextzC Should be defined, otherwise the API returns empty types. cFt||j||_yr)superrr_value)rr@ __class__s rrzValueContext.__init__s ../ rc.|jjSr)rrFrgs rrFzValueContext.tree_nodes{{$$$rc.|jjSr)rrbrgs rrbzValueContext.parent_contexts{{)))rc6|jjSr)rrhrgs rrhzValueContext.is_module{{$$&&rcH|j|jjk(Sr)rrbuiltins_modulergs rrkzValueContext.is_builtins_modules{{d22BBBBrc6|jjSr)rrmrgs rrmzValueContext.is_classs{{##%%rc6|jjSr)rrorgs rrozValueContext.is_stubs{{""$$rc6|jjSr)rr[rgs rr[zValueContext.is_instance{{&&((rc6|jjSr)rrrrgs rrrzValueContext.is_compiledrrc6|jjSr)rrtrgs rrtzValueContext.is_bound_methods{{**,,rc6|jjSr)rrvrgs rrvzValueContext.py__name__{{%%''rc.|jjSr)rr=rgs rr=zValueContext.names{{rc6|jjSr)rr{rgs rr{z ValueContext.get_qualified_namess{{..00rc6|jjSr)rrrgs rrzValueContext.py__doc__rrc|jSrrrgs rrxzValueContext.get_value {{rcN|jjd|jdSN())rrrrgs r__repr__zValueContext.__repr__s>>22DKK@@r)rrr__doc__rrrFrbrhrkrmror[rrrtrvr=r{rrxr __classcell__rs@rrrs%%**'C&%))-(  1'Arrc$eZdZdZdZdZdZy)TreeContextMixinc ddlm}|||S)Nr) infer_node)jedi.inference.syntax_treer)rr9rs rrzTreeContextMixin.infer_nodes9$%%rcZddlm}||jk(r"|jsJ|j S|j |}|j dvr|jj||}|jrn|jj|j}|j|j|j|}|j||j|}|S|j dk(r|j!|j||St#d|z)Nr)r@)funcdeflambdef)instance class_contextfunctionclassdefzProbably shouldn't happen: %s)r'r@rFrhrxcreate_contextrC FunctionValue from_contextrmrb create_valueAnonymousInstancer BoundMethod as_context ClassValuer)rr9r@rbfunc class_valuers rrzTreeContextMixin.create_values( 4>> !>># ##>># #,,T2 99. .&&33NDID&&(,;;HHIaIab  22((.*G*GV((%"-"8"8":!) K YY* $##D$8$8.$O O%&E&LM MrcHdfd d}|jdvrs|j|jjd}j|jkr2j}|jdk(r|j k(s|}|dS) NTcP|jk(rS|jdvrj|jS|jdvrL|j}j |j dj k\r|St||Std|z)N)rrrrWz(There's a scope that was not managed: %s) rFrCrrrB start_poschildrenCompForContext Exception) scope_node is_nestedrbfrom_scope_noder9 parent_scopers rrz8TreeContextMixin.create_context..from_scope_nodesT^^+ "DD((4??AA$AA!0j>O>O1P!Q>>Z%8%8%<%F%FF))%njAAFST Trc& |j}tj|r|S|jdvr*|jdjdvrD|jdS|jdk(r&|jddD]}|jdvs|cS)N)argument testlist_comprWdictorsetmaker)rBrrArCr)r9r`s rrz5TreeContextMixin.create_context..parent_scope s{{((.KYY"??}}Q',,0MM#}}Q//YY"22!]]1Q/%66%BB#$H%r)rr:param)r)T)rCrindexrrBr=)rr9rcolonrBrrs`` @@rrzTreeContextMixin.create_contexts U U %"$' ??5 5'' (;(;(A(A#(FGE~~/ w.6;;$3F!-j!9JzT::rc|j}|rH|jdk(r9|j|k(r*t|dd}|j |}t ||S|j |}t||S)Nrrr)get_definitionrCr=rrr rr )r tree_name definitionrrr7s r create_namezTreeContextMixin.create_name"sq--/ *//W4I9U%j)YGG$$W-D%dI6 6)))4G%gy9 9rN)rrrrrrrrfrrrrs&N4$;L:rrceZdZddZy)FunctionContextNc#BKt|j|||ywN)rbr!r")r rr s rr#zFunctionContext.get_filters.s%  )%   srrrrr#rfrrrr-s rrcReZdZdeefdZd dZdZedZ edZ dZ y) ModuleContextreturnc6|jjSrr py__file__rgs rrzModuleContext.py__file__8rrNc#K|jj|}t|dtt ||||j |Ed{y7wr)rr#nextr r get_global_filter)rr!r"r.s rr#zModuleContext.get_filters;s[++)),7 Wd #-)   " " $   sAAAAct|Sr)r rgs rrzModuleContext.get_global_filterIs %%rc.|jjSrr string_namesrgs rrzModuleContext.string_namesL{{'''rc.|jjSr)r code_linesrgs rrzModuleContext.code_linesPs{{%%%rc|jS)z This is the only function that converts a context back to a value. This is necessary for stub -> python conversion and vice versa. However this method shouldn't be moved to AbstractContext. rrgs rrxzModuleContext.get_valueTs {{rr) rrrrrrr#rrrrrxrfrrrr7sI(HTN( &((&&rrc<eZdZddZdZedZdeefdZ y)NamespaceContextNc6|jjSrrr#r s rr#zNamespaceContext.get_filters^rrc|jSrrrgs rrxzNamespaceContext.get_valuearrc.|jjSrrrgs rrzNamespaceContext.string_namesdrrrc6|jjSrrrgs rrzNamespaceContext.py__file__hrrr) rrrr#rxrrrrrrfrrrr]s0)(((HTN(rrceZdZddZddZy) ClassContextNc#4K|j||ywr)rr s rr#zClassContext.get_filtersms$$^\BBsct|||Srr r s rrzClassContext.get_global_filterps)%  rr)rrrr#rrfrrrrls C rrc8eZdZfdZddZdZdZdZxZS)rcTt||j||_||_yr)rrrrFrb)rrbr4rs rrzCompForContext.__init__ys% 778!,rc#&Kt|ywrrr s rr#zCompForContext.get_filters~st$$scyrrfrgs rrxzCompForContext.get_valuesrcy)Nzrfrgs rrvzCompForContext.py__name__s(rcN|jjd|jdSr)rrrFrgs rrzCompForContext.__repr__s>>22DNNCCrr) rrrrr#rxrvrrrs@rrrxs- %)DrrceZdZddZy)CompiledContextNc6|jjSrrr s rr#zCompiledContext.get_filtersrrrrrfrrrrs)rrc8eZdZdZdZedZdeefdZ y)CompiledModuleContextNc|jSrrrgs rrxzCompiledModuleContext.get_valuerrc.|jjSrrrgs rrz"CompiledModuleContext.string_namesrrrc6|jjSrrrgs rrz CompiledModuleContext.py__file__rr) rrrrrxrrrrrrfrrrrs0J(((HTN(rrc|pt|ddd}d}|dk(r|}t|dd}|J|jd}|9||jkr*|||jdjkr |j}t|||S)Nrrr)rrrget_global_filters)r7 name_or_noner-ancestorrrs rr(r(s"<J R y G&|Y KH  %%b)E#5??(B?h1A1A"1E1O1O&O'11H gx >>rc# K|}ddlm}|>|j||Ed{t||tfrd}|j }|>t |jjjd}|J|y7^w)a Returns all filters in order of priority for name resolution. For global name lookups. The filters will handle name resolution themselves, but here we gather possible filters downwards. >>> from jedi import Script >>> script = Script(''' ... x = ['a', 'b', 'c'] ... def func(): ... y = None ... ''') >>> module_node = script._module_node >>> scope = next(module_node.iter_funcdefs()) >>> scope >>> context = script._get_module_context().create_context(scope) >>> filters = list(get_global_filters(context, (4, 0), None)) First we get the names from the function scope. >>> print(filters[0]) # doctest: +ELLIPSIS MergedFilter(, ) >>> sorted(str(n) for n in filters[0].values()) # doctest: +NORMALIZE_WHITESPACE ['', ''] >>> filters[0]._filters[0]._until_position (4, 0) >>> filters[0]._filters[1]._until_position Then it yields the names from one level "lower". In this example, this is the module scope (including globals). As a side note, you can see, that the position in the filter is None on the globals filter, because there the whole module is searched. >>> list(filters[1].values()) # package modules -> Also empty. [] >>> sorted(name.string_name for name in filters[2].values()) # Module attributes ['__doc__', '__name__', '__package__'] Finally, it yields the builtin filter, if `include_builtin` is true (default). >>> list(filters[3].values()) # doctest: +ELLIPSIS [...] r)BaseFunctionExecutionContextN)r!r") jedi.inference.value.functionrr#r)rrbrrr)r7r!r" base_contextrrXs rr r s^LJ  &&)%'    g rs%&"G9.O'O'd6A?6ArM:M:` &  #$l#L (' (  #\  D%D&)l) (O (?*@ r