Concrete implementation for interior nodes.
| 229 | |
| 230 | |
| 231 | class Node(Base): |
| 232 | """Concrete implementation for interior nodes.""" |
| 233 | |
| 234 | fixers_applied: list[Any] | None |
| 235 | used_names: set[str] | None |
| 236 | |
| 237 | def __init__( |
| 238 | self, |
| 239 | type: int, |
| 240 | children: list[NL], |
| 241 | context: Any | None = None, |
| 242 | prefix: str | None = None, |
| 243 | fixers_applied: list[Any] | None = None, |
| 244 | ) -> None: |
| 245 | """ |
| 246 | Initializer. |
| 247 | |
| 248 | Takes a type constant (a symbol number >= 256), a sequence of |
| 249 | child nodes, and an optional context keyword argument. |
| 250 | |
| 251 | As a side effect, the parent pointers of the children are updated. |
| 252 | """ |
| 253 | assert type >= 256, type |
| 254 | self.type = type |
| 255 | self.children = list(children) |
| 256 | for ch in self.children: |
| 257 | assert ch.parent is None, repr(ch) |
| 258 | ch.parent = self |
| 259 | self.invalidate_sibling_maps() |
| 260 | if prefix is not None: |
| 261 | self.prefix = prefix |
| 262 | if fixers_applied: |
| 263 | self.fixers_applied = fixers_applied[:] |
| 264 | else: |
| 265 | self.fixers_applied = None |
| 266 | |
| 267 | def __repr__(self) -> str: |
| 268 | """Return a canonical string representation.""" |
| 269 | assert self.type is not None |
| 270 | return f"{self.__class__.__name__}({type_repr(self.type)}, {self.children!r})" |
| 271 | |
| 272 | def __str__(self) -> str: |
| 273 | """ |
| 274 | Return a pretty string representation. |
| 275 | |
| 276 | This reproduces the input source exactly. |
| 277 | """ |
| 278 | return "".join(map(str, self.children)) |
| 279 | |
| 280 | def _eq(self, other: Base) -> bool: |
| 281 | """Compare two nodes for equality.""" |
| 282 | return (self.type, self.children) == (other.type, other.children) |
| 283 | |
| 284 | def clone(self) -> "Node": |
| 285 | assert self.type is not None |
| 286 | """Return a cloned (deep) copy of self.""" |
| 287 | return Node( |
| 288 | self.type, |
no outgoing calls
no test coverage detected