aiida_vasp.utils.inheritance#
Inheritance tools.
This sets up inheritance of the docstrings for use when we inherit classes. This makes it simple to add further details to or replace the docstring present on the base class.
Module Contents#
Functions#
Update docstring of (an inherited) class method. |
Data#
API#
- aiida_vasp.utils.inheritance.ClassType = 'TypeVar(...)'#
- aiida_vasp.utils.inheritance.update_docstring(method_name: str, content: str, append: bool = True) Callable[[type[aiida_vasp.utils.inheritance.ClassType]], type[aiida_vasp.utils.inheritance.ClassType]][source]#
Update docstring of (an inherited) class method.
For subclasses that use hooks to change behavior of superclass methods.
- Parameters:
method_name – Name of the method to update
content – Content to add or replace
append – If true, append to the docstring, else overwrite it entirely.
Example:
class Base(object): def method(self, **kwargs): '''Print the base_arg kwarg.''' print kwargs.pop('base_arg') self.process_additional(**kwargs) def process_additional(self, **kwargs): pass @update_docstring('method', '\n\nAlso print the sub_arg kwarg.', append=True) class Subclass(Base): def process_additional(self, **kwargs): print kwargs['sub_arg'] @update_docstring('method', 'Print all kwargs.', append=False) class Allprinter(Base): def process_additional(self, **kwargs): for _, value in kwargs.items(): print value