Represents a path from one node to another within a tree.
| 22 | |
| 23 | |
| 24 | class NodePath(PurePosixPath): |
| 25 | """Represents a path from one node to another within a tree.""" |
| 26 | |
| 27 | def __init__(self, *pathsegments): |
| 28 | if sys.version_info >= (3, 12): |
| 29 | super().__init__(*pathsegments) |
| 30 | else: |
| 31 | super().__new__(PurePosixPath, *pathsegments) |
| 32 | if self.drive: |
| 33 | raise ValueError("NodePaths cannot have drives") |
| 34 | |
| 35 | if self.root not in ["/", ""]: |
| 36 | raise ValueError( |
| 37 | 'Root of NodePath can only be either "/" or "", with "" meaning the path is relative.' |
| 38 | ) |
| 39 | # TODO should we also forbid suffixes to avoid node names with dots in them? |
| 40 | |
| 41 | def absolute(self) -> Self: |
| 42 | """Convert into an absolute path.""" |
| 43 | return type(self)("/", *self.parts) |
| 44 | |
| 45 | |
| 46 | class TreeNode: |
no outgoing calls
searching dependent graphs…