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

Method add_option

Lib/optparse.py:985–1013  ·  view source on GitHub ↗

add_option(Option) add_option(opt_str, ..., kwarg=val, ...)

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

983 c_option.container.option_list.remove(c_option)
984
985 def add_option(self, *args, **kwargs):
986 """add_option(Option)
987 add_option(opt_str, ..., kwarg=val, ...)
988 """
989 if isinstance(args[0], str):
990 option = self.option_class(*args, **kwargs)
991 elif len(args) == 1 and not kwargs:
992 option = args[0]
993 if not isinstance(option, Option):
994 raise TypeError("not an Option instance: %r" % option)
995 else:
996 raise TypeError("invalid arguments")
997
998 self._check_conflict(option)
999
1000 self.option_list.append(option)
1001 option.container = self
1002 for opt in option._short_opts:
1003 self._short_opt[opt] = option
1004 for opt in option._long_opts:
1005 self._long_opt[opt] = option
1006
1007 if option.dest is not None: # option has a dest, we need a default
1008 if option.default is not NO_DEFAULT:
1009 self.defaults[option.dest] = option.default
1010 elif option.dest not in self.defaults:
1011 self.defaults[option.dest] = None
1012
1013 return option
1014
1015 def add_options(self, option_list):
1016 for option in option_list:

Callers 4

add_optionsMethod · 0.95
mainFunction · 0.45
_add_help_optionMethod · 0.45
_add_version_optionMethod · 0.45

Calls 2

_check_conflictMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected