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

Method __call__

Lib/test/test_argparse.py:2262–2280  ·  view source on GitHub ↗
(self, parser, namespace, value, option_string=None)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

ArgumentParserErrorClass · 0.85
NSClass · 0.70

Tested by

no test coverage detected