Skip to content

Commit 75cf835

Browse files
committed
It seems like Mypy specific handling of class scopes, fixes #5
1 parent cc04805 commit 75cf835

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

crates/zuban_python/src/type_helpers/class.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,17 +1416,15 @@ impl<'db: 'a, 'a> Class<'a> {
14161416
.get(class_block.index())
14171417
.calculated()
14181418
{
1419-
if !db.project.settings.mypy_compatible {
1420-
let result = self.file.ensure_module_symbols_flow_analysis(db);
1421-
if result.is_err() {
1422-
debug!(
1423-
"Wanted to calculate class {:?} diagnostics, but could not calculated file {}",
1424-
self.name(),
1425-
self.file.qualified_name(db)
1426-
);
1427-
}
1428-
result?;
1419+
let result = self.file.ensure_module_symbols_flow_analysis(db);
1420+
if result.is_err() {
1421+
debug!(
1422+
"Wanted to calculate class {:?} diagnostics, but could not calculated file {}",
1423+
self.name(),
1424+
self.file.qualified_name(db)
1425+
);
14291426
}
1427+
result?;
14301428
let result = FLOW_ANALYSIS.with(|fa| {
14311429
fa.with_new_empty_and_delay_further(db, || {
14321430
self.file

crates/zuban_python/tests/mypylike/tests/flow-analysis.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,3 +546,15 @@ def test_func():
546546
offset = data["next"]
547547
else:
548548
break
549+
550+
[case file_flow_analysis]
551+
from h import H
552+
553+
def blubb(self, h: H):
554+
h.asdf
555+
556+
[file h.py]
557+
x = undefined # E: Name "undefined" is not defined
558+
559+
class H:
560+
asdf = x

0 commit comments

Comments
 (0)