Nothing calls a method whose name is mangled private

tx0/python:uncalled-private-methodrecommendedwarningmaintainability

What it finds

def __recompute(self): that nothing calls: a name with two leading underscores and no trailing ones is private to its class, since Python renames it to _Class__name inside the class body. If the class itself never mentions it, no code can reach it without spelling out the mangled name, and the method is dead.

Mentions are counted anywhere in the file, as the plain or the mangled name, so that uses through getattr with a string, or from other classes of the file, also count. Decorated methods and stubs are left alone.

From the rule's source, uncalled_private_method.rs.

Example from the rule's tests
class Store:    def __recompute(self):tx0 reports: the private method __recompute is never called        return 1     def __flush(self):        return 2     def save(self):        return self.__flush()     def __len__(self):        return 0     def _helper(self):        return 3     def __mangled(self):        return 4     def use(self):        return getattr(self, "_Store__mangled")()
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:uncalled-private-method" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:uncalled-private-method] reason="..."

tx0 explain tx0/python:uncalled-private-method shows the same in the terminal. Found a false positive? Report it.