MCPcopy Index your code
hub / github.com/ipython/ipython / python_func_kw_matches

Method python_func_kw_matches

IPython/core/completer.py:2907–2987  ·  view source on GitHub ↗

Match named parameters (kwargs) of the last open function. .. deprecated:: 8.6 You can use :meth:`python_func_kw_matcher` instead.

(self, text)

Source from the content-addressed store, hash-verified

2905 return _convert_matcher_v1_result_to_v2_no_no(matches, type="param")
2906
2907 def python_func_kw_matches(self, text):
2908 """Match named parameters (kwargs) of the last open function.
2909
2910 .. deprecated:: 8.6
2911 You can use :meth:`python_func_kw_matcher` instead.
2912 """
2913
2914 if "." in text: # a parameter cannot be dotted
2915 return []
2916 try: regexp = self.__funcParamsRegex
2917 except AttributeError:
2918 regexp = self.__funcParamsRegex = re.compile(r'''
2919 '.*?(?<!\\)' | # single quoted strings or
2920 ".*?(?<!\\)" | # double quoted strings or
2921 \w+ | # identifier
2922 \S # other characters
2923 ''&#x27;, re.VERBOSE | re.DOTALL)
2924 # 1. find the nearest identifier that comes before an unclosed
2925 # parenthesis before the cursor
2926 # e.g. for "foo (1+bar(x), pa<cursor>,a=1)", the candidate is "foo"
2927 tokens = regexp.findall(self.text_until_cursor)
2928 iterTokens = reversed(tokens)
2929 openPar = 0
2930
2931 for token in iterTokens:
2932 if token == ')':
2933 openPar -= 1
2934 elif token == '(':
2935 openPar += 1
2936 if openPar > 0:
2937 # found the last unclosed parenthesis
2938 break
2939 else:
2940 return []
2941 # 2. Concatenate dotted names ("foo.bar" for "foo.bar(x, pa" )
2942 ids = []
2943 isId = re.compile(r'\w+$').match
2944
2945 while True:
2946 try:
2947 ids.append(next(iterTokens))
2948 if not isId(ids[-1]):
2949 ids.pop()
2950 break
2951 if not next(iterTokens) == '.':
2952 break
2953 except StopIteration:
2954 break
2955
2956 # Find all named arguments already assigned to, as to avoid suggesting
2957 # them again
2958 usedNamedArgs = set()
2959 par_level = -1
2960 for token, next_token in zip(tokens, tokens[1:]):
2961 if token == '(':
2962 par_level += 1
2963 elif token == ')':
2964 par_level -= 1

Callers 1

Calls 3

_default_argumentsMethod · 0.95
popMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected