-
Notifications
You must be signed in to change notification settings - Fork 34
Description
I have a basic inherited class structure that looks more or less like this, with some methods in the base class that return objects of the same type:
from typing import Self
class A(SomeOtherBaseClass):
...
def method_1(self) -> Self:
modified_copy = self.deepcopy()
return modified_copy
def method_2(self) -> Self:
modified_copy = self.deepcopy()
return modified_copy
...
class B(A):
def sub_class_method_b():
...
class C(A):
def sub_class_method_c():
...
To type hint the methods in class A
, I've specified the return type as typing.Self
, which works fine in my editor. When building the docs using python-apigen
, the entity pages for classes B
and C
look something like this:
I have also tried type-hinting with the name of the parent class, like this:
class A(SomeOtherBaseClass):
...
def method_1(self) -> "A":
modified_copy = self.deepcopy()
return modified_copy
def method_2(self) -> "A":
modified_copy = self.deepcopy()
return modified_copy
...
class B(A):
def sub_class_method_b():
...
class C(A):
def sub_class_method_c():
...
That also works in my editor, but results in incorrect documentation pages, that show the methods always return an object of class A
, even on the pages for class B
and C
:
Ideally, the correct interpretation would be that those methods would return type B
on the B page, and C
on the C page. Is there anyway to configure things so this is the output?