stairval.notepad package
The module includes the Notepad
API
and the default implementation backed by a tree (not public).
Example
Create a new notepad with a top-level label order:
>>> from stairval.notepad import Notepad, create_notepad
>>> notepad = create_notepad('order')
>>> notepad.label
'order'
- class stairval.notepad.Notepad(label: str, level: int)[source]
Bases:
object
Record issues encountered during parsing/validation of a hierarchical data structure.
The issues can be organized in sections. Notepad keeps track of issues in one section and the subsections can be created by calling
add_subsection()
. The function returns an instance responsible for issues of a subsection.A collection of the issues from the current section are available via
issues
property and the convenience functions provide iterators over error and warnings.- abstract add_subsections(*labels: str) Sequence[Notepad] [source]
Add a sequence/chain of subsections.
- Parameters:
labels – a sequence of labels for the new notepad subsections.
- abstract iter_sections() Iterator[Notepad] [source]
Iterate over nodes in the depth-first fashion.
Returns: a depth-first iterator over
Notepad
nodes.
- add_subsection(label: str) Notepad [source]
Add a single labeled subsection.
- Parameters:
label – a label to use for the new subsection.
- property level: int
Get the level of the notepad node (distance from the top-level hierarchy node).
- add_issue(level: Level, message: str, solution: str | None = None)[source]
Add an issue with certain level, message, and an optional solution.
- add_error(message: str, solution: str | None = None)[source]
A convenience function for adding an error with a message and an optional solution.
- has_errors(include_subsections: bool = False) bool [source]
- Returns:
True if one or more errors were found in the current section or its subsections.
- Return type:
- add_warning(message: str, solution: str | None = None)[source]
A convenience function for adding a warning with a message and an optional solution.
- has_warnings(include_subsections: bool = False) bool [source]
- Returns:
True if one or more warnings were found in the current section or its subsections.
- Return type:
- has_errors_or_warnings(include_subsections: bool = False) bool [source]
- Returns:
True if one or more errors or warnings were found in the current section or its subsections.
- Return type: