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

bug: Regular classes that inherit dataclass do not get dataclass parameters #238

Closed
has2k1 opened this issue Feb 13, 2024 · 1 comment
Closed
Assignees

Comments

@has2k1
Copy link
Contributor

has2k1 commented Feb 13, 2024

Here is failing test case

from griffe.tests import temporary_visited_module

code = """
from dataclasses import dataclass

@dataclass
class Base:
    a: int
    b: str

@dataclass
class Derived1(Base):
    c: float

class Derived2(Base):
    d: float 
"""

with temporary_visited_module(code) as module:
    params1 = list(module["Derived1"].parameters)
    params2 = list(module["Derived2"].parameters)
    assert [p.name for p in params1] == ["a", "b", "c"]
    assert [p.name for p in params2] == ["a", "b"] # failing
@pawamoy
Copy link
Member

pawamoy commented Feb 13, 2024

Thanks, nice catch. The new approach will fix that too.

has2k1 added a commit to has2k1/qrenderer that referenced this issue Feb 14, 2024
This is so griffe can pick the parameters from the dataclass
base class.
ref: mkdocstrings/griffe#238
pawamoy added a commit that referenced this issue Mar 5, 2024
Instead of generating parameters on the fly by (wrongly) checking attributes of the class,
we always load a Griffe extension that re-creates `__init__` methods and their parameters.

Issue-33: #233
Issue-34: #234
Issue-38: #238
Issue-39: #239
PR-240: #240
@pawamoy pawamoy closed this as completed Mar 5, 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

No branches or pull requests

2 participants