ruff
60d46947 - [`flake8-logging`] Allow closures in except handlers for LOG004 (#24464)

Commit
51 days ago
[`flake8-logging`] Allow closures in except handlers for LOG004 (#24464) ## Summary Fixes #18646. `outside_handlers` walks AST ancestors looking for a `Try` statement whose handler range contains the call offset. It used to bail out at `FunctionDef` nodes to avoid crossing scope boundaries, which meant any `logging.exception()` inside a closure defined in an except block got flagged. The range check applies to where the function is defined, not where it's called (which Ruff can't track). This means functions defined inside an except block but called outside of it won't be flagged. This tradeoff fixes the more common false positive at the cost of a less common false negative. Dropped the `FunctionDef` break. ## Test Plan - Updated fixture to move function-inside-except to no-errors section - Added closure-called-within-except test case - local ecosystem runs showed expected results --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
Parents
Loading