Skip to content

Copy method annotations from parent

Copy missing type annotations from a parent method into an overriding method. This is useful when subclass methods intentionally keep the same signature but were written without annotations.

How to invoke

Place the caret on an overriding method and use ⌥⏎ / Alt+Enter -> "Copy type annotations from parent".

Example

class Handler:
    def handle(self, event: Event) -> Result:
        ...


class AuditHandler(Handler):
    def handle(self, event):
        ...

becomes:

class AuditHandler(Handler):
    def handle(self, event: Event) -> Result:
        ...

What it supports

  • Copying missing parameter annotations.
  • Copying missing return annotations.
  • Keeping existing child annotations when they are already present.
  • Adding imports required by copied annotation names.
  • Rewriting common alias imports so the resulting annotation resolves in the child file.

What it deliberately avoids

  • Methods with no typed parent method.
  • Signature shapes that do not line up with the parent method.
  • Blindly overwriting annotations already present on the child.
  • Applying a fix when import or name conflicts need explicit review.

Notes

  • The intention can be used directly, and the overridden-method inspection can offer it as a quick-fix.
  • The feature is gated by the Copy method annotations from parent setting under Settings | BetterPy | Typing & Type Hints | Type Editing.