mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Tweak the unknown node ID exception
See https://github.com/Textualize/textual/pull/1535#discussion_r1065904713 and https://github.com/Textualize/textual/pull/1535#discussion_r1065909144
This commit is contained in:
@@ -513,7 +513,7 @@ class Tree(Generic[TreeDataType], ScrollView, can_focus=True):
|
||||
else:
|
||||
return line.node
|
||||
|
||||
class UnknownID(Exception):
|
||||
class UnknownNodeID(Exception):
|
||||
"""Exception raised when referring to an unknown `TreeNode` ID."""
|
||||
|
||||
def get_node_by_id(self, node_id: NodeID) -> TreeNode[TreeDataType]:
|
||||
@@ -531,7 +531,7 @@ class Tree(Generic[TreeDataType], ScrollView, can_focus=True):
|
||||
try:
|
||||
return self._nodes[node_id]
|
||||
except KeyError:
|
||||
raise self.UnknownID(f"Unknown TreeNode ID: {node_id}") from None
|
||||
raise self.UnknownNodeID(f"Unknown NodeID ({node_id}) in tree") from None
|
||||
|
||||
def validate_cursor_line(self, value: int) -> int:
|
||||
"""Prevent cursor line from going outside of range."""
|
||||
|
||||
@@ -12,5 +12,5 @@ def test_get_tree_node_by_id() -> None:
|
||||
assert tree.get_node_by_id(tree.root.id).id == tree.root.id
|
||||
assert tree.get_node_by_id(child.id).id == child.id
|
||||
assert tree.get_node_by_id(grandchild.id).id == grandchild.id
|
||||
with pytest.raises(Tree.UnknownID):
|
||||
with pytest.raises(Tree.UnknownNodeID):
|
||||
tree.get_node_by_id(cast(NodeID, grandchild.id + 1000))
|
||||
|
||||
Reference in New Issue
Block a user