Closed cclauss closed 9 months ago
I learned a lot from going through those improvements. One of your changes seems unintended though.
You changed log.error
to log.exception
. Not the same. In the case of multithreading with the aforementioned code, we certainly want the log.error
with the shortened output because log.exception
adds exception info to the logging message, which is normally fine, but it'll make multithreaded output messy. Please undo that specific change.
Merged!
%
ruff --select=B004,G010,PLR1701,PLR5501,RET502,SIM114 --fix
%
ruff --select=C4,RET503,SIM110,SIM118,TRY400,UP028 --fix --unsafe-fixes
%
ruff rule B004
unreliable-callable-check (B004)
Derived from the flake8-bugbear linter.
Fix is sometimes available.
What it does
Checks for uses of
hasattr
to test if an object is callable (e.g.,hasattr(obj, "__call__")
).Why is this bad?
Using
hasattr
is an unreliable mechanism for testing if an object is callable. Ifobj
implements a custom__getattr__
, or if its__call__
is itself not callable, you may get misleading results.Instead, use
callable(obj)
to test ifobj
is callable.Example
Use instead:
References
callable
hasattr
__getattr__
__call__