Format: application/x-python-code
⬇ Download File (93.0 KB)
   1  o
   2  
   3  ��h	��@sUdZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
   4  Z
   5  ddlZddlZddl
   6  Z
   7  ddlZddlZddlZddlZddlZddlZddl
   8  mZddlmZddlmZddlmZddlmZmZdd	lmZdd
   9  l m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.ddl/m0Z0m1Z1ddl2m3Z3dd
  10  l4m5Z5ddl6m7Z7m8Z8ddl9m:Z:ddl;m<Z<ddl=m>Z>ddl?m@Z@ddlAmBZBmCZCddlDmEZEddlFmGZGddlHmIZIddlJmKZKmLZLmMZMm#ZNmOZOm(ZPm%ZQmRZRddlSmTZTddlUZUdZVzddlWZWdeWjX_YddlZZWddl[ZWdZ\Wne]�ydZ\Ynwe*�s*eE�r?ej^dk�r?ddl m_Z_ddl`maZambZbmcZcmdZdmeZenddl mfZfdd �Z_e$Zbe(ZaegZce&ZdefZeeE�r\dd!l maZad"d#gZhd$d%gZiejjd&k�rmd'Zknd(Zkd)Zld*Zmeg�ZnGd+d,�d,eo�Zpejqd-epd.�e<ed�d0d1���Zrd�d6d7�Zsekfd�d9d:�Ztd�d=d>�Zud�dBdC�ZvdDdE�ZwGdFdG�dG�Zxe%dHexfZyGdIdJ�dJ�ZzGdKdL�dL�Z{GdMdN�dNea�Z|e@ddOgdP�GdQdR�dRe|ea��Z}GdSdT�dTe|�Z~e%eye{fZe-dUeez�Z�eGdVdW�dW��Z�e%e}e~fZ�GdXdY�dYec�Z�GdZd[�d[e�ec�Z�e%e�e�fZ�d\e�d]<Gd^d_�d_ec�Z�e%e�e�fZ�d\e�d`<d�dcdd�Z�d�dfdg�Z�d�dkdl�Z�d�dndo�Z�d�drds�Z�dddtdu�d�d}d~�Z�d�dd��Z�d�d�d��Z�d�d��Z�ee�d�d��Z�e!ezZ�d�d�d��Z�dd��d�d�d��Z�ejjd&k�r|d�Z�nd�Z�d�Z�Gd�d��d�eg�Z�Gd�d$�d$eT�Z�d�d��Z�Gd�d��d�ej��Z�d�d��Z�d�d�d��Z�e�e�e�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�e�fZ�e��d��Z�		d�d�d�dȄZ�Gd�d%�d%e��Z�d�d�d΄Z�dS)�u�Completion for IPython.
  11  
  12  This module started as fork of the rlcompleter module in the Python standard
  13  library.  The original enhancements made to rlcompleter have been sent
  14  upstream and were accepted as of Python 2.3,
  15  
  16  This module now support a wide variety of completion mechanism both available
  17  for normal classic Python code, as well as completer for IPython specific
  18  Syntax like magics.
  19  
  20  Latex and Unicode completion
  21  ============================
  22  
  23  IPython and compatible frontends not only can complete your code, but can help
  24  you to input a wide range of characters. In particular we allow you to insert
  25  a unicode character using the tab completion mechanism.
  26  
  27  Forward latex/unicode completion
  28  --------------------------------
  29  
  30  Forward completion allows you to easily type a unicode character using its latex
  31  name, or unicode long description. To do so type a backslash follow by the
  32  relevant name and press tab:
  33  
  34  
  35  Using latex completion:
  36  
  37  .. code::
  38  
  39      \alpha<tab>
  40      α
  41  
  42  or using unicode completion:
  43  
  44  
  45  .. code::
  46  
  47      \GREEK SMALL LETTER ALPHA<tab>
  48      α
  49  
  50  
  51  Only valid Python identifiers will complete. Combining characters (like arrow or
  52  dots) are also available, unlike latex they need to be put after the their
  53  counterpart that is to say, ``F\\vec<tab>`` is correct, not ``\\vec<tab>F``.
  54  
  55  Some browsers are known to display combining characters incorrectly.
  56  
  57  Backward latex completion
  58  -------------------------
  59  
  60  It is sometime challenging to know how to type a character, if you are using
  61  IPython, or any compatible frontend you can prepend backslash to the character
  62  and press :kbd:`Tab` to expand it to its latex form.
  63  
  64  .. code::
  65  
  66      \α<tab>
  67      \alpha
  68  
  69  
  70  Both forward and backward completions can be deactivated by setting the
  71  :std:configtrait:`Completer.backslash_combining_completions` option to
  72  ``False``.
  73  
  74  
  75  Experimental
  76  ============
  77  
  78  Starting with IPython 6.0, this module can make use of the Jedi library to
  79  generate completions both using static analysis of the code, and dynamically
  80  inspecting multiple namespaces. Jedi is an autocompletion and static analysis
  81  for Python. The APIs attached to this new mechanism is unstable and will
  82  raise unless use in an :any:`provisionalcompleter` context manager.
  83  
  84  You will find that the following are experimental:
  85  
  86      - :any:`provisionalcompleter`
  87      - :any:`IPCompleter.completions`
  88      - :any:`Completion`
  89      - :any:`rectify_completions`
  90  
  91  .. note::
  92  
  93      better name for :any:`rectify_completions` ?
  94  
  95  We welcome any feedback on these new API, and we also encourage you to try this
  96  module in debug mode (start IPython with ``--Completer.debug=True``) in order
  97  to have extra logging information if :any:`jedi` is crashing, or if current
  98  IPython completer pending deprecations are returning results not yet handled
  99  by :any:`jedi`
 100  
 101  Using Jedi for tab completion allow snippets like the following to work without
 102  having to execute any code:
 103  
 104     >>> myvar = ['hello', 42]
 105     ... myvar[1].bi<tab>
 106  
 107  Tab completion will be able to infer that ``myvar[1]`` is a real number without
 108  executing almost any code unlike the deprecated :any:`IPCompleter.greedy`
 109  option.
 110  
 111  Be sure to update :any:`jedi` to the latest stable version or to try the
 112  current development version to get better completions.
 113  
 114  Matchers
 115  ========
 116  
 117  All completions routines are implemented using unified *Matchers* API.
 118  The matchers API is provisional and subject to change without notice.
 119  
 120  The built-in matchers include:
 121  
 122  - :any:`IPCompleter.dict_key_matcher`:  dictionary key completions,
 123  - :any:`IPCompleter.magic_matcher`: completions for magics,
 124  - :any:`IPCompleter.unicode_name_matcher`,
 125    :any:`IPCompleter.fwd_unicode_matcher`
 126    and :any:`IPCompleter.latex_name_matcher`: see `Forward latex/unicode completion`_,
 127  - :any:`back_unicode_name_matcher` and :any:`back_latex_name_matcher`: see `Backward latex completion`_,
 128  - :any:`IPCompleter.file_matcher`: paths to files and directories,
 129  - :any:`IPCompleter.python_func_kw_matcher` - function keywords,
 130  - :any:`IPCompleter.python_matches` - globals and attributes (v1 API),
 131  - ``IPCompleter.jedi_matcher`` - static analysis with Jedi,
 132  - :any:`IPCompleter.custom_completer_matcher` - pluggable completer with a default
 133    implementation in :any:`InteractiveShell` which uses IPython hooks system
 134    (`complete_command`) with string dispatch (including regular expressions).
 135    Differently to other matchers, ``custom_completer_matcher`` will not suppress
 136    Jedi results to match behaviour in earlier IPython versions.
 137  
 138  Custom matchers can be added by appending to ``IPCompleter.custom_matchers`` list.
 139  
 140  Matcher API
 141  -----------
 142  
 143  Simplifying some details, the ``Matcher`` interface can described as
 144  
 145  .. code-block::
 146  
 147      MatcherAPIv1 = Callable[[str], list[str]]
 148      MatcherAPIv2 = Callable[[CompletionContext], SimpleMatcherResult]
 149  
 150      Matcher = MatcherAPIv1 | MatcherAPIv2
 151  
 152  The ``MatcherAPIv1`` reflects the matcher API as available prior to IPython 8.6.0
 153  and remains supported as a simplest way for generating completions. This is also
 154  currently the only API supported by the IPython hooks system `complete_command`.
 155  
 156  To distinguish between matcher versions ``matcher_api_version`` attribute is used.
 157  More precisely, the API allows to omit ``matcher_api_version`` for v1 Matchers,
 158  and requires a literal ``2`` for v2 Matchers.
 159  
 160  Once the API stabilises future versions may relax the requirement for specifying
 161  ``matcher_api_version`` by switching to :any:`functools.singledispatch`, therefore
 162  please do not rely on the presence of ``matcher_api_version`` for any purposes.
 163  
 164  Suppression of competing matchers
 165  ---------------------------------
 166  
 167  By default results from all matchers are combined, in the order determined by
 168  their priority. Matchers can request to suppress results from subsequent
 169  matchers by setting ``suppress`` to ``True`` in the ``MatcherResult``.
 170  
 171  When multiple matchers simultaneously request suppression, the results from of
 172  the matcher with higher priority will be returned.
 173  
 174  Sometimes it is desirable to suppress most but not all other matchers;
 175  this can be achieved by adding a set of identifiers of matchers which
 176  should not be suppressed to ``MatcherResult`` under ``do_not_suppress`` key.
 177  
 178  The suppression behaviour can is user-configurable via
 179  :std:configtrait:`IPCompleter.suppress_competing_matchers`.
 180  �)�annotationsN)�literal_eval)�defaultdict)�contextmanager)�	dataclass)�cached_property�partial)�SimpleNamespace)�Iterable�Iterator�List�Tuple�Union�Any�Sequence�Dict�Optional�
 181  TYPE_CHECKING�Set�Sized�TypeVar�Literal)�guarded_eval�EvaluationContext)�TryNext)�	ESC_MAGIC)�
 182  latex_symbols�reverse_latex_symbol)�
 183  InspectColors)�skip_doctest)�generics)�sphinx_options)�dir2�get_real_method)�GENERATING_DOCUMENTATION)�ensure_dir_exists)�	arg_split)�Bool�Enum�Intr�Unicoderr�observe)�ConfigurableTF)��)�cast)�	TypedDict�NotRequired�Protocol�	TypeAlias�	TypeGuard)�GenericcCs|S)z=Workaround for `TypeError: MatcherAPIv2() takes no arguments`�)�type_�objr6r6�Lc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/completer.pyr/
 184  �r/)r0)� i�#)ii��	Completer�IPCompleter�win32� z ()[]{}?=\|;:'#*"^&i�z	<unknown>c@seZdZdZdS)�ProvisionalCompleterWarningz�
 185      Exception raise by an experimental feature in this module.
 186  
 187      Wrap code in :any:`provisionalcompleter` context manager if you
 188      are certain you want to use an unstable feature.
 189      N)�__name__�
 190  __module__�__qualname__�__doc__r6r6r6r9r@5sr@�error��category�ignoreccsD�t���tj|td�dVWd�dS1swYdS)a�
 191      This context manager has to be used in any place where unstable completer
 192      behavior and API may be called.
 193  
 194      >>> with provisionalcompleter():
 195      ...     completer.do_experimental_things() # works
 196  
 197      >>> completer.do_experimental_things() # raises.
 198  
 199      .. note::
 200  
 201          Unstable
 202  
 203          By using this context manager you agree that the API in use may change
 204          without warning, and that you won't complain if they do so.
 205  
 206          You also understand that, if the API is not to your liking, you should report
 207          a bug to explain your use case upstream.
 208  
 209          We'll be happy to get your feedback, feature requests, and improvements on
 210          any of the unstable APIs!
 211      rFN)�warnings�catch_warnings�filterwarningsr@)�actionr6r6r9�provisionalcompleterAs
 212  �
 213  "�rM�s�str�return�Union[str, bool]cCs(|�d�dr	dS|�d�drdSdS)aReturn whether a string has open quotes.
 214  
 215      This simply counts whether the number of quote characters of either type in
 216      the string is odd.
 217  
 218      Returns
 219      -------
 220      If there is an open quote, the quote character is returned.  Else, return
 221      False.
 222      �"��'F)�count�rNr6r6r9�has_open_quotes_s
 223  
 224  rW�protectablescsBt|�t��@rtjdkrd|dSd��fdd�|D��S|S)z.Escape a string to protect certain characters.r>rR�c3s$�|]
 225  }|�vrd|n|VqdS��\Nr6��.0�c�rXr6r9�	<genexpr>zs�"z#protect_filename.<locals>.<genexpr>)�set�sys�platform�join)rNrXr6r_r9�protect_filenamets
 226  
 227  re�path�Tuple[str, bool, str]cCsTd}d}|}|�d�r%d}t|�d}tj�|�}|r#|d|�}n|}|||fS)a�Expand ``~``-style usernames in strings.
 228  
 229      This is similar to :func:`os.path.expanduser`, but it computes and returns
 230      extra information that will be useful if the input was being used in
 231      computing completions, and you wish to return the completions with the
 232      original '~' instead of its expanded value.
 233  
 234      Parameters
 235      ----------
 236      path : str
 237          String to be expanded.  If no ~ is present, the output is the same as the
 238          input.
 239  
 240      Returns
 241      -------
 242      newpath : str
 243          Result of ~ expansion in the input path.
 244      tilde_expand : bool
 245          Whether any expansion was performed or not.
 246      tilde_val : str
 247          The value that ~ was replaced with.
 248      FrY�~T�N)�
 249  startswith�len�osrf�
 250  expanduser)rf�tilde_expand�	tilde_val�newpath�restr6r6r9�expand_users
 251  
 252  rrrn�boolrocCs|r|�|d�S|S)z8Does the opposite of expand_user, with its outputs.
 253      rh��replace)rfrnror6r6r9�
 254  compress_user�srvcCs�d\}}|�d�rd}n|�d�rd}|�d�rd}|�d�r0d	|dd
 255  �vr/|dd
 256  �}d}n|�d	�rEd	|dd
 257  �vrE|dd
 258  �}d}|||fS)z�key for sorting completions
 259  
 260      This does several things:
 261  
 262      - Demote any completions starting with underscores to the end
 263      - Insert any %magic and %%cellmagic completions in the alphabetical order
 264        by their name
 265      )rr�__rS�_ri�=�����z%%�%N)rj�endswith)�wordZprio1Zprio2r6r6r9�completions_sorting_key�s"	
 266  
 267  
 268  
 269  �
 270  
 271  r~c@s eZdZdZdd�Zdd�ZdS)�_FakeJediCompletionz�
 272      This is a workaround to communicate to the UI that Jedi has crashed and to
 273      report a bug. Will be used only id :any:`IPCompleter.debug` is set to true.
 274  
 275      Added in IPython 6.0 so should likely be removed for 7.0
 276  
 277      cCs.||_||_d|_||_d|_d|_d|_dS)NZcrashedrYZfake)�name�complete�type�name_with_symbols�	signature�_origin�text)�selfr�r6r6r9�__init__�s
 278  z_FakeJediCompletion.__init__cC�dS)Nz)<Fake completion object jedi has crashed>r6�r�r6r6r9�__repr__�sz_FakeJediCompletion.__repr__N)rArBrCrDr�r�r6r6r6r9r�s
 279  rzjedi.api.Completionc@sFeZdZdZgd�Zdddd�ddd�Zdd�Zddd�Zdd�ZdS)�
 280  Completionao
 281      Completion object used and returned by IPython completers.
 282  
 283      .. warning::
 284  
 285          Unstable
 286  
 287          This function is unstable, API may change without warning.
 288          It will also raise unless use in proper context manager.
 289  
 290      This act as a middle ground :any:`Completion` object between the
 291      :any:`jedi.api.classes.Completion` object and the Prompt Toolkit completion
 292      object. While Jedi need a lot of information about evaluator and how the
 293      code should be ran/inspected, PromptToolkit (and other frontend) mostly
 294      need user facing information.
 295  
 296      - Which range should be replaced replaced by what.
 297      - Some metadata (like completion type), or meta information to displayed to
 298        the use user.
 299  
 300      For debugging purpose we can also store the origin of the completion (``jedi``,
 301      ``IPython.python_matches``, ``IPython.magics_matches``...).
 302      ��start�endr�r�r�r�NrY�r�r�r�r��intr�r�rOr��
 303  Optional[str]rP�NonecCs8tjdtdd�||_||_||_||_||_||_dS)Nz~``Completion`` is a provisional API (as of IPython 6.0). It may change without warnings. Use in corresponding context manager.rS�rG�
 304  stacklevel)	rI�warnr@r�r�r�r�r�r�)r�r�r�r�r�r�r�r6r6r9r�s
 305  �
 306  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�r6r6r9r�s�zCompletion.__repr__rscCs$|j|jko|j|jko|j|jkS)a]
 307          Equality and hash do not hash the type (as some completer may not be
 308          able to infer the type), but are use to (partially) de-duplicate
 309          completion.
 310  
 311          Completely de-duplicating completion is a bit tricker that just
 312          comparing as it depends on surrounding text, which Completions are not
 313          aware of.
 314          )r�r�r�)r��otherr6r6r9�__eq__"s
 315  
 316  
 317  �
 318  �zCompletion.__eq__cCst|j|j|jf�S�N)�hashr�r�r�r�r6r6r9�__hash__0szCompletion.__hash__)
 319  r�r�r�r�r�rOr�r�rPr�)rPrs)	rArBrCrD�	__slots__r�r�r�r�r6r6r6r9r��s�
 320  r�c@s0eZdZdZddgZdd�ddd	�Zd
 321  d�ZdS)
 322  �SimpleCompletiona�Completion item to be included in the dictionary returned by new-style Matcher (API v2).
 323  
 324      .. warning::
 325  
 326          Provisional
 327  
 328          This class is used to describe the currently supported attributes of
 329          simple completion items, and any additional implementation details
 330          should not be relied on. Additional attributes may be included in
 331          future versions, and meaning of text disambiguated from the current
 332          dual meaning of "text to insert" and "text to used as a label".
 333      r�r�N�r�rOr�cCs||_||_dSr��r�r�)r�r�r�r6r6r9r�Ds
 334  zSimpleCompletion.__init__cCsd|j�d|j�d�S)Nz<SimpleCompletion text=z type=�>r�r�r6r6r9r�HszSimpleCompletion.__repr__)r�rOr�r�)rArBrCrDr�r�r�r6r6r6r9r�4s
 335  
 336  r�c@s2eZdZUdZded<ded<ded<ded	<d
 337  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�rArBrCrD�__annotations__r6r6r6r9r�Ls
 338  r��dict)Zshow_inherited_membersZexclude_inherited_fromc@�eZdZUdZded<dS)�SimpleMatcherResultz'Result of new-style completion matcher.z7Sequence[SimpleCompletion] | Iterator[SimpleCompletion]�completionsNr�r6r6r6r9r�^s
 339  r�c@r�)�_JediMatcherResultz@Matching result returned by Jedi (will be processed differently)�Iterator[_JediCompletionLike]r�Nr�r6r6r6r9r�is
 340  r��
 341  AnyCompletionc@sVeZdZUdZded<ded<ded<ded<ded	<eddd��Zedd
 342  d��ZdS)�CompletionContextzMCompletion context provided as an argument to matchers in the Matcher API v2.rO�token�	full_textr��cursor_position�cursor_linez
 343  Optional[int]�limitrPcCs|jd|j�Sr�)�line_with_cursorr�r�r6r6r9�text_until_cursor��z#CompletionContext.text_until_cursorcCs|j�d�|jS)N�
 344  )r��splitr�r�r6r6r9r��sz"CompletionContext.line_with_cursorN�rPrO)rArBrCrDr�rr�r�r6r6r6r9r�ts
 345  r�c@s eZdZUd	dd�Zded<dS)
 346  �_MatcherAPIv1Baser�rOrP�	List[str]cCr��zCall signature.Nr6�r�r�r6r6r9�__call__�r:z_MatcherAPIv1Base.__call__rCN�r�rOrPr�)rArBrCr�r�r6r6r6r9r��s
 347  
 348  r�c@s eZdZUded<d
 349  dd�Zd	S)�_MatcherAPIv1TotalzOptional[Literal[1]]�matcher_api_versionr�rOrPr�cCr�r�r6r�r6r6r9r��r:z_MatcherAPIv1Total.__call__Nr�)rArBrCr�r�r6r6r6r9r��s
 350  r�r3�MatcherAPIv1c@s0eZdZUdZdZded<dd	d
 351  �Zded<d
 352  S)�MatcherAPIv2z#Protocol describing Matcher API v2.rSz
 353  Literal[2]r��contextr�rP�
 354  MatcherResultcCr�r�r6)r�r�r6r6r9r��r:zMatcherAPIv2.__call__rOrCN)r�r�rPr�)rArBrCrDr�r�r�r6r6r6r9r��s
 355  
 356  
 357  r��Matcher�matcher�TypeGuard[MatcherAPIv1]cC�t|�}|dkS)Nri��_get_matcher_api_version�r��api_versionr6r6r9�_is_matcher_v1��r��TypeGuard[MatcherAPIv2]cCr�)NrSr�r�r6r6r9�_is_matcher_v2�r�r��valuer�TypeGuard[Sized]cC�
 358  t|d�S)�%Determines whether objects is sizable�__len__��hasattr�r�r6r6r9�_is_sizable��
 359  r��TypeGuard[Iterator]cCr�)r��__next__r�r�r6r6r9�_is_iterator�r�r��resultr�cCsp|d}t|�rt|�dkSt|�r4z|}t|�}tttt�|g|��|d<WdSt	y3YdSwt
 360  d��)z-Check if any result includes any completions.r�rTFzCCompletions returned by matcher need to be an Iterator or a Sizable)r�rkr��nextr/rr��	itertools�chain�
 361  StopIteration�
 362  ValueError)r�r�Zold_iterator�firstr6r6r9�has_any_completions�s$���r�ri)�priority�
 363  identifierr�r��Optional[float]r�r�r�r��Callable[[Matcher], Matcher]csd���fdd�}|S)aWAdds attributes describing the matcher.
 364  
 365      Parameters
 366      ----------
 367      priority : Optional[float]
 368          The priority of the matcher, determines the order of execution of matchers.
 369          Higher priority means that the matcher will be executed first. Defaults to 0.
 370      identifier : Optional[str]
 371          identifier of the matcher allowing users to modify the behaviour via traitlets,
 372          and also used to for debugging (will be passed as ``origin`` with the completions).
 373  
 374          Defaults to matcher function's ``__qualname__`` (for example,
 375          ``IPCompleter.file_matcher`` for the built-in matched defined
 376          as a ``file_matcher`` method of the ``IPCompleter`` class).
 377      api_version: Optional[int]
 378          version of the Matcher API used by this matcher.
 379          Currently supported values are 1 and 2.
 380          Defaults to 1.
 381      �funcr�csL�pd|_�p	|j|_�|_tr$�dkrtt|�}|S�dkr$tt|�}|S)NrrirS)�matcher_priorityrC�matcher_identifierr�rr/r�r�)r��r�r�r�r6r9�wrapper	s
 382  
 383  �
 384  z#completion_matcher.<locals>.wrapperN)r�r�r6)r�r�r�r�r6r�r9�completion_matcher�sr�cC�t|dd�S)Nr�r��getattr�r�r6r6r9�_get_matcher_priority�r�cCst|d|j�S)Nr�)r�rCr�r6r6r9�_get_matcher_id�r�cCr�)Nr�rir�r�r6r6r9r�r�r�rS�r�r�r��_ICccs��t|�}|s	dStdd�|D��}tdd�|D��}t�}|D]}|||j�|j||j|�}||vr?|V|�|�q dS)a
 385      Deduplicate a set of completions.
 386  
 387      .. warning::
 388  
 389          Unstable
 390  
 391          This function is unstable, API may change without warning.
 392  
 393      Parameters
 394      ----------
 395      text : str
 396          text that should be completed.
 397      completions : Iterator[Completion]
 398          iterator over the completions to deduplicate
 399  
 400      Yields
 401      ------
 402      `Completions` objects
 403      Completions coming from multiple sources, may be different but end up having
 404      the same effect when applied to ``text``. If this is the case, this will
 405      consider completions as equal and only emit the first encountered.
 406      Not folded in `completions()` yet for debugging purpose, and to detect when
 407      the IPython completer does return things that Jedi does not, but should be
 408      at some point.
 409      Ncs��|]}|jVqdSr��r�r\r6r6r9r`H��z+_deduplicate_completions.<locals>.<genexpr>csr�r��r�r\r6r6r9r`Ir�)�list�min�maxrar�r�r��add)r�r��	new_start�new_end�seenr^�new_textr6r6r9�_deduplicate_completions)s�"
 410  ��r	)�_debugr
 411  c	cs��tjdtdd�t|�}|sdSdd�|D�}dd�|D�}t|�}t|�}t�}t�}|D]6}	|||	j�|	j||	j	|�}
 412  |	j
 413  dkrM|�|
 414  �n
 415  |	j
 416  d	krW|�|
 417  �t|||
 418  |	j
 419  |	j
 420  |	jd
 421  �Vq/|�|�}|rv|rxtd|�dSdSdS)a�
 422      Rectify a set of completions to all have the same ``start`` and ``end``
 423  
 424      .. warning::
 425  
 426          Unstable
 427  
 428          This function is unstable, API may change without warning.
 429          It will also raise unless use in proper context manager.
 430  
 431      Parameters
 432      ----------
 433      text : str
 434          text that should be completed.
 435      completions : Iterator[Completion]
 436          iterator over the completions to rectify
 437      _debug : bool
 438          Log failed completion
 439  
 440      Notes
 441      -----
 442      :any:`jedi.api.classes.Completion` s returned by Jedi may not have the same start and end, though
 443      the Jupyter Protocol requires them to behave like so. This will readjust
 444      the completion to have the same ``start`` and ``end`` by padding both
 445      extremities with surrounding text.
 446  
 447      During stabilisation should support a ``_debug`` option to log which
 448      completion are return by the IPython completer and not found in Jedi in
 449      order to make upstream bug report.
 450      z�`rectify_completions` is a provisional API (as of IPython 6.0). It may change without warnings. Use in corresponding context manager.rSr�Ncsr�r�r�r\r6r6r9r`zr�z&rectify_completions.<locals>.<genexpr>csr�r�rr\r6r6r9r`{r��jedi�IPCompleter.python_matcherr�z#IPython.python matches have extras:)rIr�r@rrrrar�r�r�r�rr�r�r��
 451  difference�print)r�r�r
 452  ZstartsZendsrrZ	seen_jediZseen_python_matchesr^r�diffr6r6r9�rectify_completionsSs0��"
 453  
 454  
 455  
 456  �rz 	
 457  `!@#$^&*()=+[{]}|;'",<>?z 	
 458  `!@#$^&*()=+[{]}\|;:'",<>?z =
 459  c@sJeZdZdZeZdZdZd
 460  dd�Ze	dd��Z
 461  e
 462  jdd��Z
 463  d
 464  dd	�ZdS)�CompletionSplitteraWAn object to split an input line in a manner similar to readline.
 465  
 466      By having our own implementation, we can expose readline-like completion in
 467      a uniform manner to all frontends.  This object only needs to be given the
 468      line of text to be split and the cursor position on said line, and it
 469      returns the 'word' to be completed on at the cursor after splitting the
 470      entire line.
 471  
 472      What characters are used as splitting delimiters can be controlled by
 473      setting the ``delims`` attribute (this is a property that internally
 474      automatically builds the necessary regular expression)NcCs|durtjn|}||_dSr�)r�_delims�delims)r�rr6r6r9r��s
 475  zCompletionSplitter.__init__cCs|jS)z*Return the string of delimiter characters.)rr�r6r6r9r�szCompletionSplitter.delimscCs8dd�dd�|D��d}t�|�|_||_||_dS)z&Set the delimiters for line splitting.�[rYcs��|]}d|VqdSrZr6r\r6r6r9r`���z,CompletionSplitter.delims.<locals>.<genexpr>�]N)rd�re�compile�	_delim_rer�_delim_expr)r�r�exprr6r6r9r�s
 476  cCs(|dur|n|d|�}|j�|�dS)zBSplit a line of text with a cursor at the given position.
 477          Nrz)rr�)r��line�
 478  cursor_posZcut_liner6r6r9�
 479  split_line�szCompletionSplitter.split_liner�)
 480  rArBrCrD�DELIMSrrrr��propertyr�setterrr6r6r6r9r�s
 481  
 482  
 483  rcs�eZdZeddd�jdd�Zedddd	�jdd�Zeed
 484  d	�jdd�Z	e
 485  ddd	�jdd�Zedd
 486  d	�jdd�Zeddd�jdd�Z
 487  eddd�jdd�Zd'�fdd�	Zdd�Zdd�Zdd�Ze�d�Z	d(d)d d!�Zd*d#d$�Zd%d&�Z�ZS)+r<FalActivate greedy completion.
 488  
 489          .. deprecated:: 8.8
 490              Use :std:configtrait:`Completer.evaluation` and :std:configtrait:`Completer.auto_close_dict_keys` instead.
 491  
 492          When enabled in IPython 8.8 or newer, changes configuration as follows:
 493  
 494          - ``Completer.evaluation = 'unsafe'``
 495          - ``Completer.auto_close_dict_keys = True``
 496          ��helpT��config)�	forbiddenZminimal�limited�unsafeZ	dangerousr(a�Policy for code evaluation under completion.
 497  
 498          Successive options allow to enable more eager evaluation for better
 499          completion suggestions, including for nested dictionaries, nested lists,
 500          or even results of function calls.
 501          Setting ``unsafe`` or higher can lead to evaluation of arbitrary user
 502          code on :kbd:`Tab` with potentially unwanted or dangerous side effects.
 503  
 504          Allowed values are:
 505  
 506          - ``forbidden``: no evaluation of code is permitted,
 507          - ``minimal``: evaluation of literals and access to built-in namespace;
 508            no item/attribute evaluationm no access to locals/globals,
 509            no evaluation of any operations or comparisons.
 510          - ``limited``: access to all namespaces, evaluation of hard-coded methods
 511            (for example: :any:`dict.keys`, :any:`object.__getattr__`,
 512            :any:`object.__getitem__`) on allow-listed objects (for example:
 513            :any:`dict`, :any:`list`, :any:`tuple`, ``pandas.Series``),
 514          - ``unsafe``: evaluation of all methods and function calls but not of
 515            syntax with side-effects like `del x`,
 516          - ``dangerous``: completely arbitrary evaluation.
 517          ��
 518  default_valuer$zYExperimental: Use Jedi to generate autocompletions. Default to True if jedi is installed.i�z�Experimental: restrict time (in milliseconds) during which Jedi can compute types.
 519          Set to 0 to stop computing types. Non-zero value lower than 100ms may hurt
 520          performance by preventing jedi to build its cache.
 521          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.a.
 522          Enable auto-closing dictionary keys.
 523  
 524          When enabled string keys will be suffixed with a final quote
 525          (matching the opening quote), tuple keys will also receive a
 526          separating comma if needed, and keys which are final will
 527          receive a closing bracket (``]``).
 528          NcsR|durd|_nd|_||_|duri|_n||_g|_tt|�jdi|��dS)a�Create a new completer for the command line.
 529  
 530          Completer(namespace=ns, global_namespace=ns2) -> completer instance.
 531  
 532          If unspecified, the default namespace where completions are performed
 533          is __main__ (technically, __main__.__dict__). Namespaces should be
 534          given as dictionaries.
 535  
 536          An optional second namespace can be given.  This allows the completer
 537          to handle cases where both the local and global scopes need to be
 538          distinguished.
 539          NTFr6)�use_main_ns�	namespace�global_namespace�custom_matchers�superr<r�)r�r-r.�kwargs��	__class__r6r9r�szCompleter.__init__cCsZ|jrtj|_|dkrd|vr|�|�|_n|�|�|_z|j|WSty,YdSw)z�Return the next possible completion for 'text'.
 540  
 541          This is called successively with state == 0, 1, 2, ... until it
 542          returns None.  The completion should begin with 'text'.
 543  
 544          r�.N)r,�__main__�__dict__r-�attr_matches�matches�global_matches�
 545  IndexError)r�r��stater6r6r9r�6s�zCompleter.completecs�g}|j}t|�}tjtj��t|j���t|j	���fD]}|D]}|d|�|kr3|dkr3||�q!qt
 546  �d��t|j���t|j	���fD]$}�fdd�|D�}|��D]}|d|�|krk|dkrk|||�qWqH|S)z�Compute matches when text is a simple name.
 547  
 548          Return a list of all keywords, built-in functions and names currently
 549          defined in self.namespace or self.global_namespace that match.
 550  
 551          N�__builtins__z[^_]+(_[^_]+)+?\Zcs2i|]}��|�rd�dd�|�d�D��|�qS)rxcSsg|]}|d�qS)rr6)r]�subr6r6r9�
 552  <listcomp>a�z7Completer.global_matches.<locals>.<dictcomp>.<listcomp>)�matchrdr�)r]r}�Z
 553  snake_case_rer6r9�
 554  <dictcomp>`s��z,Completer.global_matches.<locals>.<dictcomp>)�appendrk�keyword�kwlist�builtin_modr6�keysrr-r.rr)r�r�r8Zmatch_append�n�lstr}Z	shortenedr6rAr9r9Js0���
 555   
 556  ���zCompleter.global_matchescCs|�|�dS)a�Compute matches when text contains a dot.
 557  
 558          Assuming the text is of the form NAME.NAME....[NAME], and is
 559          evaluatable in self.namespace or self.global_namespace, it will be
 560          evaluated and its attributes (as revealed by dir()) are used as
 561          possible completions.  (For class instances, class members are
 562          also considered.)
 563  
 564          WARNING: this can still invoke arbitrary C code, if an object
 565          with a __getattr__ hook is evaluated.
 566  
 567          r)�
 568  _attr_matchesr�r6r6r9r7js
 569  zCompleter.attr_matchesz(.+)\.(\w*)$r�rO�include_prefixrsrP�Tuple[Sequence[str], str]c
 570  sl|j�|�}|sgdfS|�dd�\}�|�|�}|tur!gdfS|jr.t|d�r.t|�}nt|�}zt	�
 571  ||�}WntyCYntyJ�t
 572  yRYnwt���|r�t|�}t|�}tjtjh}	d}
 573  g}|D]/}|j|	vruqm|jtjkr�|
 574  r�|�|j�d}
 575  qm|jtjkr�|jdkr�|
 576  s�|�|j�d}
 577  qmd�t|���nd����fdd	�|D�d�fS)
 578  NrYrirS�__all__TFr4cs(g|]}|d���krd�|f�qS)Nz%s.%sr6�r]�w��attrrHZprefix_after_spacer6r9r>�s(z+Completer._attr_matches.<locals>.<listcomp>)�_ATTR_MATCH_REr@�group�_evaluate_expr�	not_found�limit_to__all__r��get__all__entriesr"r Zcomplete_objectr�AssertionError�	Exceptionrk�
 579  _parse_tokens�reversed�tokenize�	ENDMARKER�NEWLINEr��NAMErC�string�OPrd)
 580  r�r�rK�m2rr8�words�tokens�
 581  rev_tokens�	skip_overZ	name_turn�partsr�r6rPr9rJ|sR
 582  
 583  �
 584  �zCompleter._attr_matches�codecCs||r<|dd�}zt�|�}Wn	tyYqw|dusJ�t|j�dkr'q|jdj}t|tj�r:|ddks:q|SdS)z�
 585          Trim the code until it is a valid expression and not a tuple;
 586  
 587          return the trimmed expression for guarded_eval.
 588          riNrrz�)rY)�ast�parse�SyntaxErrorrk�bodyr��
 589  isinstancer
 590  )r�rh�resrr6r6r9�
 591  _trim_expr�s�zCompleter._trim_exprc
 592  Cs~t}d}|s=|r=zt|t|j|j|jd��}d}Wnty8}z|jr)td|�|�	|�}WYd}~nd}~ww|s=|s|S)NF)�globals�locals�
 593  evaluationTzEvaluation exception)
 594  rUrrr.r-rsrY�debugrrp)r�rr8�done�er6r6r9rT�s*��
 595  ���zCompleter._evaluate_expr)NN)T)r�rOrKrsrPrL)rhrOrPrO)rArBrCr'�tag�greedyr(rs�JEDI_INSTALLED�use_jedir)�jedi_compute_type_timeoutrt�backslash_combining_completions�auto_close_dict_keysr�r�r9r7rrrRrJrprT�
 596  __classcell__r6r6r2r9r<�sb�������������
 597  �! 
 598  �
 599  AcCs4zt|d�}WntygYSwdd�|D�S)z,returns the strings in the __all__ attributerMcSsg|]	}t|t�r|�qSr6)rnrOrNr6r6r9r>��z%get__all__entries.<locals>.<listcomp>)r�rY)r8rcr6r6r9rW�s�rWc@s,eZdZdZdZe��Ze��Ze��Z	dS)�
 600  _DictKeyStateaRepresent state of the key match in context of other possible matches.
 601  
 602      - given `d1 = {'a': 1}` completion on `d1['<tab>` will yield `{'a': END_OF_ITEM}` as there is no tuple.
 603      - given `d2 = {('a', 'b'): 1}`: `d2['a', '<tab>` will yield `{'b': END_OF_TUPLE}` as there is no tuple members to add beyond `'b'`.
 604      - given `d3 = {('a', 'b'): 1}`: `d3['<tab>` will yield `{'a': IN_TUPLE}` as `'a'` can be added.
 605      - given `d4 = {'a': 1, ('a', 'b'): 2}`: `d4['<tab>` will yield `{'a': END_OF_ITEM & END_OF_TUPLE}`
 606      rN)
 607  rArBrCrD�BASELINE�enum�auto�END_OF_ITEM�END_OF_TUPLE�IN_TUPLEr6r6r6r9r��sr�cCs\g}t�t|���j�}	z	|�t|��Wntjy"|YSty,|YSwq
 608  )z'Parse tokens even if there is an error.)	r\�generate_tokens�iter�
 609  splitlinesr�rCr��
 610  TokenErrorr�)r^rdZtoken_generatorr6r6r9rZs��rZ�prefix�Union[str, None]cCs�|d��rdSt|�}t|�}tjtjh}d}|D]4}|j|vr"q|dur3|jtjkr0|j}qdS|jtj	krL|jdkrA|S|jdvrK|j|}qdS|S)z�Match any valid Python numeric literal in a prefix of dictionary keys.
 611  
 612      References:
 613      - https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals
 614      - https://docs.python.org/3/library/tokenize.html
 615      rzN�,>�+�-)
 616  �isspacerZr[r\r]r^r��NUMBERr`ra)r�rdrerf�numberr�r6r6r9� _match_number_in_dict_key_prefixs.
 617  
 618  
 619  �
 620  �r�)�0bZ0o�0xrG�6List[Union[str, bytes, Tuple[Union[str, bytes], ...]]]r�extra_prefix�'Optional[Tuple[Union[str, bytes], ...]]�)Tuple[str, int, Dict[str, _DictKeyState]]cs�|r|nd�tdd��D���tttttf����fdd�}tdd��}|D]7}t|t�rJ||�rI|�}||t	|��dkrDt
 621  jnt
 622  jO<q&�d	krOq&t|��r]||t
 623  j
 624  O<q&|��}|spd
 625  d	dd�|��D�fSt�d
 626  |�}	d}
 627  |	r�|	��}||}zt|�}
 628  Wn!ty�d
 629  d	ifYSwt|�}|dur�d
 630  d	ifS|}
 631  d}
 632  d
 633  }dd
 634  �dd�|D��d}t�||tj�}|dus�J�|��}|��}i}|D]�}t|ttf�r�|
 635  s�q�t|�}t|t�r�|
 636  dd���}|tvr�t|}||�}n|
 637  r�q�|}z
 638  |�|
 639  ��s
 640  Wq�Wn
 641  tttf�yYq�w|t	|
 642  �d�}t|t��r-t|d�nt|d�}|d|� d�d�}|dk�rI|�!dd�}d||f}||||<q�|||fS)amUsed by dict_key_matches, matching the prefix to a list of keys
 643  
 644      Parameters
 645      ----------
 646      keys
 647          list of keys in dictionary currently being completed.
 648      prefix
 649          Part of the text already typed by the user. E.g. `mydict[b'fo`
 650      delims
 651          String of delimiters to consider when finding the current key.
 652      extra_prefix : optional
 653          Part of the text already typed in multi-key index cases. E.g. for
 654          `mydict['foo', "bar", 'b`, this would be `('foo', 'bar')`.
 655  
 656      Returns
 657      -------
 658      A tuple of three elements: ``quote``, ``token_start``, ``matched``, with
 659      ``quote`` being the quote that need to be used to close current string.
 660      ``token_start`` the position where the replacement should start occurring,
 661      ``matches`` a dictionary of replacement/completion keys on keys and values
 662          indicating whether the state.
 663      r6cSsg|]}t|t��qSr6)rn�slice�r]�kr6r6r9r>\s
 664  ��z#match_dict_keys.<locals>.<listcomp>csZt|��krdS|D]
 665  }t|��sdSq
 666  t|��D]\}}||kr*t|t�s*dSqdS)NFT)rkrn�zipr�)�keyr��pt�Zprefix_tupleZprefix_tuple_sizeZtext_serializable_typesr6r9�filter_prefix_tupleds
 667  ��z,match_dict_keys.<locals>.filter_prefix_tuplecSstjSr�)r�r�r6r6r6r9�<lambda>tsz!match_dict_keys.<locals>.<lambda>rirrYcSsi|]	\}}t|�|�qSr6)�repr�r]r��vr6r6r9rB�rz#match_dict_keys.<locals>.<dictcomp>z(?:"|')FNTz[^csrrZr6r\r6r6r9r`�rz"match_dict_keys.<locals>.<genexpr>z]*$rSrR�"rT�����z\"z%s%s)"�sumrO�bytesr��floatr�rrn�tuplerkr�r�r�r�rG�itemsr�searchrSrrYr�rd�UNICODEr��lower�_INT_FORMATSrj�AttributeError�	TypeError�UnicodeErrorr��indexru)rGr�rr�r�Zfiltered_key_is_finalr�Zkey_fragmentZ
 668  filtered_keysZquote_matchZis_user_prefix_numeric�quoteZvalid_prefixZ
 669  prefix_str�number_match�patternZtoken_matchZtoken_startZtoken_prefixZmatchedr�Zstr_keyZint_baseZ
 670  int_format�remZrem_reprr@r6r�r9�match_dict_keys=s���
 671  �
 672  ���
 673  ��
 674  
 675  ���$
 676  
 677  r�r�columncCsP|�d�}|t|�ksJd�t|�tt|�����tdd�|d|�D��|S)a�
 678      Convert the (line,column) position of the cursor in text to an offset in a
 679      string.
 680  
 681      Parameters
 682      ----------
 683      text : str
 684          The text in which to calculate the cursor offset
 685      line : int
 686          Line of the cursor; 0-indexed
 687      column : int
 688          Column of the cursor 0-indexed
 689  
 690      Returns
 691      -------
 692      Position of the cursor in ``text``, 0-indexed.
 693  
 694      See Also
 695      --------
 696      position_to_cursor : reciprocal of this function
 697  
 698      r�z{} <= {}css�|]	}t|�dVqdS)riN�rk)r]rr6r6r9r`�s�z%cursor_to_position.<locals>.<genexpr>N)r�rk�formatrOr�)r�rr��linesr6r6r9�cursor_to_position�s
 699  (r��offset�Tuple[int, int]cCsbd|krt|�ksnJd|t|�f��|d|�}|�d�}|�d�}t|d�}||fS)a:
 700      Convert the position of the cursor in text (0 indexed) to a line
 701      number(0-indexed) and a column number (0-indexed) pair
 702  
 703      Position should be a valid position in ``text``.
 704  
 705      Parameters
 706      ----------
 707      text : str
 708          The text in which to calculate the cursor offset
 709      offset : int
 710          Position of the cursor in ``text``, 0-indexed.
 711  
 712      Returns
 713      -------
 714      (line, column) : (int, int)
 715          Line of the cursor; 0-indexed, column of the cursor 0-indexed
 716  
 717      See Also
 718      --------
 719      cursor_to_position : reciprocal of this function
 720  
 721      rz
 722  0 <= %s <= %sNr�rz)rkr�rU)r�r��beforeZblinesr�colr6r6r9�position_to_cursor�s.
 723  
 724  r�cGs<|tjvrtj|}|g|�D]}t||�}qt||�SdS)z@Checks if obj is an instance of module.class_name if loaded
 725      N)rb�modulesr�rn)r8�module�
 726  class_name�attrs�mrQr6r6r9�_safe_isinstances
 727  
 728  
 729  �r�r�cC�t|j�\}}t|d|dd�S)z�Match Unicode characters back to Unicode name
 730  
 731      Same as :any:`back_unicode_name_matches`, but adopted to new Matcher API.
 732      �unicodeT�r��fragment�suppress_if_matches)�back_unicode_name_matchesr�� _convert_matcher_v1_result_to_v2�r�r�r8r6r6r9�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
 733  
 734      This does  ``☃`` -> ``\snowman``
 735  
 736      Note that snowman is not a valid python3 combining character but will be expanded.
 737      Though it will not recombine back to the snowman character by the completion machinery.
 738  
 739      This will not either back-complete standard sequences like \n, \b ...
 740  
 741      .. deprecated:: 8.6
 742          You can use :meth:`back_unicode_name_matcher` instead.
 743  
 744      Returns
 745      =======
 746  
 747      Return a tuple with two elements:
 748  
 749      - The Unicode character that was matched (preceded with a backslash), or
 750          empty string,
 751      - a sequence (of 1), name for the match Unicode character, preceded by
 752          backslash, or empty if no match.
 753      rS�rYr6r�r[rz�rRrT)rkr`�
 754  ascii_letters�unicodedatar��KeyError)r��maybe_slash�char�unicr6r6r9r�2s
 755  �r�cCr�)z}Match latex characters back to unicode name
 756  
 757      Same as :any:`back_latex_name_matches`, but adopted to new Matcher API.
 758      �latexTr�)�back_latex_name_matchesr�r�r�r6r6r9�back_latex_name_matcher\r�r�cCspt|�dkrdS|d}|dkrdS|d}|tjvs|dvr!dSzt|}d||gfWSty7YdSw)u�Match latex characters back to unicode name
 759  
 760      This does ``\ℵ`` -> ``\aleph``
 761  
 762      .. deprecated:: 8.6
 763          You can use :meth:`back_latex_name_matcher` instead.
 764      rSr�r�r[rzr�)rkr`r�rr�)r�r�r�r�r6r6r9r�hs�r�cCs(|j}|�d�std|��|dd�S)a
 765      Get parameter name and value from Jedi Private API
 766  
 767      Jedi does not expose a simple way to get `param=value` from its API.
 768  
 769      Parameters
 770      ----------
 771      parameter
 772          Jedi's function `Param`
 773  
 774      Returns
 775      -------
 776      A string like 'a', 'b=1', '*args', '**kwargs'
 777  
 778      zparam zWJedi function parameter description have change format.Expected "param ...", found %r".�N)�descriptionrjr�)Z	parameterr�r6r6r9�_formatparamchildren�s
 779  �r�cCsft|d�r |��}|s
 780  dS|��d}d|��jddd�dSdd�d	d
 781  �dd�|��D�D��S)
 782  aR
 783      Make the signature from a jedi completion
 784  
 785      Parameters
 786      ----------
 787      completion : jedi.Completion
 788          object does not complete a function type
 789  
 790      Returns
 791      -------
 792      a string consisting of the function signature, with the parenthesis but
 793      without the function name. example:
 794      `(a, *args, b=1, **kwargs)`
 795  
 796      �get_signaturesz(?)r�(ri)�maxsplitz(%s)�, cSsg|]}|r|�qSr6r6�r]�fr6r6r9r>�s
 797  �z#_make_signature.<locals>.<listcomp>css&�|]}|��D]}t|�VqqdSr�)Z
 798  defined_namesr�)r]r��pr6r6r9r`�s���z"_make_signature.<locals>.<genexpr>)r�r�Z	to_stringr�rd)�
 799  completionZ
 800  signaturesZc0r6r6r9�_make_signature�s
 801  &r�a�(?x)
 802  (  # match dict-referring - or any get item object - expression
 803      .+
 804  )
 805  \[   # open bracket
 806  \s*  # and optional whitespace
 807  # Capture any number of serializable objects (e.g. "a", "b", 'c')
 808  # and slices
 809  ((?:(?:
 810      (?: # closed string
 811          [uUbB]?  # string prefix (r not handled)
 812          (?:
 813              '(?:[^']|(?<!\\)\\')*'
 814          |
 815              "(?:[^"]|(?<!\\)\\")*"
 816          )
 817      )
 818      |
 819          # capture integers and slices
 820          (?:[-+]?\d+)?(?::(?:[-+]?\d+)?){0,2}
 821      |
 822          # integer in bin/hex/oct notation
 823          0[bBxXoO]_?(?:\w|\d)+
 824      )
 825      \s*,\s*
 826  )*)
 827  ((?:
 828      (?: # unclosed string
 829          [uUbB]?  # string prefix (r not handled)
 830          (?:
 831              '(?:[^']|(?<!\\)\\')*
 832              |
 833              "(?:[^"]|(?<!\\)\\")*
 834          )
 835      )
 836      |
 837          # unfinished integer
 838          (?:[-+]?\d+)
 839      |
 840          # integer in bin/hex/oct notation
 841          0[bBxXoO]_?(?:\w|\d)+
 842      )
 843  )?
 844  $
 845  r8�
 846  Sequence[str]r�r�r�csB�fdd�|D�|r|rdndndd�}|dur||d<tt|�S)zUtility to help with transitioncsg|]}t|�d��qS)r�)r�)r]r@r�r6r9r>��z4_convert_matcher_v1_result_to_v2.<locals>.<listcomp>TF�r�r�Nr�)r/r�)r8r�r�r�r�r6r�r9r��s�
 847  r�cseZdZdZed�dd��Zeddd�Zeedd	�e	ed
 848  dd	��gd
 849  dd�j
 850  dd
 851  �Zeddd�j
 852  dd
 853  �Ze
 854  e�dd�j
 855  dd
 856  �Zedddd�j
 857  dd
 858  �Zeddd�j
 859  dd
 860  �Zeddd�j
 861  dd
 862  �Zeddd�j
 863  dd
 864  �Zed�dd��Z	
 865  d��fdd�	Zed�dd��Zd�d#d$�Zd�d%d&�Zd�d'd(�Ze�d�d,d-��Zd�d.d/�Ze�d�d0d1��Zd�d2d3�Z e�d�d4d5��Z!d�d6d7�Z"e�d�d8d9��Z#d�d:d;�Z$ed<d=�d�d?d@��Z%d�dEdF�Z&GdGdH�dHe'j�Z(dIdJ�Z)dKdL�Z*e�d�dMdN��Z+e,dOdP�d�dRdS��Z-dTdU�Z.dVdW�Z/e�d�dXdY��Z0dZd[�Z1e2d�d_d`��Z3e�d�dadb��Z4d�dcdd�Z5e�d�dedf��Z6e2d�dhdi��Z7e�d�djdk��Z8d�dmdn�Z9e�dodp��Z:dqdr�Z;d�dudv�Z<d�dxdy�Z=d�d�dzd{�Z>d�d�d��Z?d
 866  d
 867  d
 868  d��d�d�d��Z@e2d�d�d���ZAe2d�d�d���ZBe�d�d�d���ZCd�d�d��ZDed�d�d���ZE�ZFS)�r=z?Extension of the completer class with IPython-specific featuresrxcCs8|drd|_d|_t|j_dSd|_d|_t|j_dS)z>update the splitter and readline delims when greedy is changed�newr)Tr(FN)rsr}�
 869  GREEDY_DELIMS�splitterrr �r�Zchanger6r6r9�_greedy_changedszIPCompleter._greedy_changedFz�
 870          Whether to show dict key matches only.
 871  
 872          (disables all matchers except for `IPCompleter.dict_key_matcher`).
 873          r#T)�
 874  allow_noneNag
 875          Whether to suppress completions from other *Matchers*.
 876  
 877          When set to ``None`` (default) the matchers will attempt to auto-detect
 878          whether suppression of other matchers is desirable. For example, at
 879          the beginning of a line followed by `%` we expect a magic completion
 880          to be the only applicable option, and after ``my_dict['`` we usually
 881          expect a completion with an existing dictionary key.
 882  
 883          If you want to disable this heuristic and see completions from all matchers,
 884          set ``IPCompleter.suppress_competing_matchers = False``.
 885          To disable the heuristic for specific matchers provide a dictionary mapping:
 886          ``IPCompleter.suppress_competing_matchers = {'IPCompleter.dict_key_matcher': False}``.
 887  
 888          Set ``IPCompleter.suppress_competing_matchers = True`` to limit
 889          completions to the set of matchers with the highest priority;
 890          this is equivalent to ``IPCompleter.merge_completions`` and
 891          can be beneficial for performance, but will sometimes omit relevant
 892          candidates from matchers further down the priority list.
 893          r*r%a6Whether to merge completion results into a single list
 894  
 895          If False, only the completion results from the first non-empty
 896          completer will be returned.
 897  
 898          As of version 8.6.0, setting the value to ``False`` is an alias for:
 899          ``IPCompleter.suppress_competing_matchers = True.``.
 900          z{List of matchers to disable.
 901  
 902          The list should contain matcher identifiers (see :any:`completion_matcher`).
 903          )rrirSrSa1Instruct the completer to omit private method names
 904  
 905          Specifically, when completing on ``object.<tab>``.
 906  
 907          When 2 [default]: all names that start with '_' will be excluded.
 908  
 909          When 1: all 'magic' names (``__foo__``) will be excluded.
 910  
 911          When 0: nothing will be excluded.
 912          a3
 913          DEPRECATED as of version 5.0.
 914  
 915          Instruct the completer to use __all__ for the completion
 916  
 917          Specifically, when completing on ``object.<tab>``.
 918  
 919          When True: only those names in obj.__all__ will be included.
 920  
 921          When False [default]: the __all__ attribute is ignored
 922          zEIf True, emit profiling data for completion subsystem using cProfile.z.completion_profileszBTemplate for path at which to output profile data for completions.rVcCst�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.)rIr��UserWarningr�r6r6r9�_limit_to_all_changedhs�z!IPCompleter._limit_to_all_changedcs�t|_t�|_t�jd|||d�|��g|_||_t�	d�|_
 923  tj|_tj
 924  �dd�}|dv|_tjdkr:|j|_n|j|_t�	d�|_t�	d�|_|j|jg|_d	|_d	|_|j|jtt|j g|_!|j"ss|j!D]
 925  }|j#�$t%|��qh|j&s{d
 926  |_'d	Sd	S)a�IPCompleter() -> completer
 927  
 928          Return a completer object.
 929  
 930          Parameters
 931          ----------
 932          shell
 933              a pointer to the ipython shell itself.  This is needed
 934              because this completer knows about magic functions, and those can
 935              only be accessed via the ipython instance.
 936          namespace : dict, optional
 937              an optional dict where completions are performed.
 938          global_namespace : dict, optional
 939              secondary optional dict for completions, to
 940              handle cases (such as IPython embedded inside functions) where
 941              both Python scopes are visible.
 942          config : Config
 943              traitlet's config object
 944          **kwargs
 945              passed to super class unmodified.
 946          )r-r.r&z([^\\] )�TERMZxterm)�dumb�emacsr>z^[\w|\s.]+\(([^)]*)\).*z[\s|\[]*(\w+)(?:\s*=\s*.*)NTr6)(r�magic_escaperr�r0r�r8�shellrrZ
 947  space_name_re�globrl�environ�getZ
 948  dumb_terminalrbrc�_clean_glob_win32�
 949  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_matchersr|�disable_matchersrCr��merge_completions�suppress_competing_matchers)r�r�r-r.r&r1�termr�r2r6r9r�osJ��
 950  
 951  
 952  ��
 953  
 954  �zIPCompleter.__init__rP�
 955  List[Matcher]cCs�|jr|jgS|jr$g|j�|j�|j�|j�|j�|j�|j�|j	�Sg|j�|j�|j�|j�|j�|j�|j
 956  �|j	�|j�S)z*All active matcher routines for completion)�dict_keys_only�dict_key_matcherrzr/rr�custom_completer_matcher�
 957  magic_matcher�
 958  _jedi_matcher�file_matcher�python_matcher�python_func_kw_matcherr�r6r6r9�matchers�sN����������������	�zIPCompleter.matchersr�rOr�csb|�d�d�t����fdd���|t|��D�Wd�S1s%wY��|�dS)zQ
 959          Wrapper around the completion methods for the benefit of emacs.
 960          r4rcs,g|]}�r�jrd��|jg�n|j�qS)r4)rzrdr�r\�r�r�r6r9r>�s$�z/IPCompleter.all_completions.<locals>.<listcomp>Nri)�
 961  rpartitionrMr�rkr�r�r6rr9�all_completions�s� �zIPCompleter.all_completionscCs|�d|�S)N�%s*�r�r�r6r6r9r�r�zIPCompleter._clean_globcCsdd�|�d|�D�S)NcSsg|]}|�dd��qS)r[�/rtr�r6r6r9r>�s�z1IPCompleter._clean_glob_win32.<locals>.<listcomp>rrr�r6r6r9r��s�zIPCompleter._clean_glob_win32r�r�r�cC�|�|j�}t|dd�S)z<Same as :any:`file_matches`, but adopted to new Matcher API.rfr�)�file_matchesr�r��r�r�r8r6r6r9r�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	�
 962  |�}|dkrt�fd
 963  d�|�d�D�Stj
 964  d
 965  kr|�|�}n	|�|�dd��}|r�t|�����fdd�|D�}n�r�tj
 966  d
 967  kr�|n�fdd�|D�}n	�fdd�|D�}dd�|D�S)a�Match filenames, expanding ~USER type strings.
 968  
 969          Most of the seemingly convoluted logic in this completer is an
 970          attempt to handle filenames with spaces in them.  And yet it's not
 971          quite perfect, because Python's readline doesn't expose all of the
 972          GNU readline details needed for this to be done correctly.
 973  
 974          For a filename with a space in it, the printed completions will be
 975          only the parts after what's already been typed (instead of the
 976          full completions, as is normally done).  I don't think with the
 977          current (as of Python 2.3) Python readline it's possible to do
 978          better.
 979  
 980          .. deprecated:: 8.6
 981              You can use :meth:`file_matcher` instead.
 982          �!riNrYr�rrzTFc�g|]}�t|��qSr6�rer���text_prefixr6r9r>:r�z,IPCompleter.file_matches.<locals>.<listcomp>�*r>r[cs$g|]}��t|�d���qSr�r&r�)�
 983  len_lsplit�text0r(r6r9r>Gs
 984  ��csg|]}t|���qSr6r&r�)�open_quotesr6r9r>Oscr%r6r&r�r'r6r9r>Qs
 985  ��cSs$g|]}tj�|�r|dn|�qS)r )rlrf�isdir�r]�xr6r6r9r>Us$)rjr�rWr&r�r�r:rerlrfrmr�rbrcrrurk)r�r�r�ZlsplitZhas_protectablesZm0r8r6)r*r,r+r(r9r"sR
 986  ��
 987  ��
 988  �zIPCompleter.file_matchescCsL|j}|�|�}t|dd�}t|�dko|ddk}|o!t|d�|d<|S)z
 989  Match magics.�magicr�rr{r�r�)r��
 990  magic_matchesr�rkrs)r�r�r�r8r�Zis_magic_prefixr6r6r9rWs
 991  zIPCompleter.magic_matchercs�|jj��}|d}|d}|j����|���}|����|����|s.��fdd��n�fdd����fdd�|D�}|���sO|��fdd�|D�7}|S)	zjMatch magics.
 992  
 993          .. deprecated:: 8.6
 994              You can use :meth:`magic_matcher` instead.
 995          r�cellcs|���o|�vS)z�
 996                  Filter magics, in particular remove magics that match
 997                  a name present in global namespace.
 998                  �rj�r0)�	bare_textr9r6r9r8~s
 999  �z*IPCompleter.magic_matches.<locals>.matchescs
1000  |���Sr�r3r4)r5r6r9r8�s
1001  c�g|]
1002  }�|�r�|�qSr6r6�r]r�)r8�pre2r6r9r>��z-IPCompleter.magic_matches.<locals>.<listcomp>cr6r6r6r7)r8�prer6r9r>�r9)r�Zmagics_managerZlsmagicr�rj�lstripr9)r�r�ZlsmZline_magicsZcell_magicsZexplicit_magic�compr6)r5r9r8r:r8r9r1as
1003  
1004  
1005  
1006  zIPCompleter.magic_matchescCr!)z3Match class names and attributes for %config magic.�paramr�)�magic_config_matchesr�r�r#r6r6r9r��z IPCompleter.magic_config_matchercs|�����t��dkr��ddks�ddkr�ttdd�|jjD��dd�d�}d	d�|D�}t��d
1007  kr8|S�d
1008  �d�}|d��fdd�|D�}�d
1009  �d�dkrW|St|�d
1010  kr�|d�kr�||���j	}|�
1011  �}t�t�
1012  d
1013  tj�d|�}�fdd�|����D�SgS)z�Match class names and attributes for %config magic.
1014  
1015          .. deprecated:: 8.6
1016              You can use :meth:`magic_config_matcher` instead.
1017          rr&z%configcSsg|]}|jjdd�r|�qS)Tr%)r3Zclass_traitsr\r6r6r9r>�s
1018  �z4IPCompleter.magic_config_matches.<locals>.<listcomp>cSs|jjSr��r3rA�r/r6r6r9r��sz2IPCompleter.magic_config_matches.<locals>.<lambda>�r�cSsg|]}|jj�qSr6r@r\r6r6r9r>�r?rir4c�g|]	}|���r|�qSr6r3r\)�	classnamer6r9r>��
1019  �z^--rYcs(g|]}|��d�r|�d�d�qS)riryr)rjr�)r]rQ)�textsr6r9r>�s�)�stripr�rk�sortedrar�Z
1020  configurables�findr�r3Zclass_get_helprr=r�	MULTILINEr�)r�r��classesZ
1021  classnamesZclassname_textsZclassname_matches�clsr$r6)rDrFr9r>�s,$�
1022  
1023  �z IPCompleter.magic_config_matchescCr!)z&Match color schemes for %colors magic.r=r�)�magic_color_matchesr�r�r#r6r6r9r�r?zIPCompleter.magic_color_matchercsb|��}|�d�r|�d�t|�dkr/|ddks |ddkr/|d��fdd	�t��D�SgS)
1024  z�Match color schemes for %colors magic.
1025  
1026          .. deprecated:: 8.6
1027              You can use :meth:`magic_color_matcher` instead.
1028          r?rYrSr�colorsz%colorsricrCr6r3)r]�color�r�r6r9r>�rEz3IPCompleter.magic_color_matches.<locals>.<listcomp>)r�r|rCrkrrG)r�r�rFr6rPr9rM�s
1029  
1030  $zIPCompleter.magic_color_matcheszIPCompleter.jedi_matcher)r�r�cCs |j|j|j|jd�}|dd�S)N)�
1031  cursor_columnr�r�Fr�)�
1032  _jedi_matchesr�r�r�r#r6r6r9r�s��zIPCompleter._jedi_matcherrQr�r�r�c
1033  
1034  Cs�|jg}|jdur|�|j�dd�}t|||�}|rK||d}|dkrK|jdkr/dd�}n|jdkr9dd�}n|jd	krCd
1035  d�}ntd�|j���t�|d|�|�}d}	z.d
1036  }
1037  zt	dd�|�
1038  �jjD��}Wn	t
1039  yrYnwt|j�d	ko�|jd	dv}
1040  |
1041  }	Wnty�}z|jr�td|d�WYd}~nd}~ww|	s�tg�Sz
1042  t||j||dd��WSty�}z|jr�ttd|�g�WYd}~Stg�WYd}~Sd}~ww)a�
1043          Return a list of :any:`jedi.api.Completion`\s object from a ``text`` and
1044          cursor position.
1045  
1046          Parameters
1047          ----------
1048          cursor_column : int
1049              column position of the cursor in ``text``, 0-indexed.
1050          cursor_line : int
1051              line position of the cursor in ``text``, 0-indexed
1052          text : str
1053              text to complete
1054  
1055          Notes
1056          -----
1057          If ``IPCompleter.debug`` is ``True`` may return a :any:`_FakeJediCompletion`
1058          object containing a string with the Jedi debug information attached.
1059  
1060          .. deprecated:: 8.6
1061              You can use :meth:`_jedi_matcher` instead.
1062          NcS�|Sr�r6rAr6r6r9r���z+IPCompleter._jedi_matches.<locals>.<lambda>rir4rScSs|j�d�S)Nrx)r�rj�r^r6r6r9r�	scSs|j�d�o|j�d�S)Nrw)r�rjr|rUr6r6r9r�	rrcSrSr�r6rAr6r6r9r�
1063  	rTz'Don't understand self.omit__names == {}TFcss�|]
1064  }t|d�r|VqdS)r�Nr�r\r6r6r9r`	s�z,IPCompleter._jedi_matches.<locals>.<genexpr>>rTrRz5Error detecting if completing a non-finished string :�|)r�rzJOops Jedi has crashed, please report a bug with the following:
1065  """
1066  %s
1067  s""")r-r.rCr��omit__namesr�r�rZInterpreterr��_get_moduleZ	tree_node�childrenr�rkr�rYrtrr��filterr�r)
1068  r�rQr�r��
1069  namespacesZcompletion_filterr�r:�interpreterZtry_jediZcompleting_stringZfirst_childrvr6r6r9rR�s`
1070  
1071  
1072  
1073  
1074  
1075  
1076  �
1077  ������	��zIPCompleter._jedi_matchesc@seZdZdZdZdS)z"IPCompleter._CompletionContextType�	attribute�globalN)rArBrC�	ATTRIBUTE�GLOBALr6r6r6r9�_CompletionContextType7	sracCs�|�|�\}}|r|s|jjS|r)|r)|�d�}|dkr)||dd�}|�|�St�d|�r3|jjSt�d|�}|r?|jjS|jjS)z_
1078          Determine whether the cursor is in an attribute or global completion context.
1079          �{rriNz)(?<!\w)(?<!\d\.)([-+]?\d+\.(\d+)?)(?!\w)$z.*(.+\.(?:[a-zA-Z]\w*)?)$)�_is_in_string_or_commentrar`�rfind�_determine_completion_contextrr�r_)r�r�	is_stringZis_in_expressionZ
1080  expr_startrZchain_matchr6r6r9re;	s
1081  
1082  z)IPCompleter._determine_completion_contextcCs�d}d}d}d}d}d}d}d}	|	t|�k�r'|	dt|�krC||	dvrC||	ddks5||	ddkrC|sC|sC|sC|sCd}|	d7}	|	dt|�kr||	|	d	�d
1083  kre|se|se|}|s`d}|	d	7}	q||	|	d	�dkr|s|s|}|szd}|	d	7}	q||	dkr�|	dt|�kr�|	d7}	q|r�|	dt|�kr�||	|	d�d
1084  kr�|	d7}	q||	dkr�|r�|r�|dkr�d}|d7}|	d7}	q||	dkr�|d8}|dkr�d}d}|	d7}	q|p�|}
1085  ||	dkr�|s�|
1086  s�|}|s�|
1087  s�d}n||	dk�r|�s|
1088  �s|}|�s|
1089  �sd}||	dk�r|�s|�s|
1090  �sdS|	d7}	|	t|�ks|�p1|�p1|�p1|}|�p:|�o:||�o@|dkfS)z�
1091          Determine if the cursor is inside a string or comment.
1092          Returns (is_string, is_in_expression) tuple:
1093          - is_string: True if in any kind of string
1094          - is_in_expression: True if inside an f-string/t-string expression
1095          Frri)r��trRrTTrSr-z"""z'''r[z{{rb�}�#)TFr�)r�r�Zin_single_quoteZin_double_quoteZin_triple_singleZin_triple_doubleZin_template_stringZ
1096  in_expressionZexpression_depth�iZin_triple_quoterfr6r6r9rcZ	s� ��������$�����[��z$IPCompleter._is_in_string_or_commentcCs�|j}|�|�}||jjkrLz,|j|dd�\}}|�d�r3|jr3|jdkr*dd�}ndd�}t||�}t|d|d	�WSt	yKg}t|dd
1097  �YSw|�
1098  |j�}t|dd
1099  �S)z'Match attributes or global python namesF)rKr4ricS�t�d|�duS�Nz.*\.__.*?__�rr@��txtr6r6r9r��	sz,IPCompleter.python_matcher.<locals>.<lambda>cS�t�d||�d�d��duS�Nz\._.*?r4�rr@�rindexrnr6r6r9r��	s�r])r�r�r��variable)r�rerar_rJr|rWrZr��	NameErrorr9r�)r�r�r��completion_typer8r��no__namer6r6r9r�	s(
1100  
1101  
1102  �
1103  ��rrir��
1104  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 names.
1105  
1106          .. deprecated:: 8.27
1107              You can use :meth:`python_matcher` instead.r4ricSrkrlrmrnr6r6r9r��	sz,IPCompleter.python_matches.<locals>.<lambda>cSrprqrrrnr6r6r9r��	s)r7r|rWrZrur9)r�r�r8rwr6r6r9�python_matches�	s&
1108  
1109  
1110  ����
1111  zIPCompleter.python_matchescCsh|durgS|����d}|j�|�}|durgS|��d�d�}g}|D]
1112  }||j�|�7}q'|S)aParse the first line of docstring for call signature.
1113  
1114          Docstring should be of the form 'min(iterable[, key=func])
1115  '.
1116          It can also parse cython docstring of the form
1117          'Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)'.
1118          Nrr�)r;r�rr��groupsr�r�findall)r��docr�sig�retrNr6r6r9�!_default_arguments_from_docstring
1119  sz-IPCompleter._default_arguments_from_docstringcs�|}g}t�|�r
1120  n/t�|�s9t�|�s9t�|�r1||�t|dd��7}t|dd�p/t|dd�}nt|d�r9|j}||�t|dd��7}tj	j
1121  tj	jf�zt�|�}|�
1122  �fdd�|j��D��Wn	tykYnwtt|��S)	z_Return the list of default arguments of obj if it is callable,
1123          or empty list otherwise.rDrYr�N�__new__r�c3s"�|]\}}|j�vr|VqdSr�)�kindr��Z_keepsr6r9r`<
1124  s�
1125  
1126  ��z1IPCompleter._default_arguments.<locals>.<genexpr>)�inspect�	isbuiltin�
1127  isfunction�ismethod�isclassrr�r�r��	Parameter�KEYWORD_ONLY�POSITIONAL_OR_KEYWORDr��extend�
1128  parametersr�r�rra)r�r8Zcall_objr~r}r6r�r9�_default_arguments!
1129  s6
1130  
1131  
1132  �
1133  �
1134  
1135  ��
1136  "�zIPCompleter._default_argumentscCr!)z:Match named parameters (kwargs) of the last open function.r=r�)�python_func_kw_matchesr�r�r#r6r6r9rC
1137  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|�
1138  t|��||d	�si|��Wnt|�dksqWnWn	t
1139  y{YnwqUt�}	d	}
1140  t||dd
1141  ��D]$\}}|dkr�|
1142  d7}
1143  n|dkr�|
1144  d8}
1145  |
1146  dkr�q�|dkr�q�|	�|�q�g}z+d�|d
1147  d
1148  d	��}
1149  |�t|
1150  |j��}t|�|	D]}|�|�r�|�
1151  d|�q�W|SY|S)
1152  z�Match named parameters (kwargs) of the last open function.
1153  
1154          .. deprecated:: 8.6
1155              You can use :meth:`python_func_kw_matcher` instead.
1156          r4z�
1157                  '.*?(?<!\\)' |    # single quoted strings or
1158                  ".*?(?<!\\)" |    # double quoted strings or
1159                  \w+          |    # identifier
1160                  \S                # other characters
1161                  rririr�z\w+$TrzNryz%s=)Z_IPCompleter__funcParamsRegexr�rr�VERBOSE�DOTALLr{r�r[r@rCr��popr�rar�rrdr��evalr-rj)r�r��regexprdZ
1162  iterTokensZopenParr�ZidsZisIdZ
1163  usedNamedArgsZ	par_levelZ
1164  next_tokenZ
1165  argMatchesZcallableObjZ	namedArgsZnamedArgr6r6r9r�I
1166  s|
1167  ��
1168  
1169  ����
1170  
1171  �
1172  ���z"IPCompleter.python_func_kw_matchesr8r�	List[Any]cCs�t|d�}|dur|�St|t�st|dd�r*zt|���WSty)gYSwt|dddd�rFzt|j���WStyEgYSwt|dd�sRt|dd	�rX|jj	pWgSgS)
1173  NZ_ipython_key_completions_ZpandasZ	DataFrame�coreZindexingZ_LocIndexer�numpyZndarrayZvoid)
1174  r#rnr�r�rrGrYr8Zdtype�names)r8�methodr6r6r9�	_get_keys�
1175  s(
1176  ��
1177  �zIPCompleter._get_keyscCs|�|j�}t|ddd�S)z7Match string keys in a dictionary, after e.g. ``foo[``.zdict keyT�r�r�)�dict_key_matchesr�r�r#r6r6r9r�
1178  s�zIPCompleter.dict_key_matchercs|j���d�r
1179  gSt�|j�}|durgS|��\}}}|�|�}|tur(gS|�|�}|s1|St	|t
1180  |j|j|j
1181  dd��}t|||jj|d�\}	}
1182  }|sPgSt|j�t|�}|re|�d�}
1183  |
1184  |
1185  }n|��}
1186  }||
1187  krrd�n|||��d}d}|jt|j�d���}|�|	�r�|t|	�d�}nd}|��}t|t�}|�d�o�|j}|�d	�o�|o�|j}|o�|j}|s�|s�|	rɇfd
1188  d�|D�Sg}tjtjB}|��D]/\}}�|}|r�|	r�||	7}||kr�	||vr�|r�|d7}|tjkr�|r�|d7}|�|�q�|S)
1189  z�Match string keys in a dictionary, after e.g. ``foo[``.
1190  
1191          .. deprecated:: 8.6
1192              You can use :meth:`dict_key_matcher` instead.
1193          rNT)rqrrrsZin_subscript)r�r-rYFr�csg|]}�|�qSr6r6r���leadingr6r9r>r?z0IPCompleter.dict_key_matches.<locals>.<listcomp>r�)r�rGr|�DICT_MATCHER_REGEXr�rzrTrUr�rrr.r-rsr�r�rrkr�r��line_bufferrjrnr�r}r�r�r�r�r�rC)r�r�r@rZprior_tuple_keysZ
1194  key_prefixr8rGZtuple_prefixZ
1195  closing_quoteZtoken_offsetr8Z
1196  text_startZ	key_startZcompletion_startZcan_close_quoteZcan_close_bracketZcontinuationZhas_known_tuple_handlingZcan_close_tuple_item�resultsZend_of_tuple_or_itemr�Z
1197  state_flagr�r6r�r9r��
1198  s�	
1199  
1200  ��
1201  �
1202  
1203  
1204  
1205  ���
1206  zIPCompleter.dict_key_matchescC� |�|j�\}}t|d|dd�S)zDSame as :any:`unicode_name_matches`, but adopted to new Matcher API.r�Tr�)�unicode_name_matchesr�r��r�r�r�r8r6r6r9r
1207  0s�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
1208          on the name of the character.
1209  
1210          This does  ``\GREEK SMALL LETTER ETA`` -> ``η``
1211  
1212          Works only on valid python 3 identifier, or on combining characters that
1213          will combine to form a valid identifier.
1214          r[rzriN�arY)rdr��lookup�isidentifierr�)r��slashposrNr�r6r6r9r�8s
1215  
1216  
1217  ���z IPCompleter.unicode_name_matchescCr�)u{Match Latex syntax for unicode characters.
1218  
1219          This does both ``\alp`` -> ``\alpha`` and ``\alpha`` -> ``α``
1220          r�Tr�)�
1221  latex_matchesr�r�r�r6r6r9r	N��zIPCompleter.latex_name_matcherr�csV|�d�}|dkr)||d���tvr�t�gfS�fdd�tD�}|r)�|fSdS)u�Match Latex syntax for unicode characters.
1222  
1223          This does both ``\alp`` -> ``\alpha`` and ``\alpha`` -> ``α``
1224  
1225          .. deprecated:: 8.6
1226              You can use :meth:`latex_name_matcher` instead.
1227          r[rzNcrCr6r3r�rVr6r9r>krz-IPCompleter.latex_matches.<locals>.<listcomp>r�)rdr)r�r�r�r8r6rVr9r�Ys
1228  zIPCompleter.latex_matchescCs:|�|j�pg}t|tdd�}d|d<t|j�h|d<|S)zpDispatch custom completer.
1229  
1230          If a match is found, suppresses all other matchers except for Jedi.
1231          Tr�r�r�)�dispatch_custom_completerr�r��
1232  _UNKNOWN_TYPEr�r)r�r�r8r�r6r6r9rps�z$IPCompleter.custom_completer_matcherc		s|jsdS|j}|��sdSt�}||_�|_|�dd�d}||_|j|_|�	|j
1233  �s6|j�|j
1234  |�}ng}t�
1235  |j�|�||j�|j��D]>}z(||�}|rq�fdd�|D�}|ra|WS�����fdd�|D�WSWqHty{YqHty�	YdSwdS)zg
1236          .. deprecated:: 8.6
1237              You can use :meth:`custom_completer_matcher` instead.
1238          NrircrCr6r3�r]�r�r�r6r9r>�rz9IPCompleter.dispatch_custom_completer.<locals>.<listcomp>csg|]}|�����r|�qSr6)r�rjr�)�text_lowr6r9r>�s)rr�rGr	r�symbolr��commandr�rjr�Z	s_matchesr�r�Zflat_matchesr�r�KeyboardInterrupt)	r�r�r�event�cmdZ	try_magicr^roZwithcaser6)r�r�r9r�~sJ��
1239  ��z%IPCompleter.dispatch_custom_completerr��Iterator[Completion]ccs,�tjdtdd�t�}zdz1|jrddl}|��}|��nd}|j|||j	dd�D]}|r4||vr4q+|V|�
1240  |�q+Wn
1241  tyH	YnwW|duro|��t
1242  |j�tj�|jtt����}td|�|�|�dSdS|dur�|��t
1243  |j�tj�|jtt����}td|�|�|�ww)	a�
1244          Returns an iterator over the possible completions
1245  
1246          .. warning::
1247  
1248              Unstable
1249  
1250              This function is unstable, API may change without warning.
1251              It will also raise unless use in proper context manager.
1252  
1253          Parameters
1254          ----------
1255          text : str
1256              Full text of the current input, multi line string.
1257          offset : int
1258              Integer representing the position of the cursor in ``text``. Offset
1259              is 0-based indexed.
1260  
1261          Yields
1262          ------
1263          Completion
1264  
1265          Notes
1266          -----
1267          The cursor on a text can either be seen as being "in between"
1268          characters or "On" a character depending on the interface visible to
1269          the user. For consistency the cursor being on "in between" characters X
1270          and Y is equivalent to the cursor being "on" character Y, that is to say
1271          the character the cursor is on is considered as being after the cursor.
1272  
1273          Combining characters may span more that one position in the
1274          text.
1275  
1276          .. note::
1277  
1278              If ``IPCompleter.debug`` is :any:`True` will yield a ``--jedi/ipython--``
1279              fake Completion token to distinguish completion returned by Jedi
1280              and usual IPython completion.
1281  
1282          .. note::
1283  
1284              Completions are not completely deduplicated yet. If identical
1285              completions are coming from different sources this function does not
1286              ensure that each completion object will only be present once.
1287          zy_complete is a provisional API (as of IPython 6.0). It may change without warnings. Use in corresponding context manager.rSr�rNi�)�_timeoutzWriting profiler output to)rIr�r@ra�profile_completions�cProfileZProfile�enable�_completionsr{rr��disabler%�profiler_output_dirrlrfrdrO�uuid�uuid4rZ
1288  dump_stats)r�r�r�rr�Zprofilerr^Zoutput_pathr6r6r9r��sF�.�
1289  ���
1290  
1291  �
1292  
1293  �zIPCompleter.completionsr�c
1294  #sL�t��|}|d|�}t||�\}}t|j��d�fdd	��|j|||d
1295  �}�fdd�|��D�}	�|vr@tt|��d
1296  nd}
1297  t	|
1298  �}|r�|D]F}z|j
1299  }
1300  Wntyd|jr`t
1301  d|�d}
1302  Ynwt|j�t|j�}|
1303  dkrxt|�}nd}t||||j|
1304  |dd�Vt��|kr�nqJ|D]}t|j�t|j�}t||||jtddd�Vq�|
1305  r�|	r�|jr�|�tt	|	����d�}t||ddddd�Vg}g}|	��D];\}}|d}|�|�}|�dd�}|r�|n|}|�|�s�J�|d
1306  D]}t|||j|d|j
1307  �ptd�}|�|�q�q�t|�||�|���dt�EdHdS)ax
1308          Core completion module.Same signature as :any:`completions`, with the
1309          extra `timeout` parameter (in seconds).
1310  
1311          Computing jedi's completion ``.type`` can be quite expensive (it is a
1312          lazy property) and can require some warm-up, more warm up than just
1313          computing the ``name`` of a completion. The warm-up can be :
1314  
1315              - Long warm-up the first time a module is encountered after
1316              install/update: actually build parse/inference tree.
1317  
1318              - first time the module is encountered in a session: load tree from
1319              disk.
1320  
1321          We don't want to block completions for tens of seconds so we give the
1322          completer a "budget" of ``_timeout`` seconds per invocation to compute
1323          completions types, the completions that have not yet been computed will
1324          be marked as "unknown" an will have a chance to be computed next round
1325          are things get cached.
1326  
1327          Keep in mind that Jedi is not the only thing treating the completion so
1328          keep the timeout short-ish as if we take more than 0.3 second we still
1329          have lots of processing to do.
1330  
1331          Nr�r�r�rOrP�TypeGuard[SimpleMatcherResult]cs|�kSr�r6)r�r�)�jedi_matcher_idr6r9�is_non_jedi_result!sz4IPCompleter._completions.<locals>.is_non_jedi_result)r�r�rcs i|]\}}�||�r||�qSr6r6)r]r�r�)r�r6r9rB*s��z,IPCompleter._completions.<locals>.<dictcomp>r�r6zError in Jedi getting type of �functionrYrr�)r�r�r�r�r�r�r�z--jedi/ipython--rt�none)r�r�r�r�r�r�r�F)r�r�r�r�r�r�)r�r�r�rOrPr�)�time�	monotonicr�r�r�	_completer�r/r�r�r�rYrtrrkr�r�r�r�r�rdr��valuesr�r|r�rCr�_deduplicate�_sort�
1332  MATCHES_LIMIT)r�r�r�r��deadliner�r�rQr�Znon_jedi_resultsZjedi_matchesZiter_jmZjmr7�deltar�Zsome_start_offsetr��sortable�originr�Zmatched_text�start_offsetZ
1333  is_ordered�	containerZsimple_completionr�r6)r�r�r9r�s��
1334  �
1335  ���
1336  
1337  �
1338  ��
1339  ���	
1340  
1341  ���zIPCompleter._completionscCs:t�dt�|j|||dd�}t|j�}|j||hdd�S)a�Find completions for the given text and line context.
1342  
1343          Note that both the text and the line_buffer are optional, but at least
1344          one of them must be given.
1345  
1346          Parameters
1347          ----------
1348          text : string, optional
1349              Text to perform the completion on.  If not given, the line buffer
1350              is split using the instance's CompletionSplitter object.
1351          line_buffer : string, optional
1352              If not given, the completer attempts to obtain the current line
1353              buffer via readline.  This keyword allows clients which are
1354              requesting for text completions in non-readline contexts to inform
1355              the completer of the entire text.
1356          cursor_pos : int, optional
1357              Index of the cursor in the full line buffer.  Should be provided by
1358              remote frontends where kernel has no access to frontend state.
1359  
1360          Returns
1361          -------
1362          Tuple of two items:
1363          text : str
1364              Text that was actually used in the completion.
1365          matches : list
1366              A list of completion matches.
1367  
1368          Notes
1369          -----
1370              This API is likely to be deprecated and replaced by
1371              :any:`IPCompleter.completions` in the future.
1372  
1373          zn`Completer.complete` is pending deprecation since IPython 6.0 and will be replaced by `Completer.completions`.r)r�rr�r�T��
1374  skip_matchers�abort_if_offset_changes)rIr��PendingDeprecationWarningr�r�r�_arrange_and_extract)r�r�r�rr�r�r6r6r9r��s"��
1375  �zIPCompleter.completer��Dict[str, MatcherResult]r��Set[str]r�rsc	Cs�g}g}d}|��D]3\}}||vrq
1376  |dsq
1377  |s|d}|r(|d|kr(n|�dd�r6|�|d�q
1378  |�|d�q
1379  |sBd}|dd�|�||�|��D�fS)Nr�r�r�FrYcSsg|]}|j�qSr6r�r7r6r6r9r>�s�z4IPCompleter._arrange_and_extract.<locals>.<listcomp>)r�r�r�r�r�)	r�r�r�r�r�r�Zmost_recent_fragmentr�r�r6r6r9r��s,��z IPCompleter._arrange_and_extract)r�r�r��_CompleteResultc	Csj|dur|durt|�nt|�}|jrtj|_|s"|r"|�d�|}|s/|r-|j�||�nd}|dur5|}||_|jd|�|_	|sD|}t
1380  ||||td�}i}t|j
1381  �}t�}	dd�t|jtdd�D�}
1382  |
1383  ��D]�\}}t|�}||jvrvqh||vr�t�d	|�d
1384  ��||	vr�qhz#t|�r�t||�td�}
1385  nt|�r�||�}
1386  nt|�}td|����Wnty�tjt���Yqhw|
1387  � d
1388  |j!�|
1389  d
1390  <|	�s |
1391  � dd�}t"|j#t$�r�|j#� |d�n|j#}|dup�|o�|duo�t%|
1392  �}|�r |
1393  � dt��}t"|t&��rt|�}nt|
1394  �}||}	i}|��D]\}}||	v�r|||<�q|}|
1395  ||<qh|j'||hdd�\}}||_(|S)a�
1396          Like complete but can also returns raw jedi completions as well as the
1397          origin of the completion text. This could (and should) be made much
1398          cleaner but that will be simpler once we drop the old (and stateful)
1399          :any:`complete` API.
1400  
1401          With current provisional API, cursor_pos act both (depending on the
1402          caller) as the offset in the ``text`` or ``line_buffer``, or as the
1403          ``column`` when passing multiline strings this could/should be renamed
1404          but would add extra noise.
1405  
1406          Parameters
1407          ----------
1408          cursor_line
1409              Index of the line the cursor is on. 0 indexed.
1410          cursor_pos
1411              Position of the cursor in the current line/line_buffer/text. 0
1412              indexed.
1413          line_buffer : optional, str
1414              The current line the cursor is in, this is mostly due to legacy
1415              reason that readline could only give a us the single current line.
1416              Prefer `full_text`.
1417          text : str
1418              The current "token" the cursor is in, mostly also for historical
1419              reasons. as the completer would trigger only after the current line
1420              was parsed.
1421          full_text : str
1422              Full text of the current cell.
1423  
1424          Returns
1425          -------
1426          An ordered dictionary where keys are identifiers of completion
1427          matchers and values are ``MatcherResult``s.
1428          Nr�rY)r�r�r�r�r�cSsi|]}t|�|�qSr6)r�)r]r�r6r6r9rB,
1429  s��z)IPCompleter._complete.<locals>.<dictcomp>T)r��reversezDuplicate matcher ID: r4r�zUnsupported API version r�r�Fr�r�))rkr,r5r6r-r�r�rr�r�r�r�r�rrarHrr�r�r
1430  rIr�r�r�r�r�r�r��
1431  BaseExceptionrb�
1432  excepthook�exc_infor�r�rnrr�r�r
1433  r�r8)r�r�rr�r�r�r�r�r�Zsuppressed_matchersrZ
1434  matcher_idr�r�r�Zsuppression_recommendedZsuppression_configZshould_suppressZsuppression_exceptionsZto_suppressZnew_resultsZprevious_matcher_idZprevious_resultrxr8r6r6r9r��s�'��	
1435  ��
1436  �
1437  ���
1438  ��
1439  ���
1440  
1441  �
1442  
1443  �	zIPCompleter._completer8�Sequence[AnyCompletion]�Iterable[AnyCompletion]cCs:i}|D]}|j}||vs||jtkr|||<q|��Sr�)r�r�r�r�)r8Zfiltered_matchesr@r�r6r6r9r��
1444  s�zIPCompleter._deduplicatecCst|dd�d�S)NcSs
1445  t|j�Sr�)r~r�rAr6r6r9r��
1446  s
1447  z#IPCompleter._sort.<locals>.<lambda>rB)rH)r8r6r6r9r��
1448  r�zIPCompleter._sortcCr�)zASame as :any:`fwd_unicode_match`, but adopted to new Matcher API.r�Tr�)�fwd_unicode_matchr�r�r�r6r6r9r�
1449  r�zIPCompleter.fwd_unicode_matchercs�|�d�}|dkrL||dd�}|����fdd�|jD�}|r%||fS�fdd�|jD�}|r5||fS��d���fd	d�|jD�}|rJ||fSd
1450  Sd
1451  S)a�
1452          Forward match a string starting with a backslash with a list of
1453          potential Unicode completions.
1454  
1455          Will compute list of Unicode character names on first call and cache it.
1456  
1457          .. deprecated:: 8.6
1458              You can use :meth:`fwd_unicode_matcher` instead.
1459  
1460          Returns
1461          -------
1462          At tuple with:
1463              - matched text (empty if no matches)
1464              - list of potential completions, empty tuple  otherwise)
1465          r[rzriNcrCr6r3r.��supr6r9r>�
1466  rz1IPCompleter.fwd_unicode_match.<locals>.<listcomp>csg|]}�|vr|�qSr6r6r.r�r6r9r>�
1467  r�r?cs&g|]�t�fdd��D��r��qS)c3s�|]}|�vVqdSr�r6)r]�urAr6r9r`�
1468  rz;IPCompleter.fwd_unicode_match.<locals>.<listcomp>.<genexpr>)�all)r])�splitsuprAr9r>�
1469  s
1470  ��r�)rd�upper�
1471  unicode_namesr�)r�r�r�rN�
1472  candidatesr6)r�r�r9r��
1473  s$
1474   
1475  
1476  �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.
1477  
1478          The list is lazily initialized on first access.
1479          Nri)	r�rangerCr�r��chrr��_unicode_name_compute�_UNICODE_RANGES)r�r�r^r6r6r9r��
1480  s
1481  �
1482  zIPCompleter.unicode_names)NNNN)rPrr�)r�rO)r�r�rPr�)r�r�rPr�)rQr�r�r�r�rOrPr�)r�rOrPrx)r8rrPr��r�r�)r�rOrPr��r�rOrPr�)r�rOr�r�rPr�)r�rOr�r�rPr�)NNN)rPr�)r�r�r�r�r�rs)rPr�)r8r�rPr�)r8r�)rPr�)GrArBrCrDr+r�r'r�
1483  UnionTrait�	DictTraitrwrr�	ListTraitr*r
1484  r(rWrVr�r�r�r�r!rrrr��context_matcherrr"rr1rr>rrMrrRr�rarercrr�ryrr�rr��staticmethodr�rr�r
1485  r�r	r�rr�r�r�r�r�r�r�r�rr�r�r~r6r6r2r9r=�s�
1486  �	���
1487  ����
1488  �������
1489  �Z
1490  
1491  
1492  
1493  V
1494  	.
1495  '
1496  
1497  Tt"R
1498  u
1499  
1500  
1501  
1502  4
1503  N
1504  8!�%
1505  
1506  =�ranges�List[Tuple[int, int]]r�c
1507  CsPg}|D]!\}}t||�D]}z|�t�t|���Wq
1508  ty$Yq
1509  wq|Sr�)r�rCr�r�r�r�)r�r�r��stopr^r6r6r9r��
1510  s��r�)rH)rNrOrPrQ)rNrOrXrOrPrO)rfrOrPrg)rfrOrnrsrorOrPrO)r�r�rPr�)r�r�rPr�)r�rrPr�)r�rrPr�)r�r�rPrs)r�r�r�r�r�r�rPr�)r�r�)r�rOr�r�rPr�)r�rOr�r�r
1511  rsrPr�)r�rOrPr�r�)
1512  rGr�r�rOrrOr�r�rPr�)r�rOrr�r�r�rPr�)r�rOr�r�rPr�r�r�r�)NF)
1513  r8r�r�rOr�r�r�rsrPr�)r�r�rPr�)�rD�
1514  __future__r�builtinsrFr�r�r�r�rDrjrlrr`rbr\r�r�r�rIr�collectionsr�
1515  contextlibr�dataclassesr�	functoolsrr�typesr	�typingr
1516  rrr
1517  rrrrrrrrrrZIPython.core.guarded_evalrrZIPython.core.errorrZIPython.core.inputtransformer2rZIPython.core.latex_symbolsrrZIPython.core.oinspectrZIPython.testing.skipdoctestrZ
1518  IPython.utilsr ZIPython.utils.decoratorsr!ZIPython.utils.dir2r"r#ZIPython.utils.docsr$ZIPython.utils.pathr%ZIPython.utils.processr&Z	traitletsr'r(r)r�r*r�r�r+Ztraitlets.config.configurabler,r5Z__skip_doctest__r�settingsZcase_insensitive_completionZjedi.api.helpersZjedi.api.classesry�ImportError�version_infor/Ztyping_extensionsr0r1r2r3r4r5�objectr�rMrcZPROTECTABLESr�r�rU�
1519  FutureWarningr@rKrMrWrerrrvr~rZ_JediCompletionLiker�r�r�r�r�ZAnyMatcherCompletionr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r	rr r�rr<rW�Flagr�rZr��bin�oct�hexr�r�r�r�r�r�r�r�r�r�r�rOr�rr�r�r=r�r6r6r6r9�<module>sN4@(
1520  �	
1521  
1522  
1523  (	 J
1524  '	
1525  
1526  
1527  
1528  
1529  
1530  �
1531  (
1532  
1533  *;4%
1534  
1535  
1536  $��
1537  "
1538  "
1539  
1540  *
1541  
1542  
1543  �4�}