diff options
| author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-09-13 12:28:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-13 12:28:30 +0200 |
| commit | af0724ba515b61dbdead945f43baf29116d44d4a (patch) | |
| tree | 58920d6c71a85d4c972adf9316c4610b144c1a00 /tests | |
| parent | 741cd614d7cec1f730a66632f018ff0bcb17b561 (diff) | |
| download | astroid-git-af0724ba515b61dbdead945f43baf29116d44d4a.tar.gz | |
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``
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unittest_brain_dataclasses.py | 18 |
1 files changed, 18 insertions, 0 deletions
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 |
