From af0724ba515b61dbdead945f43baf29116d44d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Mon, 13 Sep 2021 12:28:30 +0200 Subject: Fix crash on datafields (#1165) * Fix crash on datafields Fixes the crash reported at PyCQA/pylint#4963 Tests added there. * Change to ``if not`` * Update astroid/brain/brain_dataclasses.py * Add tests * Update and merge test * Use ``raise UseInferenceDefault`` --- tests/unittest_brain_dataclasses.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests') diff --git a/tests/unittest_brain_dataclasses.py b/tests/unittest_brain_dataclasses.py index b50d4575..6710009b 100644 --- a/tests/unittest_brain_dataclasses.py +++ b/tests/unittest_brain_dataclasses.py @@ -643,3 +643,21 @@ def test_invalid_init(module: str): ) init = next(node.infer()) assert init._proxied.parent.name == "object" + + +@parametrize_module +def test_annotated_enclosed_field_call(module: str): + """Test inference of dataclass attribute with a field call in another function call""" + node = astroid.extract_node( + f""" + from {module} import dataclass, field + from typing import cast + + @dataclass + class A: + attribute: int = cast(int, field(default_factory=dict)) + """ + ) + inferred = node.inferred() + assert len(inferred) == 1 and isinstance(inferred[0], nodes.ClassDef) + assert "attribute" in inferred[0].instance_attrs -- cgit v1.2.1