Skip to content

False positive [unexpected-positional-argument] with dataclass inheritance #2166

@randolf-scholz

Description

@randolf-scholz

Describe the Bug

from dataclasses import dataclass, KW_ONLY

@dataclass
class Foo:
    _: KW_ONLY
    option: int | None = None


@dataclass
class Bar(Foo):
    arg: str

Bar("arg")  # ❌️ raises [unexpected-positional-argument]

Because all arguments in the parent class are KW_ONLY, we can add POSITIONAL_OR_KEYWORD arguments in the dataclass subclass.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEmqALqgMZSpxzx0Q3G5KTBszYcuAGjoBpAOoB9APIA5ADIBNADrptAAUYt2nONqNc6AMVy5E2uvbrzEMhSo12HuYkwi50ziHRhAB86ZT8YOgBeMIjtePR9UTMTdBS6ACFUSgAKK1wASlt0BzpsgHNnOCZKBKzczRAKxoL7AGI6QBlyQHg-ukpUCG44OgBtAFd0GHxiGFYmGEwAWgE4CB8-VChFirGaGCCAXRAJEDGfKDgSckQQDoBVc7XSOjAJud90VO1MGDAXwRozHk6F22BguXwASCrUWAD46NVKMVSpQYEwxpQSmBGspQeDnMB8ABfRraY4gMiosBQUiEJi0KAUDoABVIVJpCIwOAIdFYfkg5QxzA%2BhG0HQAyjBIgALJhMYhwRAAeiVlN%2BNMIgnKSv2SswuFYcCVfPQAqF63QSv%2BlDKADcBhxsLBefyIIL%2Bha6F4LZdtGQmNK-ItbeDVn5onRGgBmQgARgATKT0CAiSc2D4QxZoDAKGgsHgiGQU0A

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedLarger than "good first issue", but still well-defined and ready for someone to pick upstaletypechecking

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions