@@ -147,6 +147,14 @@ class RenderCache(NamedTuple):
147147 lines : Lines
148148
149149
150+ class WidgetError (Exception ):
151+ """Base widget error."""
152+
153+
154+ class MountError (WidgetError ):
155+ """Error raised when there was a problem with the mount request."""
156+
157+
150158@rich .repr .auto
151159class Widget (DOMNode ):
152160 """
@@ -189,9 +197,6 @@ class Widget(DOMNode):
189197 hover_style : Reactive [Style ] = Reactive (Style , repaint = False )
190198 highlight_link_id : Reactive [str ] = Reactive ("" )
191199
192- class WidgetError (Exception ):
193- """Base widget error."""
194-
195200 def __init__ (
196201 self ,
197202 * children : Widget ,
@@ -238,7 +243,7 @@ def __init__(
238243 )
239244
240245 if self in children :
241- raise self . WidgetError ("A widget can't be its own parent" )
246+ raise WidgetError ("A widget can't be its own parent" )
242247
243248 self ._add_children (* children )
244249
@@ -381,9 +386,6 @@ def _get_virtual_dom(self) -> Iterable[Widget]:
381386 if self ._scrollbar_corner is not None :
382387 yield self ._scrollbar_corner
383388
384- class MountError (WidgetError ):
385- """Error raised when there was a problem with the mount request."""
386-
387389 def _find_mount_point (self , spot : int | str | "Widget" ) -> tuple ["Widget" , int ]:
388390 """Attempt to locate the point where the caller wants to mount something.
389391
@@ -394,7 +396,7 @@ def _find_mount_point(self, spot: int | str | "Widget") -> tuple["Widget", int]:
394396 tuple[Widget, int]: The parent and the location in its child list.
395397
396398 Raises:
397- Widget. MountError: If there was an error finding where to mount a widget.
399+ MountError: If there was an error finding where to mount a widget.
398400
399401 The rules of this method are:
400402
@@ -421,7 +423,7 @@ def _find_mount_point(self, spot: int | str | "Widget") -> tuple["Widget", int]:
421423 # have a parent? There's no way we can use it as a sibling to make
422424 # mounting decisions if it doesn't have a parent.
423425 if spot .parent is None :
424- raise self . MountError (
426+ raise MountError (
425427 f"Unable to find relative location of { spot !r} because it has no parent"
426428 )
427429
@@ -431,7 +433,7 @@ def _find_mount_point(self, spot: int | str | "Widget") -> tuple["Widget", int]:
431433 try :
432434 return spot .parent , spot .parent .children .index (spot )
433435 except ValueError :
434- raise self . MountError (f"{ spot !r} is not a child of { self !r} " ) from None
436+ raise MountError (f"{ spot !r} is not a child of { self !r} " ) from None
435437
436438 def mount (
437439 self ,
@@ -459,7 +461,7 @@ def mount(
459461
460462 # Saying you want to mount before *and* after something is an error.
461463 if before is not None and after is not None :
462- raise self . MountError (
464+ raise MountError (
463465 "Only one of `before` or `after` can be handled -- not both"
464466 )
465467
0 commit comments