+
    eC                        ^ RI Ht ^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHtHtHt ^ RIHtHt ^ R	IHtHt ^ R
IHt ^ RIHt ^ RIHt  ! R R4      t ! R R]4      t ! R R4      t ! R R]]4      t ! R R]]4      t ! R R]]4      t  ! R R]]4      t! ! R R]]4      t" ! R R]4      t# ! R R ]#4      t$R! t%R" t&R## )$    )abstractmethod)contextmanager)Path)Optional)search_ancestor)Name)ParserTreeFilterMergedFilterGlobalNameFilter)AnonymousParamNameTreeNameDefinition)	NO_VALUESValueSet)get_parent_scope)debug)parser_utilsc                      a  ] tR t^t o R t]RR l4       tR tRR ltR t	R t
R tR	 tR
 tR tR tR tR t]R 4       tR t]R 4       tR tR t]R 4       tRtV tR# )AbstractContextc                     Wn         / V n        R # Ninference_statepredefined_names)selfr   s   &&8/usr/lib/python3/dist-packages/jedi/inference/context.py__init__AbstractContext.__init__   s    . "    Nc                    \         hr   NotImplementedErrorr   until_positionorigin_scopes   &&&r   get_filtersAbstractContext.get_filters       !!r   c                    ^ RI Hp \        T \        V\        4      '       d   TMRV4      pVP                  WA4      p\        P                  ! RWV4       V# )r   )finderNzcontext.goto %s in (%s): %s)jedi.inferencer)   _get_global_filters_for_name
isinstancer   filter_namer   dbg)r   name_or_strpositionr)   filtersnamess   &&&   r   gotoAbstractContext.goto   sL    ).K!>!>+D(
 ""78		/EJr   c                   Vf   T pV P                  W4      p\        V\        4      '       d   VP                  MTpRpV P                  '       dw   \        V\        4      '       da   TpVe[   \
        P                  ! V4      '       g?   VP                  pVP                  R	9   g   K?   V P                  V,          p	W,          p
T
p VeF   V'       d>   ^ RI
Hp VP                  V V P                  VR7      pWP                  J d   \        pM TpM\         P"                  ! R V 4       4      pV'       gI   V'       gA   V'       d9   \        V\        4      '       d#   ^ RI
Hp RV,          pVP'                  VRW4       \(        P*                  ! RW]4       V'       d   V# V P-                  WV4      #   \         d     EKV  i ; i)
zJ
:param position: Position of the last statement -> tuple of line, column
N)flow_analysis)contextvalue_scopenodec              3   @   "   T F  qP                  4       x  K  	  R # 5ir   )infer).0names   & r   	<genexpr>5AbstractContext.py__getattribute__.<locals>.<genexpr>M   s     'G

s   )analysisz$NameError: name '%s' is not defined.z
name-errorz context.names_to_types: %s -> %s)if_stmtfor_stmtcomp_forsync_comp_for)r3   r,   r   valuer   r   is_scopeparenttypeKeyErrorr*   r6   reachability_check	tree_nodeUNREACHABLEr   r   	from_setsr@   addr   r.   _check_for_additional_knowledge)r   r/   name_contextr0   analysis_errorsr2   string_namefound_predefined_typesr9   	name_dicttypesr6   checkvaluesr@   messages   &&&&&           r   py__getattribute__"AbstractContext.py__getattribute__&   sy   
 L		+0+5k4+H+Hk''k "&   ZT%B%BD"<+@+@+F+F{{99 TT$($9$9$$?	 ) 6 27.!-%4!44 NN  5 E
 111"/'''G'GGFV+t,,3AKO\<N		4eDM33KxXX9 $ ! !s   (F/ /F?>F?c                   T;'       g    T p\        V\        4      '       d   VP                  4       '       g   TpVP                  .p\        ;QJ d    R  V 4       F  '       g   K   RM	  RM! R  V 4       4      '       d   \
        # ^ RIHp  \        VRR7      pV! W$W4      pVe   V# WE9   g   K%   \
        # \
        # )c              3   >   "   T F  qP                   R9   x  K  	  R# 5i)rC   NrC   rD   )rH   )r<   bs   & r   r>   BAbstractContext._check_for_additional_knowledge.<locals>.<genexpr>a   s     OJq66::Js   TF)check_flow_information)include_flows)	r,   r   is_instancerK   anyr   jedi.inference.finderr`   r   )r   r/   rP   r0   
flow_scope
base_nodesr`   ns   &&&&    r   rO   /AbstractContext._check_for_additional_knowledgeZ   s    #++tk4((1I1I1K1K$J&001JsOJOsssOJOOO  D-jM
*<+6B=H+yr   c                F    V P                   pVf   V # VP                  4       # r   )parent_contextget_root_context)r   rj   s   & r   rk    AbstractContext.get_root_contextn   s'    ,,!K..00r   c                    R # F r   s   &r   	is_moduleAbstractContext.is_modulet       r   c                    R # rn   ro   rp   s   &r   is_builtins_module"AbstractContext.is_builtins_modulew   rs   r   c                    R # rn   ro   rp   s   &r   is_classAbstractContext.is_classz   rs   r   c                    R # rn   ro   rp   s   &r   is_stubAbstractContext.is_stub}   rs   r   c                    R # rn   ro   rp   s   &r   rb   AbstractContext.is_instance   rs   r   c                    R # rn   ro   rp   s   &r   is_compiledAbstractContext.is_compiled   rs   r   c                    R # rn   ro   rp   s   &r   is_bound_methodAbstractContext.is_bound_method   rs   r   c                    \         hr   r    rp   s   &r   
py__name__AbstractContext.py__name__   r'   r   c                    \         hr   r    rp   s   &r   	get_valueAbstractContext.get_value   s    !!r   c                    R # r   ro   rp   s   &r   r=   AbstractContext.name   s    r   c                    R# )Nro   ro   rp   s   &r   get_qualified_names#AbstractContext.get_qualified_names   s    	r   c                    R # ) ro   rp   s   &r   	py__doc__AbstractContext.py__doc__   s    r   c              #  J   "   V P                   pW#V&    R x  W1 R #   Y1 i ; i5ir   )r   )r   re   dct
predefineds   &&& r   predefine_namesAbstractContext.predefine_names   s,     **
!$:	'&
&s   # # #r   NN)NNT)__name__
__module____qualname____firstlineno__r   r   r%   r3   rY   rO   rk   rq   ru   rx   r{   rb   r   r   r   r   propertyr=   r   r   r   r   __static_attributes____classdictcell____classdict__s   @r   r   r      s     # " "2Yh(1 " ""   ' 'r   r   c                      a a ] tR t^t oRtV 3R lt]R 4       t]R 4       tR t	R t
R tR tR	 tR
 tR tR t]R 4       tR tR tR tR tRtVtV ;t# )ValueContextz;
Should be defined, otherwise the API returns empty types.
c                F   < \         SV `  VP                  4       Wn        R # r   )superr   r   _value)r   rE   	__class__s   &&r   r   ValueContext.__init__   s    ../r   c                .    V P                   P                  # r   )r   rK   rp   s   &r   rK   ValueContext.tree_node   s    {{$$$r   c                .    V P                   P                  # r   )r   rj   rp   s   &r   rj   ValueContext.parent_context   s    {{)))r   c                6    V P                   P                  4       # r   )r   rq   rp   s   &r   rq   ValueContext.is_module       {{$$&&r   c                H    V P                   V P                  P                  8H  # r   )r   r   builtins_modulerp   s   &r   ru   ValueContext.is_builtins_module   s    {{d22BBBBr   c                6    V P                   P                  4       # r   )r   rx   rp   s   &r   rx   ValueContext.is_class   s    {{##%%r   c                6    V P                   P                  4       # r   )r   r{   rp   s   &r   r{   ValueContext.is_stub   s    {{""$$r   c                6    V P                   P                  4       # r   )r   rb   rp   s   &r   rb   ValueContext.is_instance       {{&&((r   c                6    V P                   P                  4       # r   )r   r   rp   s   &r   r   ValueContext.is_compiled   r   r   c                6    V P                   P                  4       # r   )r   r   rp   s   &r   r   ValueContext.is_bound_method   s    {{**,,r   c                6    V P                   P                  4       # r   )r   r   rp   s   &r   r   ValueContext.py__name__       {{%%''r   c                .    V P                   P                  # r   )r   r=   rp   s   &r   r=   ValueContext.name   s    {{r   c                6    V P                   P                  4       # r   )r   r   rp   s   &r   r    ValueContext.get_qualified_names   s    {{..00r   c                6    V P                   P                  4       # r   )r   r   rp   s   &r   r   ValueContext.py__doc__   r   r   c                    V P                   # r   r   rp   s   &r   r   ValueContext.get_value       {{r   c                R    V P                   P                  : R V P                  : R2# ())r   r   r   rp   s   &r   __repr__ValueContext.__repr__   s    >>22DKK@@r   r   )r   r   r   r   __doc__r   r   rK   rj   rq   ru   rx   r{   rb   r   r   r   r=   r   r   r   r   r   r   __classcell__r   r   s   @@r   r   r      s      % % * *'C&%))-(    1'A Ar   r   c                   8   a  ] tR t^t o R tR tR tR tRtV t	R# )TreeContextMixinc                    ^ RI Hp V! W4      # )r   )
infer_node)jedi.inference.syntax_treer   )r   r9   r   s   && r   r   TreeContextMixin.infer_node   s    9$%%r   c                   ^ RI Hp WP                  8X  d)   V P                  4       '       g   Q hV P	                  4       # V P                  V4      pVP                  R9   d   VP                  P                  W14      pVP                  4       '       do   VP                  P                  VP                  4      pVP                  V P                  VP                  V4      pVP                  VVP                  4       VR7      pV# VP                  R8X  d   VP!                  V P                  W14      # \#        RV,          4      h)r   )rE   )instanceclass_contextfunctionclassdefzProbably shouldn't happen: %s)funcdeflambdef)r*   rE   rK   rq   r   create_contextrH   FunctionValuefrom_contextrx   rj   create_valueAnonymousInstancer   BoundMethod
as_context
ClassValuer!   )r   r9   rE   rj   funcclass_valuer   s   &&     r   r   TreeContextMixin.create_value   s   (>>!>>####>>##,,T299..&&33NID&&((,;;HHIaIab 22((.*G*GV((%"-"8"8":! ) 
 KYY*$##D$8$8.OO%&E&LMMr   c                f  a aaa RVVVV 3R lloR oS! S4      pVP                   R9   d~   VP                  VP                  P                  R4      ,          pSP                  VP                  8  d7   SP                  pVP                   R8X  d   VP
                  S8X  g	   S! V4      pS! VR R7      # )Tc                 r  < V SP                   8X  d   S# V P                  R9   d    SP                  V 4      P                  4       # V P                  R9   dR   S! S! V P                  4      4      pSP
                  V P                  R,          P
                  8  d   V# \        W 4      # \        RV ,          4      h)r   z(There's a scope that was not managed: %s)r   r   r   r]   )	rK   rH   r   r   rG   	start_poschildrenCompForContext	Exception)
scope_node	is_nestedrj   from_scope_noder9   parent_scoper   s   && r   r   8TreeContextMixin.create_context.<locals>.from_scope_node   s    T^^+"DD((4??AA$AA!0j>O>O1P!Q>>Z%8%8%<%F%FF))%nAAFSTTr   c                 p    V P                   p \        P                  ! V 4      '       d   V # V P                  R9   d8   V P                  ^,          P                  R9   d   V P                  ^,          # Ks  V P                  R8X  g   K  V P                  R,           F  pVP                  R9   g   K  Vu # 	  K  )Tdictorsetmaker:      N)argumenttestlist_compr]   )rG   r   rF   rH   r   )r9   rg   s   & r   r   5TreeContextMixin.create_context.<locals>.parent_scope
  s    {{((..KYY"??}}Q',,0MM#}}Q// NYY"22!]]3//66%BB#$H 0r   :param)r   )T)r   r   )rH   r   indexr   rG   r=   )r   r9   r   colonrG   r   r   s   ff   @@r   r   TreeContextMixin.create_context   s    	U 	U	% "$'
??55''
(;(;(A(A#(FGE~~/w.6;;$3F!-j!9JzT::r   c                    VP                  4       pV'       dL   VP                  R 8X  d;   VP                  V8X  d*   \        VRR4      pV P	                  V4      p\        WA4      # V P                  V4      p\        WQ4      # )r  r   r   )get_definitionrH   r=   r   r   r   r   r   )r   	tree_name
definitionr   r   r7   s   &&    r   create_nameTreeContextMixin.create_name"  sm    --/
*//W4I9U%j)YGG$$W-D%d66)))4G%g99r   ro   N)
r   r   r   r   r   r   r   r	  r   r   r   s   @r   r   r      s      &N4$;L: :r   r   c                   *   a  ] tR tRt o RR ltRtV tR# )FunctionContexti-  Nc              #  D   "   \        V P                  V VVR 7      x  R# 5i)rj   r#   r$   N)r	   r   r"   s   &&&r   r%   FunctionContext.get_filters.  s$       )%	
 	
s    ro   r   r   r   r   r   r%   r   r   r   s   @r   r  r  -  s     
 
r   r  c                   h   a  ] tR tRt o V 3R lR ltRR ltR t]R 4       t]R 4       t	R	 t
R
tV tR# )ModuleContexti7  c                0   < V ^8  d   QhRS[ S[,          /#    returnr   r   )formatr   s   "r   __annotate__ModuleContext.__annotate__8       ( (HTN (r   c                6    V P                   P                  4       # r   r   
py__file__rp   s   &r   r  ModuleContext.py__file__8  r   r   Nc              #     "   V P                   P                  V4      p\        VR 4       \        \	        V VVR7      V P                  4       4      x  T R j  xL
  R #  L5i)Nr  )r   r%   nextr
   r	   get_global_filter)r   r#   r$   r1   s   &&& r   r%   ModuleContext.get_filters;  sZ     ++)),7Wd#-)
 ""$
 	
 s   AA AA c                    \        V 4      # r   )r   rp   s   &r   r"  ModuleContext.get_global_filterI  s    %%r   c                .    V P                   P                  # r   r   string_namesrp   s   &r   r(  ModuleContext.string_namesL      {{'''r   c                .    V P                   P                  # r   )r   
code_linesrp   s   &r   r,  ModuleContext.code_linesP  s    {{%%%r   c                    V P                   # )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.
r   rp   s   &r   r   ModuleContext.get_valueT  s     {{r   ro   r   )r   r   r   r   r  r%   r"  r   r(  r,  r   r   r   r   s   @r   r  r  7  sK     ( (& ( ( & & r   r  c                   R   a  ] tR tRt o R	R ltR t]R 4       tV 3R lR ltRt	V t
R# )
NamespaceContexti]  Nc                6    V P                   P                  4       # r   r   r%   r"   s   &&&r   r%   NamespaceContext.get_filters^  r   r   c                    V P                   # r   r   rp   s   &r   r   NamespaceContext.get_valuea  r   r   c                .    V P                   P                  # r   r'  rp   s   &r   r(  NamespaceContext.string_namesd  r*  r   c                0   < V ^8  d   QhRS[ S[,          /# r  r  )r  r   s   "r   r  NamespaceContext.__annotate__h  r  r   c                6    V P                   P                  4       # r   r  rp   s   &r   r  NamespaceContext.py__file__h  r   r   ro   r   )r   r   r   r   r%   r   r   r(  r  r   r   r   s   @r   r1  r1  ]  s-     ) ( (( (r   r1  c                   4   a  ] tR tRt o RR ltRR ltRtV tR# )ClassContextil  Nc              #  4   "   V P                  W4      x  R # 5ir   )r"  r"   s   &&&r   r%   ClassContext.get_filtersm  s     $$^BBs   c                    \        V VVR 7      # )r  r	   r"   s   &&&r   r"  ClassContext.get_global_filterp  s    )%
 	
r   ro   r   )r   r   r   r   r%   r"  r   r   r   s   @r   r>  r>  l  s     C
 
r   r>  c                   N   a a ] tR tRt oV 3R ltRR ltR tR tR tRt	Vt
V ;t# )	r   ix  c                R   < \         SV `  VP                  4       W n        Wn        R # r   )r   r   r   rK   rj   )r   rj   rC   r   s   &&&r   r   CompForContext.__init__y  s!    778!,r   c              #  (   "   \        V 4      x  R # 5ir   rB  r"   s   &&&r   r%   CompForContext.get_filters~  s     t$$s   c                    R # r   ro   rp   s   &r   r   CompForContext.get_value  s    r   c                    R # )z<comprehension context>ro   rp   s   &r   r   CompForContext.py__name__  s    (r   c                R    V P                   P                  : R V P                  : R2# r   )r   r   rK   rp   s   &r   r   CompForContext.__repr__  s    >>22DNNCCr   )rj   rK   r   )r   r   r   r   r   r%   r   r   r   r   r   r   r   s   @@r   r   r   x  s%     -
%)D Dr   r   c                   *   a  ] tR tRt o RR ltRtV tR# )CompiledContexti  Nc                6    V P                   P                  4       # r   r3  r"   s   &&&r   r%   CompiledContext.get_filters  r   r   ro   r   r  r   s   @r   rP  rP    s     ) )r   rP  c                   L   a  ] tR tRt o RtR t]R 4       tV 3R lR ltRt	V t
R# )CompiledModuleContexti  Nc                    V P                   # r   r   rp   s   &r   r   CompiledModuleContext.get_value  r   r   c                .    V P                   P                  # r   r'  rp   s   &r   r(  "CompiledModuleContext.string_names  r*  r   c                0   < V ^8  d   QhRS[ S[,          /# r  r  )r  r   s   "r   r  "CompiledModuleContext.__annotate__  r  r   c                6    V P                   P                  4       # r   r  rp   s   &r   r   CompiledModuleContext.py__file__  r   r   ro   )r   r   r   r   r,  r   r   r(  r  r   r   r   s   @r   rT  rT    s-     J ( (( (r   rT  c                 &   Ve   \        VRRR4      pR pVR8X  d   Tp\        VRR4      pVeY   VP                  R,          pVeB   W%P                  8  d2   Ve"   W$P                  R,          P                  8  d   VP                  p\        WV4      # )Nr   r   r   )r   r   r   get_global_filters)r7   name_or_noner0   ancestorr   r  s   &&&   r   r+   r+     s     "<J	Ry  G&|Y
KH%%b)E#??(B?h1A1A"1E1O1O&O'11Hg>>r   c              #    "   T p^ RI Hp V eC   V P                  VVR7       Rj  xL
  \        W\        34      '       d   RpV P
                  p KF  \        VP                  P                  P                  4       R4      pVf   Q hVx  R#  Le5i)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
<Function: func@3-5>
>>> 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(<ParserTreeFilter: ...>, <GlobalNameFilter: ...>)
>>> sorted(str(n) for n in filters[0].values())  # doctest: +NORMALIZE_WHITESPACE
['<TreeNameDefinition: string_name=func start_pos=(3, 4)>',
 '<TreeNameDefinition: string_name=x start_pos=(2, 0)>']
>>> 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
[...]
)BaseFunctionExecutionContextN)r#   r$   )	jedi.inference.value.functionrc  r%   r,   r  rj   r!  r   r   )r7   r#   r$   base_contextrc  r^   s   &&&   r   r_  r_    s     ^ LJ

&&)% ' 
 	
 	
 gmLMM!N((\))99EEGNA==
G	
s   #BBA&BN)'abcr   
contextlibr   pathlibr   typingr   
parso.treer   parso.python.treer   jedi.inference.filtersr	   r
   r   jedi.inference.namesr   r   jedi.inference.base_valuer   r   jedi.parser_utilsr   jedir   r   r   r   r   r  r  r1  r>  r   rP  rT  r+   r_  ro   r   r   <module>rq     s     %   & "  G 9 .  O' O'd6A? 6ArM: M:`
& 
#$l #L(' (	
#\ 	
D% D&)l )
(O (?*@r   