[flake8-logging] .exception() and exc_info= outside exception handlers (LOG004, LOG014)#15799
[flake8-logging] .exception() and exc_info= outside exception handlers (LOG004, LOG014)#15799MichaReiser merged 7 commits intoastral-sh:mainfrom
flake8-logging] .exception() and exc_info= outside exception handlers (LOG004, LOG014)#15799Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| LOG004 | 22 | 22 | 0 | 0 | 0 |
| LOG014 | 16 | 16 | 0 | 0 | 0 |
|
They could have been defined in the same module/function, but I was worried that there might be too much coupling between them. I'll merge them if that is indeed the better approach. |
|
I just realized #14682 exists (which, unfortunately, hasn't been active for more than a month). I'm willing to remove my |
|
I see that the code does handle it, but I think it would be good to test that the lint doesn't trigger for |
|
@bluetech Done for the former and already done for the latter. |
MichaReiser
left a comment
There was a problem hiding this comment.
Thanks. This overall looks good. We should add some tests with custom logger objects (in dedicated files) to see if the seen_module short-circuit check is valid.
crates/ruff_linter/src/rules/flake8_logging/rules/exception_call_outside_handlers.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_logging/rules/exception_call_outside_handlers.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_logging/rules/exception_call_outside_handlers.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_logging/rules/exc_info_outside_handlers.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_logging/rules/exc_info_outside_handlers.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_logging/rules/exc_info_outside_handlers.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_logging/rules/exc_info_outside_handlers.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_logging/rules/exc_info_outside_handlers.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_logging/rules/exc_info_outside_handlers.rs
Outdated
Show resolved
Hide resolved
|
The ecosystem check also report a few false-positives e.g: This was discussed in your linked PR, see #14682 (comment) and #14682 (comment) I'm interested in your opinion on this. I'm somewhat leaning towards using noqa comments for such functions because: The function should document that it should only be called from inside a Did you review the other ecosystem checks? Considering that there are more LOG014, maybe consider splitting the PR into two? |
…andlers (`LOG004`, `LOG014`)
I'm aware of them. The original rule also intentionally reports them, so I think it's fine. As for splitting, I'm not sure. They are closely related enough. |
|
Huh, this one is interesting. Would you mind taking a look at why it is flagged |
|
@MichaReiser Fixed. The method name should also have been checked. |
|
Thanks |
* main: (66 commits) [red-knot] Use ternary decision diagrams (TDDs) for visibility constraints (#15861) [`pyupgrade`] Rename private type parameters in PEP 695 generics (`UP049`) (#15862) Simplify the `StringFlags` trait (#15944) [`flake8-pyi`] Make `PYI019` autofixable for `.py` files in preview mode as well as stubs (#15889) Docs (`linter.md`): clarify that Python files are always searched for in subdirectories (#15882) [`flake8-pyi`] Make PEP-695 functions with multiple type parameters fixable by PYI019 again (#15938) [red-knot] Use unambiguous invalid-syntax-construct for suppression comment test (#15933) Make `Binding::range()` point to the range of a type parameter's name, not the full type parameter (#15935) Update black deviations (#15928) [red-knot] MDTest: Fix line numbers in error messages (#15932) Preserve triple quotes and prefixes for strings (#15818) [red-knot] Hand-written MDTest parser (#15926) [`pylint`] Fix missing parens in unsafe fix for `unnecessary-dunder-call` (`PLC2801`) (#15762) nit: docs for ignore & select (#15883) [airflow] `BashOperator` has been moved to `airflow.providers.standard.operators.bash.BashOperator` (AIR302) (#15922) [`flake8-logging`] `.exception()` and `exc_info=` outside exception handlers (`LOG004`, `LOG014`) (#15799) [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) [red-knot] Internal refactoring of visibility constraints API (#15913) [red-knot] Implicit instance attributes (#15811) [`flake8-comprehensions`] Handle extraneous parentheses around list comprehension (`C403`) (#15877) ...
Summary
Part of #7248.
This change adds two new rules:
LOG004andLOG014. They are closely related and thus share the same handlers detecting logic. Tests and documentation are adapted from that of the upstream linter.Test Plan
cargo nextest runandcargo insta test.