diff --git a/pyrefly/lib/alt/class/class_field.rs b/pyrefly/lib/alt/class/class_field.rs index 343ff20468..e096e43e3c 100644 --- a/pyrefly/lib/alt/class/class_field.rs +++ b/pyrefly/lib/alt/class/class_field.rs @@ -3440,7 +3440,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> { .. } => { ty = self.normalize_attr_ty(ty); - if ambiguous { + if ambiguous && !matches!(cls, ClassBase::SelfType(_)) { ClassAttribute::no_access(NoAccessReason::ClassAttributeIsGeneric( cls.class_object().dupe(), )) diff --git a/pyrefly/lib/test/attributes.rs b/pyrefly/lib/test/attributes.rs index a346991eaa..9108ebd362 100644 --- a/pyrefly/lib/test/attributes.rs +++ b/pyrefly/lib/test/attributes.rs @@ -701,6 +701,21 @@ C.x # E: Generic attribute `x` of class `C` is not visible on the class "#, ); +testcase!( + test_class_generic_attribute_lookup_on_self_type, + r#" +from typing import assert_type + +class C[T]: + x: type[T] + + @classmethod + def f(cls) -> type[T]: + assert_type(cls.x, type[T]) + return cls.x +"#, +); + testcase!( test_var_attribute, r#"