diff options
| author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2021-10-15 20:53:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-15 20:53:05 +0200 |
| commit | b2f57b7e5e49253c69bd7335999b20fea9e3633a (patch) | |
| tree | 8f829cba740d46ba797a2d8a9c6be38fb19c2881 /tests | |
| parent | d4674781d974bd73ca3bfe82fd0816684f2a97d4 (diff) | |
| download | astroid-git-b2f57b7e5e49253c69bd7335999b20fea9e3633a.tar.gz | |
Fix crash with invalid field call (#1212)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unittest_brain_dataclasses.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/unittest_brain_dataclasses.py b/tests/unittest_brain_dataclasses.py index 62c0af7a..237d54ae 100644 --- a/tests/unittest_brain_dataclasses.py +++ b/tests/unittest_brain_dataclasses.py @@ -664,3 +664,20 @@ def test_annotated_enclosed_field_call(module: str): inferred = node.inferred() assert len(inferred) == 1 and isinstance(inferred[0], nodes.ClassDef) assert "attribute" in inferred[0].instance_attrs + + +@parametrize_module +def test_invalid_field_call(module: str) -> None: + """Test inference of invalid field call doesn't crash.""" + code = astroid.extract_node( + f""" + from {module} import dataclass, field + + @dataclass + class A: + val: field() + """ + ) + inferred = code.inferred() + assert len(inferred) == 1 + assert isinstance(inferred[0], nodes.ClassDef) |
