Skip to content

How should we annotate functions that forward to their superclass? #1471

Description

@NeilGirdhar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: featureDiscussions about new features for Python's type annotations

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions