How should we annotate functions that forward to their superclass? · Issue #1471 · python/typing (original) (raw)
Consider this real code:
from typing import SuperKwargs
class InferenceManager(Generic[T]): @override def init(self, *, default_trajectory: T, progress_manager: None | ProgressManager, wandb_run: None | Run ) -> None: super().init() self._progress_manager = progress_manager self._results: list[T] = [] self._trajectory = default_trajectory self._wandb_run = wandb_run
class TrainingInferenceManager(InferenceManager[RLTrainingResult]): def init(self, training_result: TrainingResult, **kwargs: SuperKwargs): self.training_result = training_result super().init(**kwargs)
If we want full annotations for TrainingInferenceManager.__init__
, we currently need to duplicate all of the superclass's parameters. I suggest adding typing.SuperKwargs
that stands in place of them.
(This could be made more complicated by allowing the child class to synthesize some of the parameters.)
Related: python/mypy#8769