Skip to content

mypy doesn't infer **kwargs types from superclass #10079

Open
@rectalogic

Description

@rectalogic

Bug Report
If a subclass __init__ passes **kwargs to it's superclass, the superclasses parameter types should be used to validate the subclass arguments.

To Reproduce

Run mypy on this file:

import datetime


class Bar:
    def __init__(self, a: int, b: str, c: datetime.datetime):
        pass


class Baz(Bar):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)


Baz(b=3)

Expected Behavior

Something like
error: Argument "b" to "Baz" has incompatible type "int"; expected "str"

Actual Behavior

mypy found no errors

Your Environment

  • Mypy version used: mypy 0.800
  • Mypy command-line flags: python filename
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.8.6
  • Operating system and version: macOS 10.15.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    featuretopic-inferenceWhen to infer types or require explicit annotationstopic-inheritanceInheritance and incompatible overrides

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions