(self, parser, namespace, value, option_string=None)
| 2260 | class OptionalAction(argparse.Action): |
| 2261 | |
| 2262 | def __call__(self, parser, namespace, value, option_string=None): |
| 2263 | try: |
| 2264 | # check destination and option string |
| 2265 | assert self.dest == 'spam', 'dest: %s' % self.dest |
| 2266 | assert option_string == '-s', 'flag: %s' % option_string |
| 2267 | # when option is before argument, badger=2, and when |
| 2268 | # option is after argument, badger=<whatever was set> |
| 2269 | expected_ns = NS(spam=0.25) |
| 2270 | if value in [0.125, 0.625]: |
| 2271 | expected_ns.badger = 2 |
| 2272 | elif value in [2.0]: |
| 2273 | expected_ns.badger = 84 |
| 2274 | else: |
| 2275 | raise AssertionError('value: %s' % value) |
| 2276 | assert expected_ns == namespace, ('expected %s, got %s' % |
| 2277 | (expected_ns, namespace)) |
| 2278 | except AssertionError as e: |
| 2279 | raise ArgumentParserError('opt_action failed: %s' % e) |
| 2280 | setattr(namespace, 'spam', value) |
| 2281 | |
| 2282 | class PositionalAction(argparse.Action): |
| 2283 |
nothing calls this directly
no test coverage detected