MCPcopy Create free account
hub / github.com/PyTables/PyTables / _g_refnode

Method _g_refnode

tables/group.py:520–581  ·  view source on GitHub ↗

Insert references to a `childnode` via a `childname`. Checks that the `childname` is valid and does not exist, then creates references to the given `childnode` by that `childname`. The validation of the name can be omitted by setting `validate` to a false value (this

(
        self, childnode: Node, childname: str, validate: bool = True
    )

Source from the content-addressed store, hash-verified

518 )
519
520 def _g_refnode(
521 self, childnode: Node, childname: str, validate: bool = True
522 ) -> None:
523 """Insert references to a `childnode` via a `childname`.
524
525 Checks that the `childname` is valid and does not exist, then
526 creates references to the given `childnode` by that `childname`.
527 The validation of the name can be omitted by setting `validate`
528 to a false value (this may be useful for adding already existing
529 nodes to the tree).
530
531 """
532 # Check for name validity.
533 if validate:
534 check_name_validity(childname)
535 childnode._g_check_name(childname)
536
537 # Check if there is already a child with the same name.
538 # This can be triggered because of the user
539 # (via node construction or renaming/movement).
540 # Links are not checked here because they are copied and referenced
541 # using ``File.get_node`` so they already exist in `self`.
542 if (not isinstance(childnode, Link)) and childname in self:
543 raise NodeError(
544 "group ``%s`` already has a child node named ``%s``"
545 % (self._v_pathname, childname)
546 )
547
548 # Show a warning if there is an object attribute with that name.
549 if childname in self.__dict__:
550 warnings.warn(
551 f"group ``{self._v_pathname}`` already has an attribute "
552 f"named ``{childname}``; you will not be able to use "
553 f"natural naming to access the child node",
554 NaturalNameWarning,
555 )
556
557 # Check group width limits.
558 if (
559 len(self._v_children) + len(self._v_hidden)
560 >= self._v_max_group_width
561 ):
562 self._g_width_warning()
563
564 # Update members information.
565 # Insert references to the new child.
566 # (Assigned values are entirely irrelevant.)
567 if isvisiblename(childname):
568 # Visible node.
569 self.__members__.insert(0, childname) # enable completion
570 self._v_children[childname] = None # insert node
571 if isinstance(childnode, Unknown):
572 self._v_unknown[childname] = None
573 elif isinstance(childnode, Link):
574 self._v_links[childname] = None
575 elif isinstance(childnode, Leaf):
576 self._v_leaves[childname] = None
577 elif isinstance(childnode, Group):

Callers 3

__init__Method · 0.80
_g_moveMethod · 0.80
copyMethod · 0.80

Calls 5

_g_width_warningMethod · 0.95
check_name_validityFunction · 0.85
NodeErrorClass · 0.85
isvisiblenameFunction · 0.85
_g_check_nameMethod · 0.45

Tested by

no test coverage detected