Skip to content

Possible overlap between TRY400 and G201 #4603

@ericbn

Description

@ericbn

test.py

Minimal code snipped that reproduces the bug:

import logging

logger = logging.getLogger()
try:
    pass
except Exception:
    logger.error("Error", exc_info=True)

Ruff output

The command I've invoked: ruff --isolated --select G,TRY test.py

test.py:7:5: TRY400 Use `logging.exception` instead of `logging.error`
test.py:7:12: G201 Logging `.exception(...)` should be used instead of `.error(..., exc_info=True)`
Found 2 errors.

After changing the test.py file to:

-    logger.error("Error", exc_info=True)
+    logger.error("Error")

I get only:

test.py:7:5: TRY400 Use `logging.exception` instead of `logging.error`
Found 1 error.

Maybe the broader TRY400 rule is enough, in favor of G201. Not sure what's the rationale for overlapping/duplicate rules in ruff.

ruff --version

ruff 0.0.269

Metadata

Metadata

Assignees

Labels

questionAsking for support or clarification

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions