This rule raises an issue when a method decorated with @property does not contain any return statement.
In Python, the @property decorator transforms a method into a getter for a computed attribute. When you access a property, you expect
to receive a value, just like accessing a regular attribute.
A property method without a return statement will implicitly return None. This makes the property useless because it
always provides None instead of a meaningful value. This behavior is almost always unintentional and indicates a bug in the code.
This rule does not raise an issue when the property method raises an exception or is decorated with @abstractmethod, as these are
intentional patterns where a return value is not expected.
When a property method lacks a return statement, it always returns None. This leads to:
None return is not obvious from looking at the property access, making bugs
harder to trace.None
instead, breaking the expected interface.Add a return statement to the property method that returns the intended value.
@property
def area(self):
3.14159 * self._radius ** 2 # Noncompliant
@property
def area(self):
return 3.14159 * self._radius ** 2
property