So, given a class setup something like this:
class Parent:
_GET_URL = None
@classmethod
def get_object(cls) -> typing.Self:
requests.get(cls._GET_URL)
and
class Child(Parent):
_GET_URL = "https://some-url-to-child.me"
Similar URLs are set up for all child classes.
How do I typehint it such that
- its obvious that the get_object method can only be callable by calling it on a child class (and therefore getting the object from their url)
- the linter understands the returned object is of Child type. Using pycharm, it only recognizes the result of Child.get_object() as ‘Parent’
Tried using both typing.Self
and ChildObject = TypeVar('ChildObject', bounds="Parent"
) with no results. No idea how to achieve 1)