This rule raises an issue when a method decorated with @property does not contain any return statement.

Why is this an issue?

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.

Exceptions

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.

What is the potential impact?

When a property method lacks a return statement, it always returns None. This leads to:

How to fix it

Add a return statement to the property method that returns the intended value.

Code examples

Noncompliant code example

@property
def area(self):
    3.14159 * self._radius ** 2  # Noncompliant

Compliant solution

@property
def area(self):
    return 3.14159 * self._radius ** 2

Resources

Documentation

Related rules