Suppose that I have classes Drawable, Placeable, and Draggable. The latter 2 are subclasses of the first. See bare implementation below
class Drawable:
def __init__(self, parent: Union['Drawable', None], children: list['Drawable']):
self.children = children
self.parent = parent
class Placeable(Drawable):
def __init__(self, rect: pygame.rect.Rect, parent: Union['Drawable', None]):
super().__init__(rect, parent, [])
def remove_child(self, target):
self.children.remove(target)
def add_child(self, target):
self.children.append(target)
class Draggable(Drawable):
def __init__(self, rect: pygame.rect.Rect, parent: Placeable):
super().__init__(rect, parent, [])
def release_click(self, pos: Tuple[int, int]):
self.parent.remove_child(self)
I noticed that my IntelliSense doesn't realize that the Draggble.parent is supposed to be a Placeable but only sees it as a Drawable. Is it possible to type hint this better so that this wouldn't be an issue? I'm trying to learn how to type hint properly so that my code can be more readable in the future.