##// END OF EJS Templates
Merge pull request #12435 from Carreau/velin-III
Matthias Bussonnier -
r25892:c0c9835c merge
parent child Browse files
Show More
@@ -193,8 +193,6 b" warnings.filterwarnings('error', category=ProvisionalCompleterWarning)"
193 @contextmanager
193 @contextmanager
194 def provisionalcompleter(action='ignore'):
194 def provisionalcompleter(action='ignore'):
195 """
195 """
196
197
198 This context manager has to be used in any place where unstable completer
196 This context manager has to be used in any place where unstable completer
199 behavior and API may be called.
197 behavior and API may be called.
200
198
@@ -262,17 +260,17 b' def expand_user(path:str) -> Tuple[str, bool, str]:'
262 Parameters
260 Parameters
263 ----------
261 ----------
264 path : str
262 path : str
265 String to be expanded. If no ~ is present, the output is the same as the
263 String to be expanded. If no ~ is present, the output is the same as the
266 input.
264 input.
267
265
268 Returns
266 Returns
269 -------
267 -------
270 newpath : str
268 newpath : str
271 Result of ~ expansion in the input path.
269 Result of ~ expansion in the input path.
272 tilde_expand : bool
270 tilde_expand : bool
273 Whether any expansion was performed or not.
271 Whether any expansion was performed or not.
274 tilde_val : str
272 tilde_val : str
275 The value that ~ was replaced with.
273 The value that ~ was replaced with.
276 """
274 """
277 # Default values
275 # Default values
278 tilde_expand = False
276 tilde_expand = False
@@ -435,12 +433,9 b' def _deduplicate_completions(text: str, completions: _IC)-> _IC:'
435 Yields
433 Yields
436 ------
434 ------
437 `Completions` objects
435 `Completions` objects
438
439
440 Completions coming from multiple sources, may be different but end up having
436 Completions coming from multiple sources, may be different but end up having
441 the same effect when applied to ``text``. If this is the case, this will
437 the same effect when applied to ``text``. If this is the case, this will
442 consider completions as equal and only emit the first encountered.
438 consider completions as equal and only emit the first encountered.
443
444 Not folded in `completions()` yet for debugging purpose, and to detect when
439 Not folded in `completions()` yet for debugging purpose, and to detect when
445 the IPython completer does return things that Jedi does not, but should be
440 the IPython completer does return things that Jedi does not, but should be
446 at some point.
441 at some point.
@@ -476,7 +471,8 b' def rectify_completions(text: str, completions: _IC, *, _debug=False)->_IC:'
476 completions: Iterator[Completion]
471 completions: Iterator[Completion]
477 iterator over the completions to rectify
472 iterator over the completions to rectify
478
473
479
474 Notes
475 -----
480 :any:`jedi.api.classes.Completion` s returned by Jedi may not have the same start and end, though
476 :any:`jedi.api.classes.Completion` s returned by Jedi may not have the same start and end, though
481 the Jupyter Protocol requires them to behave like so. This will readjust
477 the Jupyter Protocol requires them to behave like so. This will readjust
482 the completion to have the same ``start`` and ``end`` by padding both
478 the completion to have the same ``start`` and ``end`` by padding both
@@ -758,7 +754,7 b' def match_dict_keys(keys: List[Union[str, bytes, Tuple[Union[str, bytes]]]], pre'
758 """Used by dict_key_matches, matching the prefix to a list of keys
754 """Used by dict_key_matches, matching the prefix to a list of keys
759
755
760 Parameters
756 Parameters
761 ==========
757 ----------
762 keys:
758 keys:
763 list of keys in dictionary currently being completed.
759 list of keys in dictionary currently being completed.
764 prefix:
760 prefix:
@@ -766,12 +762,11 b' def match_dict_keys(keys: List[Union[str, bytes, Tuple[Union[str, bytes]]]], pre'
766 delims:
762 delims:
767 String of delimiters to consider when finding the current key.
763 String of delimiters to consider when finding the current key.
768 extra_prefix: optional
764 extra_prefix: optional
769 Part of the text already typed in multi-key index cases. E.g. for
765 Part of the text already typed in multi-key index cases. E.g. for
770 `mydict['foo', "bar", 'b`, this would be `('foo', 'bar')`.
766 `mydict['foo', "bar", 'b`, this would be `('foo', 'bar')`.
771
767
772 Returns
768 Returns
773 =======
769 -------
774
775 A tuple of three elements: ``quote``, ``token_start``, ``matched``, with
770 A tuple of three elements: ``quote``, ``token_start``, ``matched``, with
776 ``quote`` being the quote that need to be used to close current string.
771 ``quote`` being the quote that need to be used to close current string.
777 ``token_start`` the position where the replacement should start occurring,
772 ``token_start`` the position where the replacement should start occurring,
@@ -850,13 +845,11 b' def match_dict_keys(keys: List[Union[str, bytes, Tuple[Union[str, bytes]]]], pre'
850
845
851 def cursor_to_position(text:str, line:int, column:int)->int:
846 def cursor_to_position(text:str, line:int, column:int)->int:
852 """
847 """
853
854 Convert the (line,column) position of the cursor in text to an offset in a
848 Convert the (line,column) position of the cursor in text to an offset in a
855 string.
849 string.
856
850
857 Parameters
851 Parameters
858 ----------
852 ----------
859
860 text : str
853 text : str
861 The text in which to calculate the cursor offset
854 The text in which to calculate the cursor offset
862 line : int
855 line : int
@@ -864,13 +857,13 b' def cursor_to_position(text:str, line:int, column:int)->int:'
864 column : int
857 column : int
865 Column of the cursor 0-indexed
858 Column of the cursor 0-indexed
866
859
867 Return
860 Returns
868 ------
861 -------
869 Position of the cursor in ``text``, 0-indexed.
862 Position of the cursor in ``text``, 0-indexed.
870
863
871 See Also
864 See Also
872 --------
865 --------
873 position_to_cursor: reciprocal of this function
866 position_to_cursor : reciprocal of this function
874
867
875 """
868 """
876 lines = text.split('\n')
869 lines = text.split('\n')
@@ -887,23 +880,20 b' def position_to_cursor(text:str, offset:int)->Tuple[int, int]:'
887
880
888 Parameters
881 Parameters
889 ----------
882 ----------
890
891 text : str
883 text : str
892 The text in which to calculate the cursor offset
884 The text in which to calculate the cursor offset
893 offset : int
885 offset : int
894 Position of the cursor in ``text``, 0-indexed.
886 Position of the cursor in ``text``, 0-indexed.
895
887
896 Return
888 Returns
897 ------
889 -------
898 (line, column) : (int, int)
890 (line, column) : (int, int)
899 Line of the cursor; 0-indexed, column of the cursor 0-indexed
891 Line of the cursor; 0-indexed, column of the cursor 0-indexed
900
892
901
902 See Also
893 See Also
903 --------
894 --------
904 cursor_to_position : reciprocal of this function
895 cursor_to_position : reciprocal of this function
905
896
906
907 """
897 """
908
898
909 assert 0 <= offset <= len(text) , "0 <= %s <= %s" % (offset , len(text))
899 assert 0 <= offset <= len(text) , "0 <= %s <= %s" % (offset , len(text))
@@ -993,18 +983,15 b' def _formatparamchildren(parameter) -> str:'
993
983
994 Jedi does not expose a simple way to get `param=value` from its API.
984 Jedi does not expose a simple way to get `param=value` from its API.
995
985
996 Parameter
986 Parameters
997 =========
987 ----------
998
999 parameter:
988 parameter:
1000 Jedi's function `Param`
989 Jedi's function `Param`
1001
990
1002 Returns
991 Returns
1003 =======
992 -------
1004
1005 A string like 'a', 'b=1', '*args', '**kwargs'
993 A string like 'a', 'b=1', '*args', '**kwargs'
1006
994
1007
1008 """
995 """
1009 description = parameter.description
996 description = parameter.description
1010 if not description.startswith('param '):
997 if not description.startswith('param '):
@@ -1016,15 +1003,13 b' def _make_signature(completion)-> str:'
1016 """
1003 """
1017 Make the signature from a jedi completion
1004 Make the signature from a jedi completion
1018
1005
1019 Parameter
1006 Parameters
1020 =========
1007 ----------
1021
1022 completion: jedi.Completion
1008 completion: jedi.Completion
1023 object does not complete a function type
1009 object does not complete a function type
1024
1010
1025 Returns
1011 Returns
1026 =======
1012 -------
1027
1028 a string consisting of the function signature, with the parenthesis but
1013 a string consisting of the function signature, with the parenthesis but
1029 without the function name. example:
1014 without the function name. example:
1030 `(a, *args, b=1, **kwargs)`
1015 `(a, *args, b=1, **kwargs)`
@@ -1125,20 +1110,16 b' class IPCompleter(Completer):'
1125
1110
1126 Parameters
1111 Parameters
1127 ----------
1112 ----------
1128
1129 shell
1113 shell
1130 a pointer to the ipython shell itself. This is needed
1114 a pointer to the ipython shell itself. This is needed
1131 because this completer knows about magic functions, and those can
1115 because this completer knows about magic functions, and those can
1132 only be accessed via the ipython instance.
1116 only be accessed via the ipython instance.
1133
1134 namespace : dict, optional
1117 namespace : dict, optional
1135 an optional dict where completions are performed.
1118 an optional dict where completions are performed.
1136
1137 global_namespace : dict, optional
1119 global_namespace : dict, optional
1138 secondary optional dict for completions, to
1120 secondary optional dict for completions, to
1139 handle cases (such as IPython embedded inside functions) where
1121 handle cases (such as IPython embedded inside functions) where
1140 both Python scopes are visible.
1122 both Python scopes are visible.
1141
1142 use_readline : bool, optional
1123 use_readline : bool, optional
1143 DEPRECATED, ignored since IPython 6.0, will have no effects
1124 DEPRECATED, ignored since IPython 6.0, will have no effects
1144 """
1125 """
@@ -1409,7 +1390,6 b' class IPCompleter(Completer):'
1409
1390
1410 def _jedi_matches(self, cursor_column:int, cursor_line:int, text:str) -> Iterable[Any]:
1391 def _jedi_matches(self, cursor_column:int, cursor_line:int, text:str) -> Iterable[Any]:
1411 """
1392 """
1412
1413 Return a list of :any:`jedi.api.Completions` object from a ``text`` and
1393 Return a list of :any:`jedi.api.Completions` object from a ``text`` and
1414 cursor position.
1394 cursor position.
1415
1395
@@ -1422,9 +1402,8 b' class IPCompleter(Completer):'
1422 text : str
1402 text : str
1423 text to complete
1403 text to complete
1424
1404
1425 Debugging
1405 Notes
1426 ---------
1406 -----
1427
1428 If ``IPCompleter.debug`` is ``True`` may return a :any:`_FakeJediCompletion`
1407 If ``IPCompleter.debug`` is ``True`` may return a :any:`_FakeJediCompletion`
1429 object containing a string with the Jedi debug information attached.
1408 object containing a string with the Jedi debug information attached.
1430 """
1409 """
@@ -1865,7 +1844,6 b' class IPCompleter(Completer):'
1865
1844
1866 Parameters
1845 Parameters
1867 ----------
1846 ----------
1868
1869 text:str
1847 text:str
1870 Full text of the current input, multi line string.
1848 Full text of the current input, multi line string.
1871 offset:int
1849 offset:int
@@ -1874,9 +1852,10 b' class IPCompleter(Completer):'
1874
1852
1875 Yields
1853 Yields
1876 ------
1854 ------
1877 :any:`Completion` object
1855 Completion
1878
1879
1856
1857 Notes
1858 -----
1880 The cursor on a text can either be seen as being "in between"
1859 The cursor on a text can either be seen as being "in between"
1881 characters or "On" a character depending on the interface visible to
1860 characters or "On" a character depending on the interface visible to
1882 the user. For consistency the cursor being on "in between" characters X
1861 the user. For consistency the cursor being on "in between" characters X
@@ -1886,7 +1865,6 b' class IPCompleter(Completer):'
1886 Combining characters may span more that one position in the
1865 Combining characters may span more that one position in the
1887 text.
1866 text.
1888
1867
1889
1890 .. note::
1868 .. note::
1891
1869
1892 If ``IPCompleter.debug`` is :any:`True` will yield a ``--jedi/ipython--``
1870 If ``IPCompleter.debug`` is :any:`True` will yield a ``--jedi/ipython--``
@@ -1936,7 +1914,6 b' class IPCompleter(Completer):'
1936 Core completion module.Same signature as :any:`completions`, with the
1914 Core completion module.Same signature as :any:`completions`, with the
1937 extra `timeout` parameter (in seconds).
1915 extra `timeout` parameter (in seconds).
1938
1916
1939
1940 Computing jedi's completion ``.type`` can be quite expensive (it is a
1917 Computing jedi's completion ``.type`` can be quite expensive (it is a
1941 lazy property) and can require some warm-up, more warm up than just
1918 lazy property) and can require some warm-up, more warm up than just
1942 computing the ``name`` of a completion. The warm-up can be :
1919 computing the ``name`` of a completion. The warm-up can be :
@@ -2024,17 +2001,15 b' class IPCompleter(Completer):'
2024
2001
2025 Parameters
2002 Parameters
2026 ----------
2003 ----------
2027 text : string, optional
2004 text : string, optional
2028 Text to perform the completion on. If not given, the line buffer
2005 Text to perform the completion on. If not given, the line buffer
2029 is split using the instance's CompletionSplitter object.
2006 is split using the instance's CompletionSplitter object.
2030
2007 line_buffer : string, optional
2031 line_buffer : string, optional
2032 If not given, the completer attempts to obtain the current line
2008 If not given, the completer attempts to obtain the current line
2033 buffer via readline. This keyword allows clients which are
2009 buffer via readline. This keyword allows clients which are
2034 requesting for text completions in non-readline contexts to inform
2010 requesting for text completions in non-readline contexts to inform
2035 the completer of the entire text.
2011 the completer of the entire text.
2036
2012 cursor_pos : int, optional
2037 cursor_pos : int, optional
2038 Index of the cursor in the full line buffer. Should be provided by
2013 Index of the cursor in the full line buffer. Should be provided by
2039 remote frontends where kernel has no access to frontend state.
2014 remote frontends where kernel has no access to frontend state.
2040
2015
@@ -2042,17 +2017,15 b' class IPCompleter(Completer):'
2042 -------
2017 -------
2043 Tuple of two items:
2018 Tuple of two items:
2044 text : str
2019 text : str
2045 Text that was actually used in the completion.
2020 Text that was actually used in the completion.
2046 matches : list
2021 matches : list
2047 A list of completion matches.
2022 A list of completion matches.
2048
2049
2050 .. note::
2051
2023
2024 Notes
2025 -----
2052 This API is likely to be deprecated and replaced by
2026 This API is likely to be deprecated and replaced by
2053 :any:`IPCompleter.completions` in the future.
2027 :any:`IPCompleter.completions` in the future.
2054
2028
2055
2056 """
2029 """
2057 warnings.warn('`Completer.complete` is pending deprecation since '
2030 warnings.warn('`Completer.complete` is pending deprecation since '
2058 'IPython 6.0 and will be replaced by `Completer.completions`.',
2031 'IPython 6.0 and will be replaced by `Completer.completions`.',
@@ -2064,23 +2037,19 b' class IPCompleter(Completer):'
2064 def _complete(self, *, cursor_line, cursor_pos, line_buffer=None, text=None,
2037 def _complete(self, *, cursor_line, cursor_pos, line_buffer=None, text=None,
2065 full_text=None) -> _CompleteResult:
2038 full_text=None) -> _CompleteResult:
2066 """
2039 """
2067
2068 Like complete but can also returns raw jedi completions as well as the
2040 Like complete but can also returns raw jedi completions as well as the
2069 origin of the completion text. This could (and should) be made much
2041 origin of the completion text. This could (and should) be made much
2070 cleaner but that will be simpler once we drop the old (and stateful)
2042 cleaner but that will be simpler once we drop the old (and stateful)
2071 :any:`complete` API.
2043 :any:`complete` API.
2072
2044
2073
2074 With current provisional API, cursor_pos act both (depending on the
2045 With current provisional API, cursor_pos act both (depending on the
2075 caller) as the offset in the ``text`` or ``line_buffer``, or as the
2046 caller) as the offset in the ``text`` or ``line_buffer``, or as the
2076 ``column`` when passing multiline strings this could/should be renamed
2047 ``column`` when passing multiline strings this could/should be renamed
2077 but would add extra noise.
2048 but would add extra noise.
2078
2049
2079 Return
2050 Returns
2080 ======
2051 -------
2081
2082 A tuple of N elements which are (likely):
2052 A tuple of N elements which are (likely):
2083
2084 matched_text: ? the text that the complete matched
2053 matched_text: ? the text that the complete matched
2085 matches: list of completions ?
2054 matches: list of completions ?
2086 matches_origin: ? list same lenght as matches, and where each completion came from
2055 matches_origin: ? list same lenght as matches, and where each completion came from
@@ -2186,15 +2155,13 b' class IPCompleter(Completer):'
2186
2155
2187 def fwd_unicode_match(self, text:str) -> Tuple[str, Sequence[str]]:
2156 def fwd_unicode_match(self, text:str) -> Tuple[str, Sequence[str]]:
2188 """
2157 """
2189
2190 Forward match a string starting with a backslash with a list of
2158 Forward match a string starting with a backslash with a list of
2191 potential Unicode completions.
2159 potential Unicode completions.
2192
2160
2193 Will compute list list of Unicode character names on first call and cache it.
2161 Will compute list list of Unicode character names on first call and cache it.
2194
2162
2195 Return
2163 Returns
2196 ======
2164 -------
2197
2198 At tuple with:
2165 At tuple with:
2199 - matched text (empty if no matches)
2166 - matched text (empty if no matches)
2200 - list of potential completions, empty tuple otherwise)
2167 - list of potential completions, empty tuple otherwise)
General Comments 0
You need to be logged in to leave comments. Login now