pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Unexpected keyword argument for Generic dataclass with ABC bounded TypeVar

Open jtblp opened this issue 4 months ago • 0 comments

Bug description

The following minimal example causes pylint to raise an error (mypy is fine with it):

from abc import ABC
from dataclasses import dataclass
from typing import Generic, TypeVar


class Base:
    pass


class AbstractBase(ABC):
    pass


_T = TypeVar("_T", bound=Base | AbstractBase)


@dataclass
class GenericClass(Generic[_T]):
    field: _T


@dataclass
class ConcreteGeneric(GenericClass[Base | AbstractBase]):
    pass


a = ConcreteGeneric(field=Base())

Configuration

No response

Command used

pylint pylint_test.py

Pylint output

************* Module pylint_test
pylint_test.py:27:4: E1123: Unexpected keyword argument 'field' in constructor call (unexpected-keyword-arg)

-----------------------------------
Your code has been rated at 6.15/10

Expected behavior

I would expect that this code does not raise a warning as the parameter exists.

Pylint version

pylint 3.0.3
astroid 3.0.3
Python 3.12.1 (main, Feb  6 2024, 10:17:43) [Clang 15.0.0 (clang-1500.1.0.2.5)]

OS / Environment

MacOS

Additional dependencies

No response

jtblp avatar Mar 07 '24 10:03 jtblp