Skip to content

Commit abc60f7

Browse files
joke1196sonartech
authored andcommitted
SONARPY-4020 S8504 Fix property shadowing tests (#1048)
GitOrigin-RevId: d95038f4fc3260c5c9266d3a05f80d63da24ff2c
1 parent b1f2a3e commit abc60f7

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

python-checks/src/main/java/org/sonar/python/checks/PropertyMethodWithoutReturnCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class PropertyMethodWithoutReturnCheck extends PythonSubscriptionCheck {
2929

3030
private static final String MESSAGE = "Add a return statement to this property method.";
31-
private static final TypeMatcher PROPERTY_MATCHER = TypeMatchers.isType("builtins.property");
31+
private static final TypeMatcher PROPERTY_MATCHER = TypeMatchers.isType("property");
3232
private static final TypeMatcher ABSTRACT_METHOD_MATCHER = TypeMatchers.isType("abc.abstractmethod");
3333

3434
@Override

python-checks/src/test/java/org/sonar/python/checks/PropertyMethodWithoutReturnCheckTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ void test() {
2626
PythonCheckVerifier.verify("src/test/resources/checks/propertyMethodWithoutReturn.py", new PropertyMethodWithoutReturnCheck());
2727
}
2828

29+
@Test
30+
void test_shadowing_propery() {
31+
PythonCheckVerifier.verifyNoIssue("src/test/resources/checks/propertyMethodWithoutReturnShadowingProperty.py", new PropertyMethodWithoutReturnCheck());
32+
}
2933
}

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,6 @@ def via_finally(self): # Compliant - return in finally block
201201
return self._data.get("key")
202202

203203

204-
def property(func):
205-
"""A user-defined decorator that happens to be named 'property'."""
206-
return func
207-
208-
209-
class UserDefinedPropertyDecorator:
210-
def __init__(self):
211-
self._value = 0
212-
213-
@property
214-
def value(self): # Compliant - built-in 'property' is shadowed by the user-defined decorator above; type matcher correctly excludes this
215-
self._value * 2
216-
217-
218204
import functools
219205

220206

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
def property(func):
3+
"""A user-defined decorator that happens to be named 'property'."""
4+
return func
5+
6+
7+
class UserDefinedPropertyDecorator:
8+
def __init__(self):
9+
self._value = 0
10+
11+
@property
12+
def value(self): # Compliant - built-in 'property' is shadowed by the user-defined decorator above; type matcher correctly excludes this
13+
self._value * 2
14+

0 commit comments

Comments
 (0)