Skip to content

hasattr-call

Pythonsuspiciousno fixdefault: warnpython/ruff

Reports a call of hasattr or getattr that asks for "__call__".

hasattr(x, "__call__") asks for the attribute on the object, which is not what Python does when it calls a value: it looks the method up on the type. The result can differ, and callable(x) is the test that matches the call.

To fix, write callable(x).

Reported
...
...
hasattr(x, "__call__")
python:
lint:
rules:
hasattr-call: warn # off, warn (default), error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line hasattr-call in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff B004 full