I have a Python library that encapsulates an external c++ library that exposes its objects via handles. I have a root class
class ABObj:
def __init__(self, *args, **kwargs):
if is_handle(args[0]):
self.handle = args[0]
else:
self.handle = self._make_obj(*args, **kwargs)
The idea is the constructor can either capture an external handle or create a new object. The latter task is delegated to the subclasses of ABObj
.
The problem with this setup is the user gets no parameter hints when instantiating a subclass of ABObj
. The autocompletion tool (like Pylance in VS Code) has no idea that the constructor signature is either a single handle or it matches the subclass’s make_obj
method. Is there a way to accomplish that?