-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected TRY400 indicated in unchanged code #292
Comments
…e RUF100 to prevent it from failing in this branch. Ref #292
My understanding of the purpose of try:
i = 1 / 0
except ZeroDivisionError as exc:
logging.exception('"my error message"') instead of: try:
i = 1 / 0
except ZeroDivisionError as exc:
logging.error(f'"my error message" {exc}') The output is considered more informative:
instead of:
In any case |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I can reproduce the issue with branch feature/compilers-module-redux after removing Files distutils/_msvccompiler.py from |
The reason is hidden in this change at the top of the file, in imports: - from ._log import log
+ from ..._log import log In the former case, from ._log import log into: import logging
log = logging.getLogger() That looks like a ruff bug, doesn't it? |
This comment was marked as outdated.
This comment was marked as outdated.
The bug is triggered by the
Even an empty $ ruff check --select=TRY400
All checks passed!
$ After removing the empty
I do see the $ ruff check --select=TRY400
distutils/_msvccompiler.py:6:5: TRY400 Use `logging.exception` instead of `logging.error`
|
4 | i = 1 / 0
5 | except DivisionByZero as e:
6 | log.error(f"raised {e}")
| ^^^^^^^^^^^^^^^^^^^^^^^^ TRY400
|
= help: Replace with `exception`
Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
$ |
I created astral-sh/ruff#13225. |
Thanks for the investigation! |
…version 74.1.2 Jason R. Coombs (9): Use monkeypatch to monkeypatch. Disable TRY400 so it doesn't cause problems in other branches. Disable RUF100 to prevent it from failing in this branch. Ref pypa/distutils#292 In sdist.prune_file_list, support build.build_base as a pathlib.Path. Add test capturing missed expectation. Enable the test Add news fragment. Skip test on stdlib distutils Bump version: 74.1.1 → 74.1.2 Removed test_integration tests (for easy_install).
In the feature/compilers-module-redux branch, I'm attempting to refactor the code. When I do, a TRY400 error is indicated even though the code hasn't changed:
First off, that's a nuisance error. What if what I really wanted was to log just the error message? Ruff shouldn't be griping about legitimate usage of supported interfaces. If
logging.error
shouldn't ever be used, they should file that as a feature change to CPython to get that functionality deprecated.Second, why is this error only emitted in the branch (bac29f1), when the same code succeeds just fine in main?
@DimitriPapadopoulos What do you make of this error?
The text was updated successfully, but these errors were encountered: