MCPcopy
hub / github.com/google/python-fire / _get_or_create_arg_by_name

Function _get_or_create_arg_by_name

fire/docstrings.py:274–299  ·  view source on GitHub ↗

Gets or creates a new Arg. These Arg objects (Namespaces) are turned into the ArgInfo namedtuples returned by parse. Each Arg object is used to collect the name, type, and description of a single argument to the docstring's function. Args: state: The state of the parser. name: The

(state, name, is_kwarg=False)

Source from the content-addressed store, hash-verified

272
273
274def _get_or_create_arg_by_name(state, name, is_kwarg=False):
275 """Gets or creates a new Arg.
276
277 These Arg objects (Namespaces) are turned into the ArgInfo namedtuples
278 returned by parse. Each Arg object is used to collect the name, type, and
279 description of a single argument to the docstring's function.
280
281 Args:
282 state: The state of the parser.
283 name: The name of the arg to create.
284 is_kwarg: A boolean representing whether the argument is a keyword arg.
285 Returns:
286 The new Arg.
287 """
288 for arg in state.args + state.kwargs:
289 if arg.name == name:
290 return arg
291 arg = Namespace() # TODO(dbieber): Switch to an explicit class.
292 arg.name = name
293 arg.type.lines = []
294 arg.description.lines = []
295 if is_kwarg:
296 state.kwargs.append(arg)
297 else:
298 state.args.append(arg)
299 return arg
300
301
302def _is_arg_name(name):

Callers 2

_consume_lineFunction · 0.85

Calls 1

NamespaceClass · 0.85

Tested by

no test coverage detected