(self, arg_string)
| 2427 | return [] |
| 2428 | |
| 2429 | def _parse_optional(self, arg_string): |
| 2430 | # if it's an empty string, it was meant to be a positional |
| 2431 | if not arg_string: |
| 2432 | return None |
| 2433 | |
| 2434 | # if it doesn't start with a prefix, it was meant to be positional |
| 2435 | if not arg_string[0] in self.prefix_chars: |
| 2436 | return None |
| 2437 | |
| 2438 | # if the option string is present in the parser, return the action |
| 2439 | if arg_string in self._option_string_actions: |
| 2440 | action = self._option_string_actions[arg_string] |
| 2441 | return [(action, arg_string, None, None)] |
| 2442 | |
| 2443 | # if it's just a single character, it was meant to be positional |
| 2444 | if len(arg_string) == 1: |
| 2445 | return None |
| 2446 | |
| 2447 | # if the option string before the "=" is present, return the action |
| 2448 | option_string, sep, explicit_arg = arg_string.partition('=') |
| 2449 | if sep and option_string in self._option_string_actions: |
| 2450 | action = self._option_string_actions[option_string] |
| 2451 | return [(action, option_string, sep, explicit_arg)] |
| 2452 | |
| 2453 | # search through all possible prefixes of the option string |
| 2454 | # and all actions in the parser for possible interpretations |
| 2455 | option_tuples = self._get_option_tuples(arg_string) |
| 2456 | |
| 2457 | if option_tuples: |
| 2458 | return option_tuples |
| 2459 | |
| 2460 | # if it was not found as an option, but it looks like a negative |
| 2461 | # number, it was meant to be positional |
| 2462 | # unless there are negative-number-like options |
| 2463 | if self._negative_number_matcher.match(arg_string): |
| 2464 | if not self._has_negative_number_optionals: |
| 2465 | return None |
| 2466 | |
| 2467 | # if it contains a space, it was meant to be a positional |
| 2468 | if ' ' in arg_string: |
| 2469 | return None |
| 2470 | |
| 2471 | # it was meant to be an optional but there is no such option |
| 2472 | # in this parser (though it might be a valid option in a subparser) |
| 2473 | return [(None, arg_string, None, None)] |
| 2474 | |
| 2475 | def _get_option_tuples(self, option_string): |
| 2476 | result = [] |
no test coverage detected