Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent dataclass declaration #13189

Open
Alviner opened this issue Dec 4, 2024 · 0 comments · May be fixed by #13190
Open

Inconsistent dataclass declaration #13189

Alviner opened this issue Dec 4, 2024 · 0 comments · May be fixed by #13190

Comments

@Alviner
Copy link

Alviner commented Dec 4, 2024

The dataclass decorator in the typeshed package has an inconsistency in its overloads. Specifically, when cls is passed explicitly as None, it is unclear whether additional arguments (e.g., init, repr, etc.) should be allowed or not. The current implementation allows passing cls=None alongside additional arguments, but this usage is not explicitly documented or validated.

Expected Behavior

The overloads should clearly define and document the behavior of cls=None when additional arguments are provided:

If allowed, the typing should reflect that explicitly.
If not allowed, the implementation should prevent or warn against such usage.

Current Behavior

Passing cls=None with arguments like kw_only=True is allowed, but this behavior is not described in the overloads. For example:

decorator = dataclass(None, kw_only=True)
@decorator
class MyClass:
    x: int

The above works but is ambiguous in terms of type checking and intended usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant