Made an adapter. The adapter accepts a class and returns itself.
class Adapter(metaclass=ABCMeta): def __init__(self, adaptable_object): self._adaptable_object = adaptable_object @property def adaptable_object(self) -> Adapter: # Этот метод приходится перегружать return self.adaptable_object class B(Adapter): @property def adaptable_object(self) -> "B": # Типа перегрузил. return super().adaptable_object Is it possible to specify the caller itself as the type of the returned object?
Or maybe some other solution is to not overload the method in each new heir?
adaptable_object()is a type of constructor that must return an instance subclass, and not just a base class variable, then you can try a generic self :TypeVar('T', bound='Adatpter')instead of Adapter. In general, be suspicious of cases where you use inheritance, but cannot use a particular variable as an instance of the base class — if you are trying to pull a particular subclass from the base method, you should consider delegation in this case - jfs@classmethod, and created through__init__, I initially thought that this would be more close to the python, but there was a lot of inconvenience. As a result, I began to adapt through__init__, and create new instances through@classmethod, and problems of this kind fell off, and the code became smaller. - Mr Fix