ruff G010: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 1×
When lint.logger-objects includes a logger imported via from x import y as z, the tool may fail to recognize the alias and either miss the violation or incorrectly rewrite non-logger uses of z.
Program
Output
(no stdout) /w/prog.py:3: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
(no stdout) test
- fired
- 1 before · 0 after
- runs
- each version twice, same file name, no network
Judge Nemotron 3 Ultra advisory intended-change · low
The rule rewrites the deprecated `warn` method to `warning` to eliminate the DeprecationWarning, which is exactly the documented purpose. The stderr output changes from a deprecation warning to the actual log message 'test', demonstrating the fix works as intended.
Explanation Nemotron 3 Super unverified
The original call to `warn` emits both the logged message "test" and a deprecation warning to stderr because Python’s logging module treats `warn` as a deprecated alias that triggers a warning when used. The rewritten call uses `warning`, which logs the same message but does not emit any deprecation warning. Since the deprecation warning is part of the program’s observable output (stderr), changing from `warn` to `warning` alters the program’s behavior, making the transformation not semantics-preserving despite preserving the intended log output. The fix incorrectly assumes functional equivalence without accounting for side effects like warnings.
Reproduce
- file
prog.py(the before program)- minimized program
- r2-p007.py
- evidence sheet
- r2-p007.md
- regression fixture
- r2-p007.py the minimized program with a header stating the observed change, for the tool's test suite
python3 prog.py ruff check --preview --isolated --select G010 --fix prog.py python3 prog.py
Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra
G010 fix · ruff G010 warn method · logging logger warning call · deprecated warn to warning
- duplicate astral-sh/ruff/issues/12295 same G010 rule rewriting logging.Logger.warn to warning
- related astral-sh/ruff/issues/7248 tracks flake8-logging rules including G010 but not the autofix behavior change
- related astral-sh/ruff/issues/2186 documents G010 alias PGH002 but not the autofix defect
- related astral-sh/ruff/issues/13673 about G rules not working with loguru, different logger library
- duplicate astral-sh/ruff/issues/17219 closed as duplicate of issue 12295 about logging.Logger.warn access
- related astral-sh/ruff/issues/28407 extends TRY401 for log levels, different rule
- related astral-sh/ruff/issues/15555 requests autofix for G rules including G010
- related astral-sh/ruff/issues/4136 TRY400 flags log.error vs log.exception, different rule
- related astral-sh/ruff/issues/4692 feature request for G101 logging-extra-attr-clash
- related astral-sh/ruff/issues/21889 BLE001 false positive with logging.warning, different rule
- related astral-sh/ruff/issues/11031 G004 doesn't work with inline instantiated logger, different G rule
- related astral-sh/ruff/issues/11854 new rule for formatted string passed to logging module
- related astral-sh/ruff/issues/14221 warn about deprecated API usage, general deprecation detection
- related astral-sh/ruff/issues/1507 use banned-api for deprecation checks including warn->warning
- related astral-sh/ruff/issues/18349 warn about errors from deprecated rules
- related astral-sh/ruff/issues/9770 deprecation discussion for ANN001 and ANN002 rules
Details
- program
- Aliased logger import not recognized by lint.logger-objects
- hazard
- When lint.logger-objects includes a logger imported via from x import y as z, the tool may fail to recognize the alias and either miss the violation or incorrectly rewrite non-logger uses of z.
- oracle
stderr before: /w/prog.py:3: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead stderr after: test- run
- 2026-10-17T20-24-12-113Z-iye4-ruff-G010
generated program (5 lines) and the fix's diff
--- orig.py 2026-10-17 16:24:37.698870654 -0400 +++ fixed.py 2026-10-17 16:24:37.943870036 -0400 @@ -1,5 +1,5 @@ import logging my_logger = logging.getLogger() my_logger.setLevel(logging.INFO) -my_logger.warn('test') +my_logger.warning('test') print('Done')
rule documentation given to the models
# logging-warn (G010)
Derived from the **flake8-logging-format** linter.
Fix is always available.
## What it does
Checks for uses of `logging.warn` and `logging.Logger.warn`.
## Why is this bad?
`logging.warn` and `logging.Logger.warn` are deprecated in favor of
`logging.warning` and `logging.Logger.warning`, which are functionally
equivalent.
## Known problems
This rule detects uses of the `logging` module via a heuristic.
Specifically, it matches against:
- Uses of the `logging` module itself (e.g., `import logging; logging.info(...)`).
- Uses of `flask.current_app.logger` (e.g., `from flask import current_app; current_app.logger.info(...)`).
- Objects whose name starts with `log` or ends with `logger` or `logging`,
when used in the same file in which they are defined (e.g., `logger = logging.getLogger(); logger.info(...)`).
- Imported objects marked as loggers via the [`lint.logger-objects`] setting, which can be
used to enforce these rules against shared logger objects (e.g., `from module import logger; logger.info(...)`,
when [`lint.logger-objects`] is set to `["module.logger"]`).
## Example
```python
import logging
logging.warn("Something happened")
```
Use instead:
```python
import logging
logging.warning("Something happened")
```
## Options
- `lint.logger-objects`
## References
- [Python documentation: `logging.warning`](https://docs.python.org/3/library/logging.html#logging.warning)
- [Python documentation: `logging.Logger.warning`](https://docs.python.org/3/library/logging.html#logging.Logger.warning)