/ lib / IPython / core / completer.pyc
completer.pyc
   1  o

   2  .��c/��@s>UdZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
   3  Z
   4  ddlZddlZddl
Z
ddlZddlZddlZddlmZddlmZddlmZmZddlmZddlmZdd	lmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*dd
   5  l+m,Z,ddl-m.Z.ddl/m0Z0m1Z1dd
l2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;m<Z<ddl=m>Z>ddl?m@Z@ddlAmBZBddlCmDZDmEZEmFZFmZGmHZHm$ZIm!ZJmKZKmLZLddlMmNZNddlOZOdZPzddlQZQdeQjR_SddlTZQddlUZQdZVWneW�ydZVYnwe(�se>�rddlmXZXddlYmZZZm[Z[m\Z\m]Z]ndd�ZXe Z[e$ZZe^Z\e"Z]e>�r4ddlmZZZddgZ_d d!gZ`ejad"k�rEd#Zbnd$Zbd%Zcd&ZdGd'd(�d(ee�Zfejgd)efd*�e5ed�d,d-���Zhd.d/�Ziebfd0d1�Zjd�d6d7�Zkd�d;d<�Zld=d>�ZmGd?d@�d@�Zne!eQjojpenfZqGdAdB�dB�ZpGdCdD�dD�ZrGdEdF�dFeZ�Zse9ddGgdH�GdIdJ�dJeseZ��ZtGdKdL�dLes�ZueGdMdN�dN��Zve!eteufZwGdOdP�dPe\�ZxGdQdR�dRexe\�Zye!exeyfZzdSe{dT<GdUdV�dVe\�Z|e!eze|fZ}dSe{dW<d�dZd[�Z~ddd\d]�d�dcdd�Zd�dfdg�Z�d�dhdi�Z�djdk�Z�eedldm�Z�eepZ�d�dqdr�Z�dds�d�dudv�Z�ejad"k�r1dwZ�ndxZ�dyZ�Gdzd{�d{e^�Z�Gd|d �d eN�Z�d}d~�Z�	d�d�d�d��Z�d�d�d��Z�d�d�d��Z�d�d��Z�e��d�d�d���Z�d�d�d��Z�e��d�d�d���Z�d�d�d��Z�d�d�d��Z�d�d�d��Z�e$e�ewfZ�		d�d�d�d��Z�Gd�d!�d!e��Z�d�d�d��Z�dS)�u�Completion for IPython.
   6  
   7  This module started as fork of the rlcompleter module in the Python standard
   8  library.  The original enhancements made to rlcompleter have been sent
   9  upstream and were accepted as of Python 2.3,
  10  
  11  This module now support a wide variety of completion mechanism both available
  12  for normal classic Python code, as well as completer for IPython specific
  13  Syntax like magics.
  14  
  15  Latex and Unicode completion
  16  ============================
  17  
  18  IPython and compatible frontends not only can complete your code, but can help
  19  you to input a wide range of characters. In particular we allow you to insert
  20  a unicode character using the tab completion mechanism.
  21  
  22  Forward latex/unicode completion
  23  --------------------------------
  24  
  25  Forward completion allows you to easily type a unicode character using its latex
  26  name, or unicode long description. To do so type a backslash follow by the
  27  relevant name and press tab:
  28  
  29  
  30  Using latex completion:
  31  
  32  .. code::
  33  
  34      \alpha<tab>
  35      α
  36  
  37  or using unicode completion:
  38  
  39  
  40  .. code::
  41  
  42      \GREEK SMALL LETTER ALPHA<tab>
  43      α
  44  
  45  
  46  Only valid Python identifiers will complete. Combining characters (like arrow or
  47  dots) are also available, unlike latex they need to be put after the their
  48  counterpart that is to say, ``F\\vec<tab>`` is correct, not ``\\vec<tab>F``.
  49  
  50  Some browsers are known to display combining characters incorrectly.
  51  
  52  Backward latex completion
  53  -------------------------
  54  
  55  It is sometime challenging to know how to type a character, if you are using
  56  IPython, or any compatible frontend you can prepend backslash to the character
  57  and press ``<tab>`` to expand it to its latex form.
  58  
  59  .. code::
  60  
  61      \α<tab>
  62      \alpha
  63  
  64  
  65  Both forward and backward completions can be deactivated by setting the
  66  ``Completer.backslash_combining_completions`` option to ``False``.
  67  
  68  
  69  Experimental
  70  ============
  71  
  72  Starting with IPython 6.0, this module can make use of the Jedi library to
  73  generate completions both using static analysis of the code, and dynamically
  74  inspecting multiple namespaces. Jedi is an autocompletion and static analysis
  75  for Python. The APIs attached to this new mechanism is unstable and will
  76  raise unless use in an :any:`provisionalcompleter` context manager.
  77  
  78  You will find that the following are experimental:
  79  
  80      - :any:`provisionalcompleter`
  81      - :any:`IPCompleter.completions`
  82      - :any:`Completion`
  83      - :any:`rectify_completions`
  84  
  85  .. note::
  86  
  87      better name for :any:`rectify_completions` ?
  88  
  89  We welcome any feedback on these new API, and we also encourage you to try this
  90  module in debug mode (start IPython with ``--Completer.debug=True``) in order
  91  to have extra logging information if :any:`jedi` is crashing, or if current
  92  IPython completer pending deprecations are returning results not yet handled
  93  by :any:`jedi`
  94  
  95  Using Jedi for tab completion allow snippets like the following to work without
  96  having to execute any code:
  97  
  98     >>> myvar = ['hello', 42]
  99     ... myvar[1].bi<tab>
 100  
 101  Tab completion will be able to infer that ``myvar[1]`` is a real number without
 102  executing any code unlike the previously available ``IPCompleter.greedy``
 103  option.
 104  
 105  Be sure to update :any:`jedi` to the latest stable version or to try the
 106  current development version to get better completions.
 107  
 108  Matchers
 109  ========
 110  
 111  All completions routines are implemented using unified *Matchers* API.
 112  The matchers API is provisional and subject to change without notice.
 113  
 114  The built-in matchers include:
 115  
 116  - :any:`IPCompleter.dict_key_matcher`:  dictionary key completions,
 117  - :any:`IPCompleter.magic_matcher`: completions for magics,
 118  - :any:`IPCompleter.unicode_name_matcher`,
 119    :any:`IPCompleter.fwd_unicode_matcher`
 120    and :any:`IPCompleter.latex_name_matcher`: see `Forward latex/unicode completion`_,
 121  - :any:`back_unicode_name_matcher` and :any:`back_latex_name_matcher`: see `Backward latex completion`_,
 122  - :any:`IPCompleter.file_matcher`: paths to files and directories,
 123  - :any:`IPCompleter.python_func_kw_matcher` - function keywords,
 124  - :any:`IPCompleter.python_matches` - globals and attributes (v1 API),
 125  - ``IPCompleter.jedi_matcher`` - static analysis with Jedi,
 126  - :any:`IPCompleter.custom_completer_matcher` - pluggable completer with a default
 127    implementation in :any:`InteractiveShell` which uses IPython hooks system
 128    (`complete_command`) with string dispatch (including regular expressions).
 129    Differently to other matchers, ``custom_completer_matcher`` will not suppress
 130    Jedi results to match behaviour in earlier IPython versions.
 131  
 132  Custom matchers can be added by appending to ``IPCompleter.custom_matchers`` list.
 133  
 134  Matcher API
 135  -----------
 136  
 137  Simplifying some details, the ``Matcher`` interface can described as
 138  
 139  .. code-block::
 140  
 141      MatcherAPIv1 = Callable[[str], list[str]]
 142      MatcherAPIv2 = Callable[[CompletionContext], SimpleMatcherResult]
 143  
 144      Matcher = MatcherAPIv1 | MatcherAPIv2
 145  
 146  The ``MatcherAPIv1`` reflects the matcher API as available prior to IPython 8.6.0
 147  and remains supported as a simplest way for generating completions. This is also
 148  currently the only API supported by the IPython hooks system `complete_command`.
 149  
 150  To distinguish between matcher versions ``matcher_api_version`` attribute is used.
 151  More precisely, the API allows to omit ``matcher_api_version`` for v1 Matchers,
 152  and requires a literal ``2`` for v2 Matchers.
 153  
 154  Once the API stabilises future versions may relax the requirement for specifying
 155  ``matcher_api_version`` by switching to :any:`functools.singledispatch`, therefore
 156  please do not rely on the presence of ``matcher_api_version`` for any purposes.
 157  
 158  Suppression of competing matchers
 159  ---------------------------------
 160  
 161  By default results from all matchers are combined, in the order determined by
 162  their priority. Matchers can request to suppress results from subsequent
 163  matchers by setting ``suppress`` to ``True`` in the ``MatcherResult``.
 164  
 165  When multiple matchers simultaneously request surpression, the results from of
 166  the matcher with higher priority will be returned.
 167  
 168  Sometimes it is desirable to suppress most but not all other matchers;
 169  this can be achieved by adding a list of identifiers of matchers which
 170  should not be suppressed to ``MatcherResult`` under ``do_not_suppress`` key.
 171  
 172  The suppression behaviour can is user-configurable via
 173  :any:`IPCompleter.suppress_competing_matchers`.
 174  �)�annotationsN)�contextmanager)�	dataclass)�cached_property�partial)�
import_module)�SimpleNamespace)�Iterable�Iterator�List�Tuple�Union�Any�Sequence�Dict�
 175  NamedTuple�Pattern�Optional�
TYPE_CHECKING�Set�Literal)�TryNext)�	ESC_MAGIC)�
latex_symbols�reverse_latex_symbol)�
InspectColors)�skip_doctest)�generics)�sphinx_options)�dir2�get_real_method)�GENERATING_DOCUMENTATION)�ensure_dir_exists)�	arg_split)	�Bool�Enum�Intr�Unicoderr
�default�observe)�ConfigurableTF)�cast)�	TypedDict�NotRequired�Protocol�	TypeAliascC�|S)z=Workaround for `TypeError: MatcherAPIv2() takes no arguments`�)�obj�type_r1r1��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\IPython\core\completer.pyr+sr+)r,)� iK)ii��	Completer�IPCompleter�win32� z ()[]{}?=\|;:'#*"^&i�z	<unknown>c@seZdZdZdS)�ProvisionalCompleterWarningz�
 176      Exception raise by an experimental feature in this module.
 177  
 178      Wrap code in :any:`provisionalcompleter` context manager if you
 179      are certain you want to use an unstable feature.
 180      N)�__name__�
 181  __module__�__qualname__�__doc__r1r1r1r4r:+sr:�error��category�ignoreccsD�t���tj|td�dVWd�dS1swYdS)a�
 182      This context manager has to be used in any place where unstable completer
 183      behavior and API may be called.
 184  
 185      >>> with provisionalcompleter():
 186      ...     completer.do_experimental_things() # works
 187  
 188      >>> completer.do_experimental_things() # raises.
 189  
 190      .. note::
 191  
 192          Unstable
 193  
 194          By using this context manager you agree that the API in use may change
 195          without warning, and that you won't complain if they do so.
 196  
 197          You also understand that, if the API is not to your liking, you should report
 198          a bug to explain your use case upstream.
 199  
 200          We'll be happy to get your feedback, feature requests, and improvements on
 201          any of the unstable APIs!
 202      r@N)�warnings�catch_warnings�filterwarningsr:)�actionr1r1r4�provisionalcompleter7s
 203  �
 204  "�rGcCs(|�d�dr	dS|�d�drdSdS)aReturn whether a string has open quotes.
 205  
 206      This simply counts whether the number of quote characters of either type in
 207      the string is odd.
 208  
 209      Returns
 210      -------
 211      If there is an open quote, the quote character is returned.  Else, return
 212      False.
 213      �"��'F)�count��sr1r1r4�has_open_quotesUs
 214  
rNcsBt|�t��@rtjdkrd|dSd��fdd�|D��S|S)z.Escape a string to protect certain characters.r8rH�c3s$�|]
}|�vrd|n|VqdS��\Nr1��.0�c��protectablesr1r4�	<genexpr>ps�"z#protect_filename.<locals>.<genexpr>)�set�sys�platform�join)rMrVr1rUr4�protect_filenamejs
 215  
 216  r\�path�str�return�Tuple[str, bool, str]cCsTd}d}|}|�d�r%d}t|�d}tj�|�}|r#|d|�}n|}|||fS)a�Expand ``~``-style usernames in strings.
 217  
 218      This is similar to :func:`os.path.expanduser`, but it computes and returns
 219      extra information that will be useful if the input was being used in
 220      computing completions, and you wish to return the completions with the
 221      original '~' instead of its expanded value.
 222  
 223      Parameters
 224      ----------
 225      path : str
 226          String to be expanded.  If no ~ is present, the output is the same as the
 227          input.
 228  
 229      Returns
 230      -------
 231      newpath : str
 232          Result of ~ expansion in the input path.
 233      tilde_expand : bool
 234          Whether any expansion was performed or not.
 235      tilde_val : str
 236          The value that ~ was replaced with.
 237      FrO�~T�N)�
 238  startswith�len�osr]�
 239  expanduser)r]�tilde_expand�	tilde_val�newpath�restr1r1r4�expand_userus
 240  
 241  rkrg�boolrhcCs|r|�|d�S|S)z8Does the opposite of expand_user, with its outputs.
 242      ra��replace)r]rgrhr1r1r4�
compress_user�srocCs�d\}}|�d�rd}n|�d�rd}|�d�rd}|�d�r0d	|dd
 243  �vr/|dd
 244  �}d}n|�d	�rEd	|dd
 245  �vrE|dd
 246  �}d}|||fS)z�key for sorting completions
 247  
 248      This does several things:
 249  
 250      - Demote any completions starting with underscores to the end
 251      - Insert any %magic and %%cellmagic completions in the alphabetical order
 252        by their name
 253      )rr�__rI�_rb�=�����z%%�%N)rc�endswith)�wordZprio1Zprio2r1r1r4�completions_sorting_key�s"	
 254  
 255  
 256  
 257  �
 258  
 259  rwc@s eZdZdZdd�Zdd�ZdS)�_FakeJediCompletionz�
 260      This is a workaround to communicate to the UI that Jedi has crashed and to
 261      report a bug. Will be used only id :any:`IPCompleter.debug` is set to true.
 262  
 263      Added in IPython 6.0 so should likely be removed for 7.0
 264  
 265      cCs(||_||_d|_||_d|_d|_dS)NZcrashedrO�fake)�name�complete�type�name_with_symbols�	signature�_origin)�selfrzr1r1r4�__init__�s
 266  z_FakeJediCompletion.__init__cC�dS)Nz)<Fake completion object jedi has crashed>r1�r�r1r1r4�__repr__�sz_FakeJediCompletion.__repr__N)r;r<r=r>r�r�r1r1r1r4rx�s	rxc@sFeZdZdZgd�Zdddd�ddd�Zdd�Zddd�Zdd�ZdS)�
 267  Completionao
 268      Completion object used and returned by IPython completers.
 269  
 270      .. warning::
 271  
 272          Unstable
 273  
 274          This function is unstable, API may change without warning.
 275          It will also raise unless use in proper context manager.
 276  
 277      This act as a middle ground :any:`Completion` object between the
 278      :any:`jedi.api.classes.Completion` object and the Prompt Toolkit completion
 279      object. While Jedi need a lot of information about evaluator and how the
 280      code should be ran/inspected, PromptToolkit (and other frontend) mostly
 281      need user facing information.
 282  
 283      - Which range should be replaced replaced by what.
 284      - Some metadata (like completion type), or meta information to displayed to
 285        the use user.
 286  
 287      For debugging purpose we can also store the origin of the completion (``jedi``,
 288      ``IPython.python_matches``, ``IPython.magics_matches``...).
 289      ��start�end�textr|r~rNrO�r|rr~r��intr�r�r^r|r_�NonecCs8tjdtdd�||_||_||_||_||_||_dS)Nz~``Completion`` is a provisional API (as of IPython 6.0). It may change without warnings. Use in corresponding context manager.rI�rA�
 290  stacklevel)	rC�warnr:r�r�r�r|r~r)r�r�r�r�r|rr~r1r1r4r��s�
 291  zCompletion.__init__cCs$d|j|j|j|jpd|jpdfS)Nz;<Completion start=%s end=%s text=%r type=%r, signature=%r,>�?)r�r�r�r|r~r�r1r1r4r�s�zCompletion.__repr__r$cCs$|j|jko|j|jko|j|jkS)a]
 292          Equality and hash do not hash the type (as some completer may not be
 293          able to infer the type), but are use to (partially) de-duplicate
 294          completion.
 295  
 296          Completely de-duplicating completion is a bit tricker that just
 297          comparing as it depends on surrounding text, which Completions are not
 298          aware of.
 299          )r�r�r�)r��otherr1r1r4�__eq__s
 300  
 301  
 302  �
 303  �zCompletion.__eq__cCst|j|j|jf�S�N)�hashr�r�r�r�r1r1r4�__hash__szCompletion.__hash__)
 304  r�r�r�r�r�r^r|r^r_r�)r_r$)	r;r<r=r>�	__slots__r�r�r�r�r1r1r1r4r��s
 305  r�c@s0eZdZdZddgZdd�ddd�Zd	d
 306  �ZdS)�SimpleCompletiona�Completion item to be included in the dictionary returned by new-style Matcher (API v2).
 307  
 308      .. warning::
 309  
 310          Provisional
 311  
 312          This class is used to describe the currently supported attributes of
 313          simple completion items, and any additional implementation details
 314          should not be relied on. Additional attributes may be included in
 315          future versions, and meaning of text disambiguated from the current
 316          dual meaning of "text to insert" and "text to used as a label".
 317      r�r|N�r|r^cCs||_||_dSr��r�r|)r�r�r|r1r1r4r�-s
 318  zSimpleCompletion.__init__cCsd|j�d|j�d�S)Nz<SimpleCompletion text=z type=�>r�r�r1r1r4r�1szSimpleCompletion.__repr__)r�r^r|r^)r;r<r=r>r�r�r�r1r1r1r4r�s
 319  
r�c@s2eZdZUdZded<ded<ded<ded	<d
 320  S)�_MatcherResultBasezFDefinition of dictionary to be returned by new-style Matcher (API v2).zNotRequired[str]�matched_fragmentz"NotRequired[Union[bool, Set[str]]]�suppresszNotRequired[Set[str]]�do_not_suppresszNotRequired[bool]�orderedN�r;r<r=r>�__annotations__r1r1r1r4r�5s
 321  r��dict)�show_inherited_members�exclude_inherited_fromc@�eZdZUdZded<dS)�SimpleMatcherResultz'Result of new-style completion matcher.�Sequence[SimpleCompletion]�completionsNr�r1r1r1r4r�Gs
 322  r�c@r�)�_JediMatcherResultz@Matching result returned by Jedi (will be processed differently)�Iterable[_JediCompletionLike]r�Nr�r1r1r1r4r�Rs
 323  r�c@sVeZdZUdZded<ded<ded<ded<ded	<eddd��Zedd
d��ZdS)�CompletionContextzMCompletion context provided as an argument to matchers in the Matcher API v2.r^�token�	full_textr��cursor_position�cursor_linez
Optional[int]�limitr_cCs|jd|j�Sr�)�line_with_cursorr�r�r1r1r4�text_until_cursorw�z#CompletionContext.text_until_cursorcCs|j�d�|jS)N�
 324  )r��splitr�r�r1r1r4r�{sz"CompletionContext.line_with_cursorN�r_r^)r;r<r=r>r�rr�r�r1r1r1r4r�Ys
 325  r�c@seZdZddd�ZdS)	�_MatcherAPIv1Baser�r^r_�	list[str]cCr��zCall signature.Nr1�r�r�r1r1r4�__call__��z_MatcherAPIv1Base.__call__N�r�r^r_r�)r;r<r=r�r1r1r1r4r��sr�c@s eZdZUded<d
 326  dd�Zd	S)�_MatcherAPIv1TotalzOptional[Literal[1]]�matcher_api_versionr�r^r_r�cCr�r�r1r�r1r1r4r��r�z_MatcherAPIv1Total.__call__Nr�)r;r<r=r�r�r1r1r1r4r��s
 327  r�r/�MatcherAPIv1c@s(eZdZUdZdZded<dd	d
 328  �ZdS)
�MatcherAPIv2z#Protocol describing Matcher API v2.rIz
 329  Literal[2]r��contextr�r_�
MatcherResultcCr�r�r1)r�r�r1r1r4r��r�zMatcherAPIv2.__call__N)r�r�r_r�)r;r<r=r>r�r�r�r1r1r1r4r��s
 330  r��Matcher�resultr�cCs\t|dd�rt|d�dkSz|d}t|�}t�|g|�|d<WdSty-YdSw)z-Check if any result includes any completions.r��__len__rTF)�hasattrrd�next�	itertools�chain�
StopIteration)r�Zold_iterator�firstr1r1r4�has_any_completions�s�r�rb)�priority�
 331  identifier�api_versionr��floatr�r�r�csd���fdd�}|S)aWAdds attributes describing the matcher.
 332  
 333      Parameters
 334      ----------
 335      priority : Optional[float]
 336          The priority of the matcher, determines the order of execution of matchers.
 337          Higher priority means that the matcher will be executed first. Defaults to 0.
 338      identifier : Optional[str]
 339          identifier of the matcher allowing users to modify the behaviour via traitlets,
 340          and also used to for debugging (will be passed as ``origin`` with the completions).
 341  
 342          Defaults to matcher function's ``__qualname__`` (for example,
 343          ``IPCompleter.file_matcher`` for the built-in matched defined
 344          as a ``file_matcher`` method of the ``IPCompleter`` class).
 345      api_version: Optional[int]
 346          version of the Matcher API used by this matcher.
 347          Currently supported values are 1 and 2.
 348          Defaults to 1.
 349      �funcr�csL�pd|_�p	|j|_�|_tr$�dkrt|t�}|S�dkr$t|t�}|S)NrrbrI)�matcher_priorityr=�matcher_identifierr�rr+r�r�)r��r�r�r�r1r4�wrapper�s
 350  
 351  �
 352  z#completion_matcher.<locals>.wrapperN)r�r�r1)r�r�r�r�r1r�r4�completion_matcher�sr��matchercC�t|dd�S)Nr�r��getattr�r�r1r1r4�_get_matcher_priority��r�cCst|d|j�S)Nr�)r�r=r�r1r1r4�_get_matcher_id��r�cCr�)Nr�rbr�r�r1r1r4�_get_matcher_api_version�r�r�rI)r�r�r��_ICccs��t|�}|s	dStdd�|D��}tdd�|D��}t�}|D]}|||j�|j||j|�}||vr?|V|�|�q dS)a
 353      Deduplicate a set of completions.
 354  
 355      .. warning::
 356  
 357          Unstable
 358  
 359          This function is unstable, API may change without warning.
 360  
 361      Parameters
 362      ----------
 363      text : str
 364          text that should be completed.
 365      completions : Iterator[Completion]
 366          iterator over the completions to deduplicate
 367  
 368      Yields
 369      ------
 370      `Completions` objects
 371      Completions coming from multiple sources, may be different but end up having
 372      the same effect when applied to ``text``. If this is the case, this will
 373      consider completions as equal and only emit the first encountered.
 374      Not folded in `completions()` yet for debugging purpose, and to detect when
 375      the IPython completer does return things that Jedi does not, but should be
 376      at some point.
 377      Ncs��|]}|jVqdSr��r�rRr1r1r4rW��z+_deduplicate_completions.<locals>.<genexpr>csr�r��r�rRr1r1r4rWr�)�list�min�maxrXr�r�r��add)r�r��	new_start�new_end�seenrT�new_textr1r1r4�_deduplicate_completions�s�"
 378  ��r�)�_debugr�c	cs��tjdtdd�t|�}|sdSdd�|D�}dd�|D�}t|�}t|�}t�}t�}|D]6}	|||	j�|	j||	j	|�}
 379  |	j
 380  dkrM|�|
 381  �n
 382  |	j
 383  d	krW|�|
 384  �t|||
 385  |	j
|	j
 386  |	jd
 387  �Vq/|�|�}|rv|rxtd|�dSdSdS)a�
 388      Rectify a set of completions to all have the same ``start`` and ``end``
 389  
 390      .. warning::
 391  
 392          Unstable
 393  
 394          This function is unstable, API may change without warning.
 395          It will also raise unless use in proper context manager.
 396  
 397      Parameters
 398      ----------
 399      text : str
 400          text that should be completed.
 401      completions : Iterator[Completion]
 402          iterator over the completions to rectify
 403      _debug : bool
 404          Log failed completion
 405  
 406      Notes
 407      -----
 408      :any:`jedi.api.classes.Completion` s returned by Jedi may not have the same start and end, though
 409      the Jupyter Protocol requires them to behave like so. This will readjust
 410      the completion to have the same ``start`` and ``end`` by padding both
 411      extremities with surrounding text.
 412  
 413      During stabilisation should support a ``_debug`` option to log which
 414      completion are return by the IPython completer and not found in Jedi in
 415      order to make upstream bug report.
 416      z�`rectify_completions` is a provisional API (as of IPython 6.0). It may change without warnings. Use in corresponding context manager.rIr�Ncsr�r�r�rRr1r1r4rW7r�z&rectify_completions.<locals>.<genexpr>csr�r�r�rRr1r1r4rW8r��jedi�IPCompleter.python_matchesr�z#IPython.python matches have extras:)rCr�r:r�r�r�rXr�r�r�rr�r�r|r~�
 417  difference�print)r�r�r��starts�endsr�r�Z	seen_jediZseen_python_matchesrTr��diffr1r1r4�rectify_completionss0��"
 418  
 419  
 420  
 421  �r�z 	
 422  `!@#$^&*()=+[{]}|;'",<>?z 	
 423  `!@#$^&*()=+[{]}\|;:'",<>?z =
 424  c@sJeZdZdZeZdZdZd
 425  dd�Ze	dd��Z
 426  e
 427  jdd��Z
 428  d
 429  dd	�ZdS)�CompletionSplitteraWAn object to split an input line in a manner similar to readline.
 430  
 431      By having our own implementation, we can expose readline-like completion in
 432      a uniform manner to all frontends.  This object only needs to be given the
 433      line of text to be split and the cursor position on said line, and it
 434      returns the 'word' to be completed on at the cursor after splitting the
 435      entire line.
 436  
 437      What characters are used as splitting delimiters can be controlled by
 438      setting the ``delims`` attribute (this is a property that internally
 439      automatically builds the necessary regular expression)NcCs|durtjn|}||_dSr�)r��_delims�delims)r�r�r1r1r4r�ns
 440  zCompletionSplitter.__init__cCs|jS)z*Return the string of delimiter characters.)r�r�r1r1r4r�rszCompletionSplitter.delimscCs8dd�dd�|D��d}t�|�|_||_||_dS)z&Set the delimiters for line splitting.�[rOcs��|]}d|VqdSrPr1rRr1r1r4rWz��z,CompletionSplitter.delims.<locals>.<genexpr>�]N)r[�re�compile�	_delim_rer��_delim_expr)r�r��exprr1r1r4r�ws
 441  cCs(|dur|n|d|�}|j�|�dS)zBSplit a line of text with a cursor at the given position.
 442          Nrs)rr�)r��line�
 443  cursor_pos�lr1r1r4�
 444  split_lineszCompletionSplitter.split_liner�)
r;r<r=r>�DELIMSr�rrr��propertyr��setterrr1r1r1r4r�Ss
 445  
 446  
 447  r�cs�eZdZeddd�jdd�Zeedd�jdd�Zedd	d�jdd�Z	edd
 448  d�jdd�Z
 449  eddd�jdd�Zd�fd
d�	Zdd�Z
dd�Zdd�Z�ZS)r6FaActivate greedy completion
 450          PENDING DEPRECATION. this is now mostly taken care of with Jedi.
 451  
 452          This will enable completion on elements of lists, results of function calls, etc.,
 453          but can be unsafe because the code is actually evaluated on TAB.
 454          ��helpT��configzYExperimental: Use Jedi to generate autocompletions. Default to True if jedi is installed.��
default_valuer
i�z�Experimental: restrict time (in milliseconds) during which Jedi can compute types.
 455          Set to 0 to stop computing types. Non-zero value lower than 100ms may hurt
 456          performance by preventing jedi to build its cache.
 457          zaEnable debug for the Completer. Mostly print extra information for experimental jedi integration.z�Enable unicode completions, e.g. \alpha<tab> . Includes completion of latex commands, unicode names, and expanding unicode characters back to latex commands.NcsR|durd|_nd|_||_|duri|_n||_g|_tt|�jdi|��dS)a�Create a new completer for the command line.
 458  
 459          Completer(namespace=ns, global_namespace=ns2) -> completer instance.
 460  
 461          If unspecified, the default namespace where completions are performed
 462          is __main__ (technically, __main__.__dict__). Namespaces should be
 463          given as dictionaries.
 464  
 465          An optional second namespace can be given.  This allows the completer
 466          to handle cases where both the local and global scopes need to be
 467          distinguished.
 468          NTFr1)�use_main_ns�	namespace�global_namespace�custom_matchers�superr6r�)r�rr�kwargs��	__class__r1r4r��szCompleter.__init__cCsZ|jrtj|_|dkrd|vr|�|�|_n|�|�|_z|j|WSty,YdSw)z�Return the next possible completion for 'text'.
 469  
 470          This is called successively with state == 0, 1, 2, ... until it
 471          returns None.  The completion should begin with 'text'.
 472  
 473          r�.N)r�__main__�__dict__r�attr_matches�matches�global_matches�
 474  IndexError)r�r��stater1r1r4r{�s�zCompleter.completecs�g}|j}t|�}tjtj��t|j���t|j	���fD]}|D]}|d|�|kr3|dkr3||�q!qt
 475  �d��t|j���t|j	���fD]$}�fdd�|D�}|��D]}|d|�|krk|dkrk|||�qWqH|S)z�Compute matches when text is a simple name.
 476  
 477          Return a list of all keywords, built-in functions and names currently
 478          defined in self.namespace or self.global_namespace that match.
 479  
 480          N�__builtins__z[^_]+(_[^_]+)+?\Zcs2i|]}��|�rd�dd�|�d�D��|�qS)rqcSsg|]}|d�qS)rr1)rS�subr1r1r4�
 481  <listcomp>��z7Completer.global_matches.<locals>.<dictcomp>.<listcomp>)�matchr[r�)rSrv�Z
snake_case_rer1r4�
 482  <dictcomp>�s��z,Completer.global_matches.<locals>.<dictcomp>)�appendrd�keyword�kwlist�builtin_modr�keysr�rrrr)r�r�rZmatch_append�n�lstrvZ	shortenedr1r'r4r�s0���
 483   
 484  ���zCompleter.global_matchesc	st�d|�}|r|�dd�\��n|jr(t�d|j�}|sgS|�dd�\��ngSzt�|j�}Wnzt�|j�}Wn	gYYSY|jrVt	|d�rVt
 485  |�}nt|�}zt�
||�}WntykYntyr�tyzYnwt������fdd�|D�S)	a�Compute matches when text contains a dot.
 486  
 487          Assuming the text is of the form NAME.NAME....[NAME], and is
 488          evaluatable in self.namespace or self.global_namespace, it will be
 489          evaluated and its attributes (as revealed by dir()) are used as
 490          possible completions.  (For class instances, class members are
 491          also considered.)
 492  
 493          WARNING: this can still invoke arbitrary C code, if an object
 494          with a __getattr__ hook is evaluated.
 495  
 496          z(\S+(\.\w+)*)\.(\w*)$rb�z(.+)\.(\w*)$rI�__all__cs(g|]}|d���krd�|f�qS)Nz%s.%sr1�rS�w��attrrr.r1r4r$/s(z*Completer.attr_matches.<locals>.<listcomp>)rr&�group�greedy�line_buffer�evalrr�limit_to__all__r��get__all__entriesrr�complete_objectr�AssertionError�	Exceptionrd)r�r��m�m2r2�wordsr1r4r4r�s>�
 497  �zCompleter.attr_matches)NN)r;r<r=r$�tagr7�JEDI_INSTALLED�use_jedir&�jedi_compute_type_timeout�debug�backslash_combining_completionsr�r{rr�
__classcell__r1r1rr4r6�s<��	��������! cCs,zt|d�}WngYSdd�|D�S)z,returns the strings in the __all__ attributer1cSsg|]	}t|t�r|�qSr1)�
 498  isinstancer^r2r1r1r4r$9�z%get__all__entries.<locals>.<listcomp>r�)r2rAr1r1r4r;2s
 499  r;r-�1List[Union[str, bytes, Tuple[Union[str, bytes]]]]�prefixr��extra_prefix�Optional[Tuple[str, bytes]]�Tuple[str, int, List[str]]cs�|r|nd�t�����fdd�}g��fdd�}|D]}t|t�r-||�r,||��q||�q|s>dddd	��D�fSt�d
 500  |�}|dusJJ�|��}z	t||i�}	WntyeddgfYSwdd�d
d�|D��d}
 501  t�|
 502  |tj	�}|dus�J�|�
 503  �}|��}
g}�D]O}z	|�|	�s�Wq�Wntt
tfy�Yq�w|t|	�d�}t|t�r�t|d�nt|d�}|d|�d�d�}|dkr�|�dd�}|�d|
|f�q�|||fS)a*Used by dict_key_matches, matching the prefix to a list of keys
 504  
 505      Parameters
 506      ----------
 507      keys
 508          list of keys in dictionary currently being completed.
 509      prefix
 510          Part of the text already typed by the user. E.g. `mydict[b'fo`
 511      delims
 512          String of delimiters to consider when finding the current key.
 513      extra_prefix : optional
 514          Part of the text already typed in multi-key index cases. E.g. for
 515          `mydict['foo', "bar", 'b`, this would be `('foo', 'bar')`.
 516  
 517      Returns
 518      -------
 519      A tuple of three elements: ``quote``, ``token_start``, ``matched``, with
 520      ``quote`` being the quote that need to be used to close current string.
 521      ``token_start`` the position where the replacement should start occurring,
 522      ``matches`` a list of replacement/completion
 523  
 524      r1csTt|��krdS|D]}t|ttf�sdSq
 525  t|��D]\}}||kr'dSqdS)NFT)rdrIr^�bytes�zip)�key�k�pt)�Nprefix�prefix_tupler1r4�filter_prefix_tupleVs��z,match_dict_keys.<locals>.filter_prefix_tuplecs t|ttf�r��|�dSdSr�)rIr^rPr)�rR)�
filtered_keysr1r4�_add_to_filtered_keysfs�z.match_dict_keys.<locals>._add_to_filtered_keysrOrcSsg|]}t|��qSr1)�repr�rSrSr1r1r4r$rr%z#match_dict_keys.<locals>.<listcomp>z["']Nz[^csr�rPr1rRr1r1r4rW{r�z"match_dict_keys.<locals>.<genexpr>z]*$rH�"rbrJ�����z\"z%s%s)rdrI�tupler�searchr6r9r>r[�UNICODEr�rc�AttributeError�	TypeError�UnicodeErrorr^r[�indexrnr))r-rLr�rMrWrZrSZquote_match�quoteZ
 526  prefix_str�patternZtoken_matchZtoken_startZtoken_prefix�matchedrR�remZrem_reprr1)rUrYrVr4�match_dict_keys<sT
 527  �
 528  �
 529  ��"
 530  rjr�columncCsP|�d�}|t|�ksJd�t|�tt|�����tdd�|d|�D��|S)a�
 531      Convert the (line,column) position of the cursor in text to an offset in a
 532      string.
 533  
 534      Parameters
 535      ----------
 536      text : str
 537          The text in which to calculate the cursor offset
 538      line : int
 539          Line of the cursor; 0-indexed
 540      column : int
 541          Column of the cursor 0-indexed
 542  
 543      Returns
 544      -------
 545      Position of the cursor in ``text``, 0-indexed.
 546  
 547      See Also
 548      --------
 549      position_to_cursor : reciprocal of this function
 550  
 551      r�z{} <= {}css�|]	}t|�dVqdS)rbN)rd)rSrr1r1r4rW�s�z%cursor_to_position.<locals>.<genexpr>N)r�rd�formatr^�sum)r�rrk�linesr1r1r4�cursor_to_position�s
 552  (ro�offset�Tuple[int, int]cCsbd|krt|�ksnJd|t|�f��|d|�}|�d�}|�d�}t|d�}||fS)a:
 553      Convert the position of the cursor in text (0 indexed) to a line
 554      number(0-indexed) and a column number (0-indexed) pair
 555  
 556      Position should be a valid position in ``text``.
 557  
 558      Parameters
 559      ----------
 560      text : str
 561          The text in which to calculate the cursor offset
 562      offset : int
 563          Position of the cursor in ``text``, 0-indexed.
 564  
 565      Returns
 566      -------
 567      (line, column) : (int, int)
 568          Line of the cursor; 0-indexed, column of the cursor 0-indexed
 569  
 570      See Also
 571      --------
 572      cursor_to_position : reciprocal of this function
 573  
 574      rz
0 <= %s <= %sNr�rs)rdr�rK)r�rp�beforeZblinesr�colr1r1r4�position_to_cursor�s.
 575  
 576  rtcCs|tjvot|tt|�|��S)z@Checks if obj is an instance of module.class_name if loaded
 577      )rY�modulesrIr�r)r2�module�
 578  class_namer1r1r4�_safe_isinstance�s
 579  �rxr�cC�t|j�\}}t|d|dd�S)z�Match Unicode characters back to Unicode name
 580  
 581      Same as :any:`back_unicode_name_matches`, but adopted to new Matcher API.
 582      �unicodeT�r|�fragment�suppress_if_matches)�back_unicode_name_matchesr�� _convert_matcher_v1_result_to_v2�r�r|rr1r1r4�back_unicode_name_matcher���r��Tuple[str, Sequence[str]]cCsvt|�dkrdS|d}|dkrdS|d}|tjvs|dvr!dSzt�|�}d|d|ffWSty:YdSw)u�Match Unicode characters back to Unicode name
 583  
 584      This does  ``☃`` -> ``\snowman``
 585  
 586      Note that snowman is not a valid python3 combining character but will be expanded.
 587      Though it will not recombine back to the snowman character by the completion machinery.
 588  
 589      This will not either back-complete standard sequences like \n, \b ...
 590  
 591      .. deprecated:: 8.6
 592          You can use :meth:`back_unicode_name_matcher` instead.
 593  
 594      Returns
 595      =======
 596  
 597      Return a tuple with two elements:
 598  
 599      - The Unicode character that was matched (preceded with a backslash), or
 600          empty string,
 601      - a sequence (of 1), name for the match Unicode character, preceded by
 602          backslash, or empty if no match.
 603      rI�rOr1r^rQrs�rHrJ)rd�string�
ascii_letters�unicodedatarz�KeyError)r��maybe_slash�char�unicr1r1r4r~�s
 604  �r~cCry)z}Match latex characters back to unicode name
 605  
 606      Same as :any:`back_latex_name_matches`, but adopted to new Matcher API.
 607      �latexTr{)�back_latex_name_matchesr�rr�r1r1r4�back_latex_name_matcherr�r�cCspt|�dkrdS|d}|dkrdS|d}|tjvs|dvr!dSzt|}d||gfWSty7YdSw)u�Match latex characters back to unicode name
 608  
 609      This does ``\ℵ`` -> ``\aleph``
 610  
 611      .. deprecated:: 8.6
 612          You can use :meth:`back_latex_name_matcher` instead.
 613      rIr�r^rQrsr�)rdr�r�rr�)r�r�r�r�r1r1r4r�!s�r�cCs(|j}|�d�std|��|dd�S)a
 614      Get parameter name and value from Jedi Private API
 615  
 616      Jedi does not expose a simple way to get `param=value` from its API.
 617  
 618      Parameters
 619      ----------
 620      parameter
 621          Jedi's function `Param`
 622  
 623      Returns
 624      -------
 625      A string like 'a', 'b=1', '*args', '**kwargs'
 626  
 627      zparam zWJedi function parameter description have change format.Expected "param ...", found %r".�N)�descriptionrc�
 628  ValueError)�	parameterr�r1r1r4�_formatparamchildren>s
 629  �r�cCsft|d�r |��}|s
dS|��d}d|��jddd�dSdd�d	d
 630  �dd�|��D�D��S)
aR
 631      Make the signature from a jedi completion
 632  
 633      Parameters
 634      ----------
 635      completion : jedi.Completion
 636          object does not complete a function type
 637  
 638      Returns
 639      -------
 640      a string consisting of the function signature, with the parenthesis but
 641      without the function name. example:
 642      `(a, *args, b=1, **kwargs)`
 643  
 644      �get_signaturesz(?)r�(rb)�maxsplitz(%s)z, cSsg|]}|r|�qSr1r1�rS�fr1r1r4r$ns
 645  �z#_make_signature.<locals>.<listcomp>css&�|]}|��D]}t|�VqqdSr�)�
defined_namesr�)rSr~�pr1r1r4rWns���z"_make_signature.<locals>.<genexpr>)r�r��	to_stringr�r[)�
 646  completion�
 647  signatures�c0r1r1r4�_make_signatureTs
 648  &r�r�
Sequence[str]r|r|r}cs<�fdd�|D�|r|rdndndd�}|dur||d<|S)zUtility to help with transitioncsg|]}t|�d��qS)r�)r�)rSr&r�r1r4r$}�z4_convert_matcher_v1_result_to_v2.<locals>.<listcomp>TF�r�r�Nr�r1)rr|r|r}r�r1r�r4rus�rcs�eZdZUdZdZded<ed�dd��Zedd	d
 649  �Z	e
 650  edd�eeddd��gdd
d�jdd�Z
eddd
 651  �jdd�Zee�dd
 652  �jdd�Zedddd�jdd�Zeddd
 653  �jdd�Zeddd�jdd�Zeddd�jdd�Zed�dd��Z	d��fdd�	Zed�d d!��Zd�d%d&�Zd�d'd(�Zd�d)d*�Ze�d�d.d/��Zd�d0d1�Z e�d�d2d3��Z!d�d4d5�Z"e�d�d6d7��Z#d�d8d9�Z$e�d�d:d;��Z%d�d<d=�Z&ed>d?�d�dAdB��Z'd�dGdH�Z(d�dJdK�Z)dLdM�Z*dNdO�Z+e�d�dPdQ��Z,dRdS�Z-e.d�dWdX��Z/e�d�dYdZ��Z0d�d[d\�Z1e�d�d]d^��Z2e.d�d`da��Z3e�d�dbdc��Z4d�dedf�Z5e�dgdh��Z6didj�Z7d�dmdn�Z8d�dpdq�Z9d�d�drds�Z:d�dzd{�Z;dddd|�d�d~d�Z<e.d�d�d���Z=e.d�d�d���Z>e�d�d�d���Z?d�d�d��Z@ed�d�d���ZA�ZBS)�r7z?Extension of the completer class with IPython-specific featuresNzOptional[Dict[bool, Pattern]]�_IPCompleter__dict_key_regexpsr7cCs |dr
 654  t|j_dSt|j_dS)z>update the splitter and readline delims when greedy is changed�newN)�
GREEDY_DELIMS�splitterr�r	�r��changer1r1r4�_greedy_changed�szIPCompleter._greedy_changedFz�
 655          Whether to show dict key matches only.
 656          
 657          (disables all matchers except for `IPCompleter.dict_key_matcher`).
 658          rT)�
 659  allow_noneag
 660          Whether to suppress completions from other *Matchers*.
 661  
 662          When set to ``None`` (default) the matchers will attempt to auto-detect
 663          whether suppression of other matchers is desirable. For example, at
 664          the beginning of a line followed by `%` we expect a magic completion
 665          to be the only applicable option, and after ``my_dict['`` we usually
 666          expect a completion with an existing dictionary key.
 667  
 668          If you want to disable this heuristic and see completions from all matchers,
 669          set ``IPCompleter.suppress_competing_matchers = False``.
 670          To disable the heuristic for specific matchers provide a dictionary mapping:
 671          ``IPCompleter.suppress_competing_matchers = {'IPCompleter.dict_key_matcher': False}``.
 672  
 673          Set ``IPCompleter.suppress_competing_matchers = True`` to limit
 674          completions to the set of matchers with the highest priority;
 675          this is equivalent to ``IPCompleter.merge_completions`` and
 676          can be beneficial for performance, but will sometimes omit relevant
 677          candidates from matchers further down the priority list.
 678          rra6Whether to merge completion results into a single list
 679  
 680          If False, only the completion results from the first non-empty
 681          completer will be returned.
 682  
 683          As of version 8.6.0, setting the value to ``False`` is an alias for:
 684          ``IPCompleter.suppress_competing_matchers = True.``.
 685          z{List of matchers to disable.
 686  
 687          The list should contain matcher identifiers (see :any:`completion_matcher`).
 688          )rrbrIrIa1Instruct the completer to omit private method names
 689  
 690          Specifically, when completing on ``object.<tab>``.
 691  
 692          When 2 [default]: all names that start with '_' will be excluded.
 693  
 694          When 1: all 'magic' names (``__foo__``) will be excluded.
 695  
 696          When 0: nothing will be excluded.
 697          a3
 698          DEPRECATED as of version 5.0.
 699  
 700          Instruct the completer to use __all__ for the completion
 701  
 702          Specifically, when completing on ``object.<tab>``.
 703  
 704          When True: only those names in obj.__all__ will be included.
 705  
 706          When False [default]: the __all__ attribute is ignored
 707          zEIf True, emit profiling data for completion subsystem using cProfile.z.completion_profileszBTemplate for path at which to output profile data for completions.r:cCst�dt�dS)Nz�`IPython.core.IPCompleter.limit_to__all__` configuration value has been deprecated since IPython 5.0, will be made to have no effects and then removed in future version of IPython.)rCr��UserWarningr�r1r1r4�_limit_to_all_changed�s�z!IPCompleter._limit_to_all_changedcs�t|_t�|_t�jd|||d�|��g|_||_t�	d�|_
 708  tj|_tj
�dd�}|dv|_tjdkr:|j|_n|j|_t�	d�|_t�	d�|_|j|jg|_d	|_d	|_|j|jtt|j g|_!|j"sr|j!D]	}|j#�$|j%�qh|j&szd
 709  |_'d	Sd	S)a�IPCompleter() -> completer
 710  
 711          Return a completer object.
 712  
 713          Parameters
 714          ----------
 715          shell
 716              a pointer to the ipython shell itself.  This is needed
 717              because this completer knows about magic functions, and those can
 718              only be accessed via the ipython instance.
 719          namespace : dict, optional
 720              an optional dict where completions are performed.
 721          global_namespace : dict, optional
 722              secondary optional dict for completions, to
 723              handle cases (such as IPython embedded inside functions) where
 724              both Python scopes are visible.
 725          config : Config
 726              traitlet's config object
 727          **kwargs
 728              passed to super class unmodified.
 729          )rrrz([^\\] )�TERM�xterm)�dumb�emacsr8z^[\w|\s.]+\(([^)]*)\).*z[\s|\[]*(\w+)(?:\s*=\s*.*)NTr1)(r�magic_escaper�r�rr�r�shellrrZ
space_name_re�globre�environ�getZ
dumb_terminalrYrZ�_clean_glob_win32�
 730  clean_glob�_clean_glob�docstring_sig_re�docstring_kwd_re�magic_config_matcher�magic_color_matcher�magic_arg_matchers�custom_completers�_unicode_names�latex_name_matcher�unicode_name_matcherr�r��fwd_unicode_matcher�_backslash_combining_matchersrG�disable_matchersr)r��merge_completions�suppress_competing_matchers)r�r�rrrr�termr�rr1r4r��sJ��
 731  
 732  
 733  ��
 734  
 735  �zIPCompleter.__init__r_�
List[Matcher]cCs�|jr|jgS|jr$g|j�|j�|j�|j�|j�|j�|j�|j	�Sg|j�|j�|j�|j�|j�|j�|j
 736  �|j	�|j�S)z*All active matcher routines for completion)�dict_keys_only�dict_key_matcherrDrr�r��custom_completer_matcher�
magic_matcher�
_jedi_matcher�file_matcher�python_matches�python_func_kw_matcherr�r1r1r4�matchersOsN���������������	�
 737  �zIPCompleter.matchersr�r^�	List[str]csb|�d�d�t����fdd���|t|��D�Wd�S1s%wY��|�dS)zQ
 738          Wrapper around the completion methods for the benefit of emacs.
 739          rrcs,g|]}�r�jrd��|jg�n|j�qS)r)rDr[r�rR�rLr�r1r4r$ts$�z/IPCompleter.all_completions.<locals>.<listcomp>Nrb)�
 740  rpartitionrGr�rdr{r�r1r�r4�all_completionsns� �zIPCompleter.all_completionscCs|�d|�S)N�%s*�r�r�r1r1r4r�yr�zIPCompleter._clean_globcCsdd�|�d|�D�S)NcSsg|]}|�dd��qS)rQ�/rmr�r1r1r4r$}s�z1IPCompleter._clean_glob_win32.<locals>.<listcomp>r�r�r�r1r1r4r�|s�zIPCompleter._clean_glob_win32r�r�r�cC�|�|j�}t|dd�S)z<Same as :any:`file_matches`, but adopted to new Matcher API.r]r�)�file_matchesr�r�r�r�rr1r1r4r��szIPCompleter.file_matchercsz|�d�r|dd�}d�nd�|j}t|��d|vsd|vr"|}n*zt|�d}Wn!tyA�r;|���d}ngYSYntyKd}Ynw�s\|t|�kr\d}||�}nd	}tj	�
 741  |�}|dkrt�fd
 742  d�|�d�D�Stj
d
kr|�|�}n	|�|�dd��}|r�t|�����fdd�|D�}n�r�tj
d
kr�|n�fdd�|D�}n	�fdd�|D�}dd�|D�S)a�Match filenames, expanding ~USER type strings.
 743  
 744          Most of the seemingly convoluted logic in this completer is an
 745          attempt to handle filenames with spaces in them.  And yet it's not
 746          quite perfect, because Python's readline doesn't expose all of the
 747          GNU readline details needed for this to be done correctly.
 748  
 749          For a filename with a space in it, the printed completions will be
 750          only the parts after what's already been typed (instead of the
 751          full completions, as is normally done).  I don't think with the
 752          current (as of Python 2.3) Python readline it's possible to do
 753          better.
 754  
 755          .. deprecated:: 8.6
 756              You can use :meth:`file_matcher` instead.
 757          �!rbNrOr�r�rsTFc�g|]}�t|��qSr1�r\r���text_prefixr1r4r$�r�z,IPCompleter.file_matches.<locals>.<listcomp>�*r8rQcs$g|]}��t|�d���qSr�r�r�)�
 758  len_lsplit�text0r�r1r4r$�s
 759  ��csg|]}t|���qSr1r�r�)�open_quotesr1r4r$�scr�r1r�r�r�r1r4r$�s
 760  ��cSs$g|]}tj�|�r|dn|�qS)r�)rer]�isdir�rS�xr1r1r4r$�s$)rcr�rNr#r�r�r r\rer]rfr�rYrZr�rnrd)r�r�r�ZlsplitZhas_protectables�m0rr1)r�r�r�r�r4r��sR
 761  ��
 762  ��
 763  �zIPCompleter.file_matchescCsL|j}|�|�}t|dd�}t|�dko|ddk}|o!t|d�|d<|S)z
Match magics.�magicr�rrtr�r�)r��
magic_matchesrrdrl)r�r�r�rr�Zis_magic_prefixr1r1r4r��s
 764  zIPCompleter.magic_matchercs�|jj��}|d}|d}|j����|���}|����|����|s.��fdd��n�fdd����fdd�|D�}|���sO|��fdd�|D�7}|S)	zjMatch magics.
 765  
 766          .. deprecated:: 8.6
 767              You can use :meth:`magic_matcher` instead.
 768          r�cellcs|���o|�vS)z�
 769                  Filter magics, in particular remove magics that match
 770                  a name present in global namespace.
 771                  �rc�r�)�	bare_textrr1r4rs
 772  �z*IPCompleter.magic_matches.<locals>.matchescs
 773  |���Sr�r�r�)r�r1r4r
s
 774  c�g|]
 775  }�|�r�|�qSr1r1�rSr?)r�pre2r1r4r$�z-IPCompleter.magic_matches.<locals>.<listcomp>cr�r1r1r�)r�prer1r4r$r�)r��magics_manager�lsmagicr�rc�lstripr)r�r�ZlsmZline_magics�cell_magicsZexplicit_magic�compr1)r�rrr�r�r4r��s
 776  
 777  
 778  
 779  zIPCompleter.magic_matchescCr�)z3Match class names and attributes for %config magic.�paramr�)�magic_config_matchesr�rr�r1r1r4r��z IPCompleter.magic_config_matchercs|�����t��dkr��ddks�ddkr�ttdd�|jjD��dd�d�}d	d�|D�}t��d
 780  kr8|S�d
 781  �d�}|d��fdd�|D�}�d
 782  �d�dkrW|St|�d
 783  kr�|d�kr�||���j	}|�
 784  �}t�t�
d
tj�d|�}�fdd�|����D�SgS)z�Match class names and attributes for %config magic.
 785  
 786          .. deprecated:: 8.6
 787              You can use :meth:`magic_config_matcher` instead.
 788          rrz%configcSsg|]}|jjdd�r|�qS)Tr)r�class_traitsrRr1r1r4r$'s
 789  �z4IPCompleter.magic_config_matches.<locals>.<listcomp>cSs|jjSr��rr;�r�r1r1r4�<lambda>)sz2IPCompleter.magic_config_matches.<locals>.<lambda>rXcSsg|]}|jj�qSr1r�rRr1r1r4r$*r%rbrc�g|]	}|���r|�qSr1r�rR)�	classnamer1r4r$3�
 790  �z^--rOcs(g|]}|��d�r|�d�d�qS)rbrrr)rcr�)rSr5)�textsr1r4r$?s�)�stripr�rd�sortedrXr��
configurables�findrer�class_get_helprr#r�	MULTILINE�
 791  splitlines)r�r��classes�
 792  classnamesZclassname_textsZclassname_matches�clsr
r1)rrr4r�s,$�
 793  
 794  �z IPCompleter.magic_config_matchescCr�)z&Match color schemes for %colors magic.r�r�)�magic_color_matchesr�rr�r1r1r4r�Dr�zIPCompleter.magic_color_matchercsb|��}|�d�r|�d�t|�dkr/|ddks |ddkr/|d��fdd	�t��D�SgS)
 795  z�Match color schemes for %colors magic.
 796  
 797          .. deprecated:: 8.6
 798              You can use :meth:`magic_color_matcher` instead.
 799          r9rOrIr�colorsz%colorsrbcrr1r�)rS�color�rLr1r4r$Yrz3IPCompleter.magic_color_matches.<locals>.<listcomp>)r�rur)rdrr-)r�r�rr1rr4rKs
 800  
 801  $zIPCompleter.magic_color_matcheszIPCompleter.jedi_matcher)r�r�cCs |j|j|j|jd�}|dd�S)N)�
cursor_columnr�r�Fr�)�
_jedi_matchesr�r�r�r�r1r1r4r�]s��zIPCompleter._jedi_matcherrr�r�r�c

 802  Cs�|jg}|jdur|�|j�dd�}t|||�}|rK||d}|dkrK|jdkr/dd�}n|jdkr9dd�}n|jd	krCd
 803  d�}ntd�|j���t�|d|�|�}d}	z.d
}
 804  zt	dd�|�
 805  �jjD��}Wn	t
yrYnwt|j�d	ko�|jd	dv}
 806  |
 807  }	Wnty�}z|jr�td|d�WYd}~nd}~ww|	s�gSz
t||j||dd��WSty�}z|jr�td|�gWYd}~SgWYd}~Sd}~ww)a�
 808          Return a list of :any:`jedi.api.Completion`s object from a ``text`` and
 809          cursor position.
 810  
 811          Parameters
 812          ----------
 813          cursor_column : int
 814              column position of the cursor in ``text``, 0-indexed.
 815          cursor_line : int
 816              line position of the cursor in ``text``, 0-indexed
 817          text : str
 818              text to complete
 819  
 820          Notes
 821          -----
 822          If ``IPCompleter.debug`` is ``True`` may return a :any:`_FakeJediCompletion`
 823          object containing a string with the Jedi debug information attached.
 824  
 825          .. deprecated:: 8.6
 826              You can use :meth:`_jedi_matcher` instead.
 827          NcSr0r�r1r�r1r1r4r�r�z+IPCompleter._jedi_matches.<locals>.<lambda>rbrrIcSs|j�d�S)Nrq)rzrc�rTr1r1r4r�scSs|j�d�o|j�d�S)Nrp)rzrcrurr1r1r4r�rJrcSr0r�r1r�r1r1r4r�r�z'Don't understand self.omit__names == {}TFcss�|]
 828  }t|d�r|VqdS)�valueN)r�rRr1r1r4rW�s�z,IPCompleter._jedi_matches.<locals>.<genexpr>>rJrHz5Error detecting if completing a non-finished string :�|)rkrzJOops Jedi has crashed, please report a bug with the following:
 829  """
 830  %s
 831  s""")rrr)ro�omit__namesr�rlr��Interpreterr��_get_module�	tree_node�childrenr�rdrr>rFr��filterr{rx)
r�rr�r��
 832  namespacesZcompletion_filterrpr��interpreterZtry_jediZcompleting_string�first_child�er1r1r4rjsR
 833  
 834  
 835  
 836  
 837  
 838  
 839  �
 840  ����zIPCompleter._jedi_matches�
Iterable[str]cCs�d|vr:z)|�|�}|�d�r(|jr+|jdkrdd�}ndd�}t||�}W|SW|SW|Sty9g}Y|Sw|�|�}|S)z'Match attributes or global python namesrrbcSst�d|�duS)Nz.*\.__.*?__)rr&��txtr1r1r4r�sz,IPCompleter.python_matches.<locals>.<lambda>cSst�d||�d�d��duS)Nz\._.*?r)rr&�rindexr#r1r1r4r�s)rrurr�	NameErrorr)r�r�rZno__namer1r1r4r��s&
 841  
 842  
 843  ����
 844  r�cCsh|durgS|����d}|j�|�}|durgS|��d�d�}g}|D]
 845  }||j�|�7}q'|S)aParse the first line of docstring for call signature.
 846  
 847          Docstring should be of the form 'min(iterable[, key=func])
 848  '.
 849          It can also parse cython docstring of the form
 850          'Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)'.
 851          Nr�,)r�rr�r`�groupsr�r��findall)r��docr�sig�retrMr1r1r4�!_default_arguments_from_docstring�sz-IPCompleter._default_arguments_from_docstringcs�|}g}t�|�r
 852  n/t�|�s9t�|�s9t�|�r1||�t|dd��7}t|dd�p/t|dd�}nt|d�r9|j}||�t|dd��7}tj	j
 853  tj	jf�zt�|�}|�
�fdd�|j��D��Wn	tykYnwtt|��S)	z_Return the list of default arguments of obj if it is callable,
 854          or empty list otherwise.r>rOr�N�__new__r�c3s"�|]\}}|j�vr|VqdSr�)�kind)rSrS�v�Z_keepsr1r4rWs�
 855  
 856  ��z1IPCompleter._default_arguments.<locals>.<genexpr>)�inspect�	isbuiltin�
 857  isfunction�ismethod�isclassr-r�r�r��	Parameter�KEYWORD_ONLY�POSITIONAL_OR_KEYWORDr~�extend�
 858  parameters�itemsr�r�rX)r�r2Zcall_objr,r+r1r1r4�_default_arguments�s6
 859  
 860  
 861  �
 862  �
 863  
 864  ��
 865  "�zIPCompleter._default_argumentscCr�)z:Match named parameters (kwargs) of the last open function.r�r�)�python_func_kw_matchesr�rr�r1r1r4r�	sz"IPCompleter.python_func_kw_matchercCs�d|vrgSz|j}Wnty!t�dtjtjB�}|_Ynw|�|j�}t|�}d}|D]}|dkr;|d8}q0|dkrI|d7}|dkrInq0gSg}t�d�j	}	z|�
 866  t|��||d	�si|��Wnt|�dksqWnWn	t
y{YnwqUt�}	d	}
 867  t||dd
 868  ��D]$\}}|dkr�|
 869  d7}
 870  n|dkr�|
 871  d8}
 872  |
 873  dkr�q�|dkr�q�|	�|�q�g}z+d�|d
 874  d
 875  d	��}
|�t|
|j��}t|�|	D]}|�|�r�|�
 876  d|�q�W|SY|S)
z�Match named parameters (kwargs) of the last open function.
 877  
 878          .. deprecated:: 8.6
 879              You can use :meth:`python_func_kw_matcher` instead.
 880          rz�
 881                  '.*?(?<!\\)' |    # single quoted strings or
 882                  ".*?(?<!\\)" |    # double quoted strings or
 883                  \w+          |    # identifier
 884                  \S                # other characters
 885                  r�)rbr�z\w+$TrsNrrz%s=)Z_IPCompleter__funcParamsRegexrbrr�VERBOSE�DOTALLr)r��reversedr&r)r��popr�rXrQr�r[r=r9rrc)r�r��regexp�tokensZ
 886  iterTokensZopenParr��ids�isIdZ
usedNamedArgsZ	par_level�
 887  next_tokenZ
 888  argMatchesZcallableObjZ	namedArgsZnamedArgr1r1r4r>sx
 889  ��
 890  
 891  ����
 892  �
 893  ���z"IPCompleter.python_func_kw_matchesr2r�	List[Any]cCs|t|d�}|dur|�St|t�st|dd�r*zt|���WSty)gYSwt|dd�s6t|dd�r<|jjp;gSgS)NZ_ipython_key_completions_�pandas�	DataFrame�numpy�ndarray�void)	r rIr�rxr�r-r>�dtype�names)r2�methodr1r1r4�	_get_keys_s 
 894  
 895  
 896  ��
 897  �zIPCompleter._get_keyscCs|�|j�}t|ddd�S)z7Match string keys in a dictionary, after e.g. ``foo[``.zdict keyT�r|r})�dict_key_matchesr�rr�r1r1r4r�ss�zIPCompleter.dict_key_matchercs�|jdur	|j}nd}t�|d�t�|d�d�}|_||j�|j�}|dur,gS|��\}}}zt||j�}Wnt	yZzt||j
 898  �}Wn
t	yWgYYSwYnw|�|�}	|	sd|	S|dkrlt|�nd}
 899  t|	||j
j|
 900  d�\}}}
|
s|
St|j�t|�}|r�|�d�}||}n|��}}||kr�d�n|||��|�d	�}d�|jt|j�d�}||kr�|r�|�|�r�|t|�d�}n�|7�||kr�|�d
 901  �s݈d
 902  7���fdd�|
D�S)
z�Match string keys in a dictionary, after e.g. ``foo[``.
 903  
 904          .. deprecated:: 8.6
 905              You can use :meth:`dict_key_matcher` instead.
 906          Na�(?x)
 907              (  # match dict-referring expression wrt greedy setting
 908                  %s
 909              )
 910              \[   # open bracket
 911              \s*  # and optional whitespace
 912              # Capture any number of str-like objects (e.g. "a", "b", 'c')
 913              ((?:[uUbB]?  # string prefix (r not handled)
 914                  (?:
 915                      '(?:[^']|(?<!\\)\\')*'
 916                  |
 917                      "(?:[^"]|(?<!\\)\\")*"
 918                  )
 919                  \s*,\s*
 920              )*)
 921              ([uUbB]?  # string prefix (r not handled)
 922                  (?:   # unclosed string
 923                      '(?:[^']|(?<!\\)\\')*
 924                  |
 925                      "(?:[^"]|(?<!\\)\\")*
 926                  )
 927              )?
 928              $
 929              z�
 930                                    # identifiers separated by .
 931                                    (?!\d)\w+
 932                                    (?:\.(?!\d)\w+)*
 933                                    zF
 934                                   .+
 935                                   )FTrO)rMr0rbr�csg|]}�|��qSr1r1r\��leading�sufr1r4r$�r�z0IPCompleter.dict_key_matches.<locals>.<listcomp>)r�rrr7r`r�r(r9rr>rrRrjr�r�rdr�r�r8rc)r�r�ZregexpsZdict_key_re_fmtr&rZprefix0rLr2r-rMZ
closing_quoteZtoken_offsetrZ
 936  text_start�	key_startZcompletion_startZbracket_idx�continuationr1rUr4rT{s\
 937  ����
 938  
 939  
 940  
 941  
 942  
 943  zIPCompleter.dict_key_matchescC� |�|j�\}}t|d|dd�S)zDSame as :any:`unicode_name_matches`, but adopted to new Matcher API.rzTr{)�unicode_name_matchesr�r�r�r�r|rr1r1r4r��s�z IPCompleter.unicode_name_matcher�Tuple[str, List[str]]cCst|�d�}|dkr6||dd�}zt�|�}d|��r%d||gfWSWdgfSty5YdgfSwdgfS)uMatch Latex-like syntax for unicode characters base
 944          on the name of the character.
 945  
 946          This does  ``\GREEK SMALL LETTER ETA`` -> ``η``
 947  
 948          Works only on valid python 3 identifier, or on combining characters that
 949          will combine to form a valid identifier.
 950          rQrsrbN�arO)�rfindr��lookup�isidentifierr�)r��slashposrMr�r1r1r4r[�s
 951  
 952  
 953  ���z IPCompleter.unicode_name_matchescCrZ)u{Match Latex syntax for unicode characters.
 954  
 955          This does both ``\alp`` -> ``\alpha`` and ``\alpha`` -> ``α``
 956          r�Tr{)�
latex_matchesr�rr\r1r1r4r�	��zIPCompleter.latex_name_matcherr�csV|�d�}|dkr)||d���tvr�t�gfS�fdd�tD�}|r)�|fSdS)u�Match Latex syntax for unicode characters.
 957  
 958          This does both ``\alp`` -> ``\alpha`` and ``\alpha`` -> ``α``
 959  
 960          .. deprecated:: 8.6
 961              You can use :meth:`latex_name_matcher` instead.
 962          rQrsNcrr1r�r\rLr1r4r$!	rJz-IPCompleter.latex_matches.<locals>.<listcomp>r�)r_r)r�r�rbrr1rLr4rc	s
 963  zIPCompleter.latex_matchescCs:|�|j�pg}t|tdd�}d|d<t|j�h|d<|S)zpDispatch custom completer.
 964  
 965          If a match is found, suppresses all other matchers except for Jedi.
 966          TrSr�r�)�dispatch_custom_completerr�r�
_UNKNOWN_TYPEr�r�)r�r�rr�r1r1r4r�&	s�z$IPCompleter.custom_completer_matcherc		s|jsdS|j}|��sdSt�}||_�|_|�dd�d}||_|j|_|�	|j
 967  �s6|j�|j
 968  |�}ng}t�
|j�|�||j�|j��D]>}z(||�}|rq�fdd�|D�}|ra|WS�����fdd�|D�WSWqHty{YqHty�	YdSwdS)zg
 969          .. deprecated:: 8.6
 970              You can use :meth:`custom_completer_matcher` instead.
 971          Nrbrcrr1r��rS�r�r�r1r4r$W	rJz9IPCompleter.dispatch_custom_completer.<locals>.<listcomp>csg|]}|�����r|�qSr1)�lowerrcrg)�text_lowr1r4r$\	s)r�r8rrr�symbolr��commandr�rcr��	s_matchesr�r��flat_matchesrjr�KeyboardInterrupt)	r�r�r�event�cmdZ	try_magicrT�resZwithcaser1)r�rkr4re4	sJ��
 972  ��z%IPCompleter.dispatch_custom_completerrp�Iterator[Completion]ccs,�tjdtdd�t�}zdz1|jrddl}|��}|��nd}|j|||j	dd�D]}|r4||vr4q+|V|�
 973  |�q+Wn
 974  tyH	YnwW|duro|��t
|j�tj�|jtt����}td|�|�|�dSdS|dur�|��t
|j�tj�|jtt����}td|�|�|�ww)	a�
 975          Returns an iterator over the possible completions
 976  
 977          .. warning::
 978  
 979              Unstable
 980  
 981              This function is unstable, API may change without warning.
 982              It will also raise unless use in proper context manager.
 983  
 984          Parameters
 985          ----------
 986          text : str
 987              Full text of the current input, multi line string.
 988          offset : int
 989              Integer representing the position of the cursor in ``text``. Offset
 990              is 0-based indexed.
 991  
 992          Yields
 993          ------
 994          Completion
 995  
 996          Notes
 997          -----
 998          The cursor on a text can either be seen as being "in between"
 999          characters or "On" a character depending on the interface visible to
1000          the user. For consistency the cursor being on "in between" characters X
1001          and Y is equivalent to the cursor being "on" character Y, that is to say
1002          the character the cursor is on is considered as being after the cursor.
1003  
1004          Combining characters may span more that one position in the
1005          text.
1006  
1007          .. note::
1008  
1009              If ``IPCompleter.debug`` is :any:`True` will yield a ``--jedi/ipython--``
1010              fake Completion token to distinguish completion returned by Jedi
1011              and usual IPython completion.
1012  
1013          .. note::
1014  
1015              Completions are not completely deduplicated yet. If identical
1016              completions are coming from different sources this function does not
1017              ensure that each completion object will only be present once.
1018          zy_complete is a provisional API (as of IPython 6.0). It may change without warnings. Use in corresponding context manager.rIr�rNi�)�_timeoutzWriting profiler output to)rCr�r:rX�profile_completions�cProfile�Profile�enable�_completionsrEr�rp�disabler"�profiler_output_dirrer]r[r^�uuid�uuid4r��
1019  dump_stats)r�r�rpr�rw�profilerrTZoutput_pathr1r1r4r�h	sF�.�
1020  ���
1021  
1022  �
1023  
1024  �zIPCompleter.completionsr�c
1025  #s<�t��|}|d|�}t||�\}}t|j��|j|||d�}�fdd�|��D�}	�|vr9t|�t�dnd}
1026  t	|
1027  �}|r�|D]F}z|j
1028  }
Wnty]|jrYt
d|�d}
Ynwt|j�t|j�}|
dkrqt|�}nd	}t||||j|
|d
1029  d�Vt��|kr�nqC|D]}t|j�t|j�}t||||jtd
1030  d	d�Vq�|
1031  r�|	r�|jr�|�tt	|	����d
�}t||dddd	d�Vg}g}|	��D]:\}}|d
}|�|�}|�dd�}|r�|n|}|�|�s�J�|dD]}t|||j|d	|j
1032  p�td�}|�|�q�q�t|�||�|���dt�EdHdS)ax
1033          Core completion module.Same signature as :any:`completions`, with the
1034          extra `timeout` parameter (in seconds).
1035  
1036          Computing jedi's completion ``.type`` can be quite expensive (it is a
1037          lazy property) and can require some warm-up, more warm up than just
1038          computing the ``name`` of a completion. The warm-up can be :
1039  
1040              - Long warm-up the first time a module is encountered after
1041              install/update: actually build parse/inference tree.
1042  
1043              - first time the module is encountered in a session: load tree from
1044              disk.
1045  
1046          We don't want to block completions for tens of seconds so we give the
1047          completer a "budget" of ``_timeout`` seconds per invocation to compute
1048          completions types, the completions that have not yet been computed will
1049          be marked as "unknown" an will have a chance to be computed next round
1050          are things get cached.
1051  
1052          Keep in mind that Jedi is not the only thing treating the completion so
1053          keep the timeout short-ish as if we take more than 0.3 second we still
1054          have lots of processing to do.
1055  
1056          N)r�r�rcsi|]\}}|�kr||�qSr1r1)rSr�r���jedi_matcher_idr1r4r(�	s
1057  �z,IPCompleter._completions.<locals>.<dictcomp>r�r1zError in Jedi getting type of �functionrOr�r�)r�r�r�r|rr~r�z--jedi/ipython--rF�none)r�r�r�rr|r~r�F)r�r�r�rr~r|)�time�	monotonicrtr�r��	_completer<r+r��iterr|r>rFr�rdr}r{r�r�rfr_r��valuesr�rur�r)r��_deduplicate�_sort�
MATCHES_LIMIT)r�r�rpru�deadlinerrr�r�resultsZnon_jedi_resultsZjedi_matchesZiter_jmZjmr3�deltar~Zsome_start_offsetr��sortable�originr��matched_text�start_offset�
1058  is_ordered�	containerZsimple_completionr�r1r�r4rz�	s��
1059  �
1060  ���
1061  
1062  �
1063  ��
1064  ���	
1065  ���zIPCompleter._completionscCs:t�dt�|j|||dd�}t|j�}|j||hdd�S)a�Find completions for the given text and line context.
1066  
1067          Note that both the text and the line_buffer are optional, but at least
1068          one of them must be given.
1069  
1070          Parameters
1071          ----------
1072          text : string, optional
1073              Text to perform the completion on.  If not given, the line buffer
1074              is split using the instance's CompletionSplitter object.
1075          line_buffer : string, optional
1076              If not given, the completer attempts to obtain the current line
1077              buffer via readline.  This keyword allows clients which are
1078              requesting for text completions in non-readline contexts to inform
1079              the completer of the entire text.
1080          cursor_pos : int, optional
1081              Index of the cursor in the full line buffer.  Should be provided by
1082              remote frontends where kernel has no access to frontend state.
1083  
1084          Returns
1085          -------
1086          Tuple of two items:
1087          text : str
1088              Text that was actually used in the completion.
1089          matches : list
1090              A list of completion matches.
1091  
1092          Notes
1093          -----
1094              This API is likely to be deprecated and replaced by
1095              :any:`IPCompleter.completions` in the future.
1096  
1097          zn`Completer.complete` is pending deprecation since IPython 6.0 and will be replaced by `Completer.completions`.r)r8rr�r�T��
skip_matchers�abort_if_offset_changes)rCr��PendingDeprecationWarningr�r�r��_arrange_and_extract)r�r�r8rr�r�r1r1r4r{4
1098  s"��
1099  �zIPCompleter.completer��Dict[str, MatcherResult]r��Set[str]r�rlc	Cs�g}g}d}|��D]3\}}||vrq
1100  |dsq
1101  |s|d}|r(|d|kr(n|�dd�r6|�|d�q
1102  |�|d�q
1103  |sBd}|dd�|�||�|��D�fS)Nr�r�r�FrOcSsg|]}|j�qSr1rir�r1r1r4r$�
1104  s�z4IPCompleter._arrange_and_extract.<locals>.<listcomp>)r<r�r:r�r�)	r�r�r�r�r�r�Zmost_recent_fragmentr�r�r1r1r4r�l
1105  s,��z IPCompleter._arrange_and_extract)r8r�r��_CompleteResultc	Cst|dur|durt|�nt|�}|jrtj|_|s"|r"|�d�|}|s/|r-|j�||�nd}|dur5|}||_|jd|�|_	|sD|}t
1106  ||||td�}i}t|j
�}t�}	dd�t|jtdd�D�}
1107  |
1108  ��D]�\}}t|�}
t|�}||jvrzqh||vr�t�d	|�d
1109  ��||	vr�qhz"|
dkr�t||�td�}n|
d
kr�t|t�|�}ntd|
����Wntjt���Yqh|�d|j �|d<|	�s%|�dd�}t!|j"t#�r�|j"�|d�n|j"}|dup�|o�|duo�t$|�}|�r%|�dt��}zt|�}Wnt%�y	t|
1110  �}Ynw||}	i}|��D]\}}||	v�r!|||<�q|}|||<qh|j&||hdd�\}}||_'|S)a�
1111          Like complete but can also returns raw jedi completions as well as the
1112          origin of the completion text. This could (and should) be made much
1113          cleaner but that will be simpler once we drop the old (and stateful)
1114          :any:`complete` API.
1115  
1116          With current provisional API, cursor_pos act both (depending on the
1117          caller) as the offset in the ``text`` or ``line_buffer``, or as the
1118          ``column`` when passing multiline strings this could/should be renamed
1119          but would add extra noise.
1120  
1121          Parameters
1122          ----------
1123          cursor_line
1124              Index of the line the cursor is on. 0 indexed.
1125          cursor_pos
1126              Position of the cursor in the current line/line_buffer/text. 0
1127              indexed.
1128          line_buffer : optional, str
1129              The current line the cursor is in, this is mostly due to legacy
1130              reason that readline could only give a us the single current line.
1131              Prefer `full_text`.
1132          text : str
1133              The current "token" the cursor is in, mostly also for historical
1134              reasons. as the completer would trigger only after the current line
1135              was parsed.
1136          full_text : str
1137              Full text of the current cell.
1138  
1139          Returns
1140          -------
1141          An ordered dictionary where keys are identifiers of completion
1142          matchers and values are ``MatcherResult``s.
1143          Nr�rO)r�r�r�r�r�cSsi|]}t|�|�qSr1)r�)rSr�r1r1r4r(�
1144  s��z)IPCompleter._complete.<locals>.<dictcomp>T)rR�reversezDuplicate matcher ID: rrbr�rIzUnsupported API version r�r�Fr�r�)(rdrrrrr�r�rr8r�r�r�r�r�rXrr�r�r<r�r�rCr�rrfr+r�r�rY�
1145  excepthook�exc_infor�r�rIr�r�r�rcr�r)r�r�rr8r�r�r�r�r�Zsuppressed_matchersr�Z
1146  matcher_idr�r�r�Zsuppression_recommendedZsuppression_configZshould_suppressZsuppression_exceptionsZto_suppress�new_resultsZprevious_matcher_idZprevious_resultrqrr1r1r4r��
1147  s�'��	
1148  ��
1149  ��
1150  ��
1151  ���
1152  �
1153  
1154  �	zIPCompleter._completerr��Iterable[SimpleCompletion]cCs:i}|D]}|j}||vs||jtkr|||<q|��Sr�)r�r|rfr�)rZfiltered_matchesr&r�r1r1r4r�-s�zIPCompleter._deduplicatecCst|dd�d�S)NcSs
1155  t|j�Sr�)rwr�r�r1r1r4r>s
1156  z#IPCompleter._sort.<locals>.<lambda>rX)r)rr1r1r4r�<r�zIPCompleter._sortcCrZ)zASame as :any:`fwd_unicode_match`, but adopted to new Matcher API.rzTr{)�fwd_unicode_matchr�rr\r1r1r4r�@rdzIPCompleter.fwd_unicode_matchercs�|�d�}|dkrL||dd�}|����fdd�|jD�}|r%||fS�fdd�|jD�}|r5||fS��d���fd	d�|jD�}|rJ||fSd
1157  Sd
1158  S)a�
1159          Forward match a string starting with a backslash with a list of
1160          potential Unicode completions.
1161  
1162          Will compute list of Unicode character names on first call and cache it.
1163  
1164          .. deprecated:: 8.6
1165              You can use :meth:`fwd_unicode_matcher` instead.
1166  
1167          Returns
1168          -------
1169          At tuple with:
1170              - matched text (empty if no matches)
1171              - list of potential completions, empty tuple  otherwise)
1172          rQrsrbNcrr1r�r���supr1r4r$urJz1IPCompleter.fwd_unicode_match.<locals>.<listcomp>csg|]}�|vr|�qSr1r1r�r�r1r4r$xr�r9cs&g|]�t�fdd��D��r��qS)c3s�|]}|�vVqdSr�r1)rS�ur�r1r4rW}r�z;IPCompleter.fwd_unicode_match.<locals>.<listcomp>.<genexpr>)�all)rS)�splitsupr�r4r$|s
1173  ��r�)r_�upper�
unicode_namesr�)r�r�rbrM�
1174  candidatesr1)r�r�r4r�Ks$
1175   
1176  
1177  �zIPCompleter.fwd_unicode_matchc	CsX|jdur)g}tdd�D]}z|�t�t|���Wqty#Yqwtt�|_|jS)z}List of names of unicode code points that can be completed.
1178  
1179          The list is lazily initialized on first access.
1180          Nri)	r��ranger)r�rz�chrr��_unicode_name_compute�_UNICODE_RANGES)r�rPrTr1r1r4r��s
1181  �
1182  zIPCompleter.unicode_names)NNNN)r_r�)r�r^r_r�)r�r^)r�r�r_r�)r�r�r_r�)rr�r�r�r�r^r_r�)r�r^r_r")r2rr_rI�r�r�)r�r^r_r]�r�r^r_r�)r�r^rpr�r_rt)r�r^rpr�r_rt)NNN)r_r�)r�r�r�r�r�rl)r_r�)rr�r_r�)rr�)r_r�)Cr;r<r=r>r�r�r)r�r$r��
1183  UnionTrait�	DictTraitrBr�r��	ListTraitr'r�r%rr:rvr|r�r�r
1184  r�r�r�r��context_matcherr�r�r�r�r�r�r�rr�rr�r-r=r�r>�staticmethodrRr�rTr�r[r�rcr�rer�rzr{r�r�r�r�r�r�r�rHr1r1rr4r7�s�
1185  
1186  �	���
1187  ����
�������
1188  �Z
1189  
1190  
1191  
1192  V
1193  	.
1194  '
1195  
1196  
1197  M"P
1198  k
1199  
1200  
1201  
1202  4
1203  N~
1204  8"� 
1205  
1206  =�ranges�List[Tuple[int, int]]r�c
1207  CsPg}|D]!\}}t||�D]}z|�t�t|���Wq
ty$Yq
wq|Sr�)r�r)r�rzr�r�)r�rPr��stoprTr1r1r4r��s��r�)rB)r]r^r_r`)r]r^rgrlrhr^r_r^)r�r�r_rl)r�r�r�r^r�r�)r�r�)r�r^r�r�r_r�)r�r^r�r�r�rlr_r�r�)
1208  r-rKrLr^r�r^rMrNr_rO)r�r^rr�rkr�r_r�)r�r^rpr�r_rqr�r�r�)NF)
1209  rr�r|r^r|r^r}rlr_r�)r�r�r_r�)�r>�
1210  __future__r�builtinsr,r�r2r�r*rerr�rYr�r�r}rC�
1211  contextlibr�dataclassesr�	functoolsrr�	importlibr�typesr�typingr	r
1212  rrr
rrrrrrrrr�IPython.core.errorr�IPython.core.inputtransformer2r�IPython.core.latex_symbolsrr�IPython.core.oinspectr�IPython.testing.skipdoctestr�
IPython.utilsr�IPython.utils.decoratorsr�IPython.utils.dir2rr �IPython.utils.docsr!�IPython.utils.pathr"�IPython.utils.processr#�	traitletsr$r%r&r�r'r�r�r(r)�traitlets.config.configurabler*r�__skip_doctest__r��settings�case_insensitive_completion�jedi.api.helpers�jedi.api.classesrC�ImportErrorr+�typing_extensionsr,r-r.r/�objectr�r1rZ�PROTECTABLESr�rf�
FutureWarningr:rErGrNr\rkrorwrx�apir��_JediCompletionLiker�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r	r�r�r6r;rjrortrxr�r~r�r�r�r�r^r�rr7r�r1r1r1r4�<module>s3@,�	
1213  
1214  (	 >
1215  '	
1216  
1217  �
1218  %
1219  
1220  *;4,�
1221  ^
1222  "
1223  *
1224  
1225  
1226  �