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

Method __setattr__

tables/attributeset.py:490–533  ·  view source on GitHub ↗

Set a PyTables attribute. Sets a (maybe new) PyTables attribute with the specified `name` and `value`. If the attribute already exists, it is simply replaced. A ``ValueError`` is raised when the name starts with a reserved prefix or contains a ``/``. A `Na

(self, name: str, value: Any)

Source from the content-addressed store, hash-verified

488 attrnamesuser.sort()
489
490 def __setattr__(self, name: str, value: Any) -> None:
491 """Set a PyTables attribute.
492
493 Sets a (maybe new) PyTables attribute with the specified `name`
494 and `value`. If the attribute already exists, it is simply
495 replaced.
496
497 A ``ValueError`` is raised when the name starts with a reserved
498 prefix or contains a ``/``. A `NaturalNameWarning` is issued if
499 the name is not a valid Python identifier. A
500 `PerformanceWarning` is issued when the recommended maximum
501 number of attributes in a node is going to be exceeded.
502
503 """
504 nodefile = self._v__nodefile
505 attrnames = self._v_attrnames
506
507 # Check for name validity
508 check_attribute_name(name)
509
510 nodefile._check_writable()
511
512 # Check if there are too many attributes.
513 max_node_attrs = nodefile.params["MAX_NODE_ATTRS"]
514 if len(attrnames) >= max_node_attrs:
515 warnings.warn(
516 """\
517node ``%s`` is exceeding the recommended maximum number of attributes (%d);\
518be ready to see PyTables asking for *lots* of memory and possibly slow I/O"""
519 % (self._v__nodepath, max_node_attrs),
520 PerformanceWarning,
521 )
522
523 undo_enabled = nodefile.is_undo_enabled()
524 # Log old attribute removal (if any).
525 if undo_enabled and (name in attrnames):
526 self._g_del_and_log(name)
527
528 # Set the attribute.
529 self._g__setattr(name, value)
530
531 # Log new attribute addition.
532 if undo_enabled:
533 self._g_log_add(name)
534
535 def _g_log_add(self, name: str) -> None:
536 self._v__nodefile._log("ADDATTR", self._v__nodepath, name)

Callers 1

__setitem__Method · 0.95

Calls 6

_g_del_and_logMethod · 0.95
_g__setattrMethod · 0.95
_g_log_addMethod · 0.95
check_attribute_nameFunction · 0.85
_check_writableMethod · 0.80
is_undo_enabledMethod · 0.80

Tested by

no test coverage detected