Skip to content

False positive on class definition keyword arguments #11036

@anuppari

Description

@anuppari

Bug Report

Mixing a numpy ndarray with a metaclass that uses keyword arguments causes a false positive.

To Reproduce
Run mypy on the following code

from typing import Dict, Optional, Tuple
import numpy as np

class Meta(type):
    def __new__(
        cls, name: str, bases: Tuple[type, ...], dct: Dict, *args,
        a: Optional[int] = None, **kwargs
    ):
        return super().__new__(cls, name, bases, dct, *args, **kwargs)

class A(np.ndarray, a=1, metaclass=Meta):
    pass

a = A(shape=(2,))

Expected Behavior

Should pass without errors

Actual Behavior

Get the following error:

error: Unexpected keyword argument "a" for "__init_subclass__" of "object"

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.8.6
  • Operating system and version: Ubuntu 20.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions