python / python/typing

How should we annotate functions that forward to their superclass?

Open
#1,471 5 comments 16 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: feature
Dominant language
Python
Stars
1.8k
Forks
302
Avg merge
23h
Merged PRs (30d)
8

Description

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: https://github.com/python/mypy/issues/8769

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation files, tests, or entry points are named. Start by reading the proposed SuperKwargs behavior and related mypy issue #8769; the issue needs an agreed design for forwarded and synthesized parameters before implementation can be scoped.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.