From f70a062b9b4e9278fcbbc856a56e4aaebd08f44f Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Sat, 22 Apr 2023 18:04:38 -0400 Subject: [PATCH] Strictly type check enhanced_directory_tree.py, ignoring private access --- enhanced_directory_tree.py | 8 ++++++-- pyrightconfig.json | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/enhanced_directory_tree.py b/enhanced_directory_tree.py index ca6066b..0c0adf6 100644 --- a/enhanced_directory_tree.py +++ b/enhanced_directory_tree.py @@ -1,5 +1,7 @@ import os from textual.widgets import DirectoryTree +from textual.widgets._tree import TreeNode +from textual.widgets._directory_tree import DirEntry class EnhancedDirectoryTree(DirectoryTree): def expand_to_path(self, target_path: str) -> None: @@ -13,7 +15,8 @@ class EnhancedDirectoryTree(DirectoryTree): # - Definitely want to figure out how to avoid the timers. node = self.root - def get_node_name(node): + def get_node_name(node: TreeNode[DirEntry]) -> str: + assert node.data return os.path.basename(node.data.path.rstrip(os.path.sep)) for path_segment in target_path.split(os.path.sep): # Find the child node with the right name. @@ -22,6 +25,7 @@ class EnhancedDirectoryTree(DirectoryTree): node = child break if get_node_name(node) == path_segment: + assert node.data if node.data.is_dir: if not node.is_expanded and not node.data.loaded: # load_directory also calls node.expand() @@ -50,7 +54,7 @@ class EnhancedDirectoryTree(DirectoryTree): # self.scroll_to_region(self._get_label_region(node._line), animate=False, top=True) # Timer is needed to wait for the new nodes to mount, I think. def scroll_node_to_top(): - region = self._get_label_region(node._line) + region = self._get_label_region(node._line) # type: ignore assert region, "Node not found in tree" self.scroll_to_region(region, animate=False, top=True) self.set_timer(0.01, scroll_node_to_top) diff --git a/pyrightconfig.json b/pyrightconfig.json index ce6dde4..117d9cc 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -8,7 +8,8 @@ "**/.*" ], "strict": [ - "**/i18n.py" + "**/i18n.py", + "**/enhanced_directory_tree.py", ], "reportOptionalMemberAccess": false } \ No newline at end of file