Skip to content

Use actual inference to determine dataclasses #1394

Closed
@DanielNoord

Description

@DanielNoord

Steps to reproduce

def test_non_dataclass_is_not_dataclass() -> None:
    """Test that something that isn't a dataclass has the correct attribute."""
    code = astroid.extract_node(
        """
    @dataclass
    class A:
        val: field()
    """
    )
    inferred = code.inferred()
    assert len(inferred) == 1
    assert isinstance(inferred[0], nodes.ClassDef)
    assert not inferred[0].is_dataclass

With the changes in #1391 this should pass, but it doesn't.
I think it might be because we only check the name of the decorator and not actually what it is. ie., in this case dataclass is not imported so A won't be a dataclass.

Expected behavior

Determine what is and what isn't a dataclass a little better.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions