From 27e0961898d1bf1af619d2c765d2c24af931b023 Mon Sep 17 00:00:00 2001 From: David Peter Date: Thu, 23 Jan 2025 10:18:59 +0100 Subject: [PATCH] [red-knot] Add test for nested attribute access --- .../resources/mdtest/attributes.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/red_knot_python_semantic/resources/mdtest/attributes.md b/crates/red_knot_python_semantic/resources/mdtest/attributes.md index 8c41be1cd501d..49121cf97f9ce 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/attributes.md +++ b/crates/red_knot_python_semantic/resources/mdtest/attributes.md @@ -470,6 +470,30 @@ for mod.global_symbol in IntIterable(): pass ``` +## Nested attributes + +```py path=outer/__init__.py +``` + +```py path=outer/nested/__init__.py +``` + +```py path=outer/nested/inner.py +class Outer: + class Nested: + class Inner: + attr: int = 1 +``` + +```py +import outer.nested.inner + +reveal_type(outer.nested.inner.Outer.Nested.Inner.attr) # revealed: int + +# error: [invalid-assignment] +outer.nested.inner.Outer.Nested.Inner.attr = "a" +``` + ## Literal types ### Function-literal attributes