Skip to content

Commit 40759d7

Browse files
yangdanny97meta-codesync[bot]
authored andcommitted
regression test for lazy class attr init
Summary: #1479 (comment) Reviewed By: migeed-z Differential Revision: D88543250 fbshipit-source-id: b243976d0062d0f8d448454a02eaa729b043ba7a
1 parent 3f263a0 commit 40759d7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pyrefly/lib/test/attributes.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,22 @@ reveal_type(A.x) # E: revealed type: T
18201820
"#,
18211821
);
18221822

1823+
testcase!(
1824+
test_lazy_class_attribute_init,
1825+
r#"
1826+
from typing import assert_type
1827+
class C:
1828+
@classmethod
1829+
def m(cls):
1830+
if hasattr(cls, "foo"):
1831+
return cls.foo
1832+
retval = "foo"
1833+
cls.foo = retval
1834+
return retval
1835+
assert_type(C.foo, str)
1836+
"#,
1837+
);
1838+
18231839
// See https://github.com/facebook/pyrefly/issues/1448 for what this tests
18241840
// and discussion of approaches to handling `@functools.wraps` with return
18251841
// type inference.

0 commit comments

Comments
 (0)