Skip to content

Commit 5beb1d8

Browse files
lolpackmeta-codesync[bot]
authored andcommitted
Add scope edge case tests
Summary: Add 2 new tests for scope edge cases (both bugs, not yet detected): - `test_del_in_dead_code_makes_local`: del in dead code branch should not affect variable locality - `test_conditionally_defined_class_member`: conditionally defined class attribute Reviewed By: yangdanny97 Differential Revision: D97777537 fbshipit-source-id: 9a374d8da24dbc5469319f2d403c13b8cccddc6a
1 parent e567467 commit 5beb1d8

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

pyrefly/lib/test/scope.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,3 +1350,34 @@ def test_2(cond: bool):
13501350
assert_type(active_session, int)
13511351
"#,
13521352
);
1353+
1354+
// https://github.com/facebook/pyrefly/issues/2930
1355+
testcase!(
1356+
bug = "del in dead code should still make the variable local, hiding the outer binding",
1357+
test_del_in_dead_code_makes_local,
1358+
r#"
1359+
x = 1
1360+
1361+
def f():
1362+
# Even though the del is in unreachable code, Python's compiler
1363+
# still marks x as local in f's scope.
1364+
print(x)
1365+
if False:
1366+
del x
1367+
"#,
1368+
);
1369+
1370+
// https://github.com/facebook/pyrefly/issues/2929
1371+
testcase!(
1372+
bug = "Should detect possibly-missing attribute on conditionally-defined class members",
1373+
test_conditionally_defined_class_member,
1374+
r#"
1375+
def coin() -> bool:
1376+
return True
1377+
1378+
class Config:
1379+
name: str = "default"
1380+
if coin():
1381+
debug = True
1382+
"#,
1383+
);

0 commit comments

Comments
 (0)