Skip to content

Commit d5f5b68

Browse files
SONARPY-1830 Prevent single-assigned module scope types from being propagated to nested functions
1 parent a828c2d commit d5f5b68

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

python-checks/src/test/resources/checks/nonCallableCalled.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def calling_global_func():
217217

218218
def using_nonlocal_var():
219219
nonlocal some_nonlocal_var
220-
some_nonlocal_var() # Noncompliant
220+
some_nonlocal_var() # OK
221221

222222

223223
def reassigned_function():

python-frontend/src/main/java/org/sonar/python/semantic/v2/types/TrivialTypeInferenceVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ public void visitName(Name name) {
364364
.filter(Expression.class::isInstance)
365365
.map(Expression.class::cast)
366366
.map(Expression::typeV2)
367+
// FIXME: classes and functions should be propagated like other types
368+
.filter(t -> (t instanceof ClassType) || (t instanceof FunctionType))
367369
.ifPresent(type -> setTypeToName(name, type));
368370
}
369371

python-frontend/src/test/java/org/sonar/python/semantic/v2/TypeInferenceV2Test.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ void inferTypeForBuiltins() {
287287
}
288288

289289
@Test
290-
@Disabled("Single assigned is approximated for now")
291290
void inferTypesInsideFunction1() {
292291
FileInput root = inferTypes("""
293292
x = 42

0 commit comments

Comments
 (0)