Skip to content

Commit 9c3f750

Browse files
committed
help type checker
1 parent ef49f95 commit 9c3f750

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/textual/_node_list.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,11 @@ def __getitem__(self, index: slice) -> list[Widget]: ...
228228
def __getitem__(self, index: int | slice) -> Widget | list[Widget]:
229229
return self._nodes[index]
230230

231-
def __getattr__(self, key: str) -> object:
232-
if key in {"clear", "append", "pop", "insert", "remove", "extend"}:
233-
raise ReadOnlyError(
234-
"Widget.children is read-only: use Widget.mount(...) or Widget.remove(...) to add or remove widgets"
235-
)
236-
raise AttributeError(key)
231+
if not TYPE_CHECKING:
232+
# This confused the type checker for some reason
233+
def __getattr__(self, key: str) -> object:
234+
if key in {"clear", "append", "pop", "insert", "remove", "extend"}:
235+
raise ReadOnlyError(
236+
"Widget.children is read-only: use Widget.mount(...) or Widget.remove(...) to add or remove widgets"
237+
)
238+
raise AttributeError(key)

0 commit comments

Comments
 (0)