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

fix: Don't return class variables as parameters of dataclasses #253

Merged
merged 3 commits into from
Mar 12, 2024

Conversation

has2k1
Copy link
Contributor

@has2k1 has2k1 commented Mar 12, 2024

This PR fixes the issue where class variables are recognised as class parameters.

This definition

from dataclasses import dataclass
from typing import ClassVar

@dataclass
class Point:
    x: float
    y: float
    z: ClassVar[float] = 3

is equivalent to

class Point:
    z: float = 3

    def __init__(self, x: float, y: float):
        self.x = x
        self.y = y

The signature is Point(x, y) and neither Point(x, y, z) or Point(x, y, z=3).

tests/test_dataclasses.py Outdated Show resolved Hide resolved
Copy link
Member

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@pawamoy pawamoy merged commit 2729c22 into mkdocstrings:main Mar 12, 2024
17 checks passed
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 this pull request may close these issues.

None yet

2 participants