MCPcopy Index your code
hub / github.com/RustPython/RustPython / key_value_rule

Function key_value_rule

Lib/tomllib/_parser.py:400–431  ·  view source on GitHub ↗
(
    src: str, pos: Pos, out: Output, header: Key, parse_float: ParseFloat
)

Source from the content-addressed store, hash-verified

398
399
400def key_value_rule(
401 src: str, pos: Pos, out: Output, header: Key, parse_float: ParseFloat
402) -> Pos:
403 pos, key, value = parse_key_value_pair(src, pos, parse_float)
404 key_parent, key_stem = key[:-1], key[-1]
405 abs_key_parent = header + key_parent
406
407 relative_path_cont_keys = (header + key[:i] for i in range(1, len(key)))
408 for cont_key in relative_path_cont_keys:
409 # Check that dotted key syntax does not redefine an existing table
410 if out.flags.is_(cont_key, Flags.EXPLICIT_NEST):
411 raise TOMLDecodeError(f"Cannot redefine namespace {cont_key}", src, pos)
412 # Containers in the relative path can't be opened with the table syntax or
413 # dotted key/value syntax in following table sections.
414 out.flags.add_pending(cont_key, Flags.EXPLICIT_NEST)
415
416 if out.flags.is_(abs_key_parent, Flags.FROZEN):
417 raise TOMLDecodeError(
418 f"Cannot mutate immutable namespace {abs_key_parent}", src, pos
419 )
420
421 try:
422 nest = out.data.get_or_create_nest(abs_key_parent)
423 except KeyError:
424 raise TOMLDecodeError("Cannot overwrite a value", src, pos) from None
425 if key_stem in nest:
426 raise TOMLDecodeError("Cannot overwrite a value", src, pos)
427 # Mark inline table and array namespaces recursively immutable
428 if isinstance(value, (dict, list)):
429 out.flags.set(header + key, Flags.FROZEN, recursive=True)
430 nest[key_stem] = value
431 return pos
432
433
434def parse_key_value_pair(

Callers 1

loadsFunction · 0.85

Calls 8

parse_key_value_pairFunction · 0.85
lenFunction · 0.85
TOMLDecodeErrorClass · 0.85
isinstanceFunction · 0.85
is_Method · 0.80
add_pendingMethod · 0.80
get_or_create_nestMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected