Skip to content

too-many-positional-arguments: dataclasses? #28777

Description

@decorator-factory

Summary

too-many-positional-arguments (PLR0917)

from dataclasses import dataclass

@dataclass
class Thing:
    foo: float
    bar: float
    baz: float
    width: float
    height: float
    is_fizz: bool
    is_buzz: bool
    is_fizzbuzz: bool

This implicilty creates an __init__ with 8 positional arguments, so a caller is allowed to do Thing(1, 2, 3, 4, 5, True, True, True) which doesn't look very clear. However, too-many-positional-arguments does not catch this.

I'm not sure how to best detect this, since there's more than just built-in dataclasses. (hardcode dataclasses, msgspec, pydantic?) (if we had type information, we could check if a "dataclass transform" is used)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainerruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions