(self, parser, namespace, value, option_string=None)
| 2282 | class PositionalAction(argparse.Action): |
| 2283 | |
| 2284 | def __call__(self, parser, namespace, value, option_string=None): |
| 2285 | try: |
| 2286 | assert option_string is None, ('option_string: %s' % |
| 2287 | option_string) |
| 2288 | # check destination |
| 2289 | assert self.dest == 'badger', 'dest: %s' % self.dest |
| 2290 | # when argument is before option, spam=0.25, and when |
| 2291 | # option is after argument, spam=<whatever was set> |
| 2292 | expected_ns = NS(badger=2) |
| 2293 | if value in [42, 84]: |
| 2294 | expected_ns.spam = 0.25 |
| 2295 | elif value in [1]: |
| 2296 | expected_ns.spam = 0.625 |
| 2297 | elif value in [2]: |
| 2298 | expected_ns.spam = 0.125 |
| 2299 | else: |
| 2300 | raise AssertionError('value: %s' % value) |
| 2301 | assert expected_ns == namespace, ('expected %s, got %s' % |
| 2302 | (expected_ns, namespace)) |
| 2303 | except AssertionError as e: |
| 2304 | raise ArgumentParserError('arg_action failed: %s' % e) |
| 2305 | setattr(namespace, 'badger', value) |
| 2306 | |
| 2307 | argument_signatures = [ |
| 2308 | Sig('-s', dest='spam', action=OptionalAction, |
nothing calls this directly
no test coverage detected