how to retrive methods pydoc from Generic class

Currently we use vs-code to develop and having pydocs documentation helps a lot to understand the system overall, but the IDE is returning the documentation of the interface rather than the implementation class, I'm wondering if there is a way to allow the IDE to use the implmentation class documentation rather than the interface one.

To better explain my point we have few classes in our app as shown below: BaseKMSProvider is a domain specific interface for any KMSProvider while AWSProvider is its implementation. We have a Service class that uses a BaseKMSProvider but we know the instance of that provider will be the AWSProvider and therefore want the documentation to come directly from the it.


T = TypeVar("T")


class BaseProvider(Generic[T]):
    pass

class BaseKMSProvider(BaseProvider):
    @abstract_method
    def method_a(self):
       """domain specific documentation"""
       pass

class AWSProvider(BaseKMSProvider):
   
    def method_a(self):
       """provider specific documentation"""
       pass


class Service:
    provider: BaseKMSProvider[AWSProvider] = get_aws_provider()

    def some_service_method(self):
        self.provider.method_a()

Here is image of the IDE: VS-code popup

I tried using Protocols also, but could not manage to make it work.

Is there any way to make the provider specific documentation appear in the Service class?

Upvotes: -1

Views: 49

Answers (1)

JialeDu
JialeDu

Reputation: 9727

If you hover over the provider you will see that the actual type of the property provider is still the BaseKMSProvider class.

enter image description here

IntelliSense will display provider specific documentation unless you modify it to AWSProvider.

enter image description here

enter image description here

Upvotes: 0

Related Questions