From e458448ee418e10cf28a089704dc42ba3c8aca37 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Wed, 30 Nov 2022 16:04:57 +0100 Subject: [PATCH] pyright: add aliasing test (#1063) --- tests/dataclass_transform_example.py | 12 ++++++++++++ tests/test_pyright.py | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/dataclass_transform_example.py b/tests/dataclass_transform_example.py index 49e09061..af09e8a5 100644 --- a/tests/dataclass_transform_example.py +++ b/tests/dataclass_transform_example.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: MIT import attr +import attrs @attr.define() @@ -43,3 +44,14 @@ d2 = FrozenDefine("a") d2.a = "new" reveal_type(d2.a) # noqa + + +# Field-aliasing works +@attrs.define +class AliasedField: + _a: int = attrs.field(alias="_a") + + +af = AliasedField(42) + +reveal_type(af.__init__) # noqa diff --git a/tests/test_pyright.py b/tests/test_pyright.py index 44b30890..98f5038b 100644 --- a/tests/test_pyright.py +++ b/tests/test_pyright.py @@ -75,9 +75,13 @@ def test_pyright_baseline(): severity="information", message='Type of "d2.a" is "Literal[\'new\']"', ), + PyrightDiagnostic( + severity="information", + message='Type of "af.__init__" is "(_a: int) -> None"', + ), } - assert diagnostics == expected_diagnostics + assert expected_diagnostics == diagnostics def test_pyright_attrsinstance_compat(tmp_path):