Skip to content

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

Merged
pawamoy merged 3 commits intomkdocstrings:mainfrom
has2k1:fix-dataclasses-classvar
Mar 12, 2024
Merged

fix: Don't return class variables as parameters of dataclasses#253
pawamoy merged 3 commits intomkdocstrings:mainfrom
has2k1:fix-dataclasses-classvar

Conversation

@has2k1
Copy link
Copy Markdown
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).

Copy link
Copy Markdown
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
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.

2 participants