Best practice for type annotation and docstring inheritance

47 views Asked by At

I have a python class like this

class LinBlock(nn.Module):
    def __init__(
            self,
            inp_features: int,
            out_features: int,
            activation: Callable[[], "nn.Module"] = None,
            normalizer: Callable[[int], "nn.Module"] = None,
            n: int = 1,
            p: float = 0,
            activation_every_n: bool = False,
            normalizer_every_n: bool = True,
            sample_type: Literal["mono", "bi"] = "mono",
            **extras,
    ):
        """
        :param inp_features: number of input features
        :param out_features: number of output features
        :param activation: activation function
        :param normalizer: normalization layer
        :param n: number of intermediate convolutions
        :param p: dropout probability
        :param activation_every_n: whether to apply activation after every n convolutions
        :param normalizer_every_n: whether to apply normalizer after every n convolutions
        :param sample_type: type of sampling, either mono or bi
        :param extras: arguments to pass to the linear layers
        """
        ...

which is inherited like this

class ResidualLinBlock(LinBlock):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        ...
        # other stuff goes here, specific to `ResidualLinBlock`

this creates a problem in code editors like PyCharm which does not understand that ResidualLinBlock (*args, **kwargs) has the same signature as LinBlock and thus does not show the doc string hints

What would be the best practice in python for such scenarios

0

There are 0 answers