MCPcopy Index your code
hub / github.com/python/cpython / _parse_known_args

Method _parse_known_args

Lib/argparse.py:2135–2440  ·  view source on GitHub ↗
(self, arg_strings, namespace, intermixed)

Source from the content-addressed store, hash-verified

2133 return namespace, args
2134
2135 def _parse_known_args(self, arg_strings, namespace, intermixed):
2136 # replace arg strings that are file references
2137 if self.fromfile_prefix_chars is not None:
2138 arg_strings = self._read_args_from_files(arg_strings)
2139
2140 # map all mutually exclusive arguments to the other arguments
2141 # they can't occur with
2142 action_conflicts = {}
2143 for mutex_group in self._mutually_exclusive_groups:
2144 group_actions = mutex_group._group_actions
2145 for i, mutex_action in enumerate(mutex_group._group_actions):
2146 conflicts = action_conflicts.setdefault(mutex_action, [])
2147 conflicts.extend(group_actions[:i])
2148 conflicts.extend(group_actions[i + 1:])
2149
2150 # find all option indices, and determine the arg_string_pattern
2151 # which has an 'O' if there is an option at an index,
2152 # an 'A' if there is an argument, or a '-' if there is a '--'
2153 option_string_indices = {}
2154 arg_string_pattern_parts = []
2155 arg_strings_iter = iter(arg_strings)
2156 for i, arg_string in enumerate(arg_strings_iter):
2157
2158 # all args after -- are non-options
2159 if arg_string == '--':
2160 arg_string_pattern_parts.append('-')
2161 for arg_string in arg_strings_iter:
2162 arg_string_pattern_parts.append('A')
2163
2164 # otherwise, add the arg to the arg strings
2165 # and note the index if it was an option
2166 else:
2167 option_tuples = self._parse_optional(arg_string)
2168 if option_tuples is None:
2169 pattern = 'A'
2170 else:
2171 option_string_indices[i] = option_tuples
2172 pattern = 'O'
2173 arg_string_pattern_parts.append(pattern)
2174
2175 # join the pieces together to form the pattern
2176 arg_strings_pattern = ''.join(arg_string_pattern_parts)
2177
2178 # converts arg strings to the appropriate and then takes the action
2179 seen_actions = set()
2180 seen_non_default_actions = set()
2181 warned = set()
2182
2183 def take_action(action, argument_strings, option_string=None):
2184 seen_actions.add(action)
2185 argument_values = self._get_values(action, argument_strings)
2186
2187 # error if this argument is not allowed with other previously
2188 # seen arguments
2189 if action.option_strings or argument_strings:
2190 seen_non_default_actions.add(action)
2191 for conflict_action in action_conflicts.get(action, []):
2192 if conflict_action in seen_non_default_actions:

Callers 1

_parse_known_args2Method · 0.95

Calls 14

_read_args_from_filesMethod · 0.95
_parse_optionalMethod · 0.95
_get_valueMethod · 0.95
enumerateFunction · 0.85
setFunction · 0.85
_get_action_nameFunction · 0.85
ArgumentErrorClass · 0.70
_Function · 0.50
setdefaultMethod · 0.45
extendMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected