fixhunt

ruff G010: fix changes program behavior

fix-changes-behaviorlabelled safeintended-change · lowduplicate
Findings / 2026-10-17T20-24-12-113Z-iye4-ruff-G010 / r2-p008ruff 0.17.19 → 3 lines2026-10-17 20:24 UTC

Hypothesis Nemotron 3 Super predicted to fire fired 1×

bytes vs str, encoding and newline handling, text vs binary modes

Program

before
1import logging
2logger = logging.getLogger()
3logger.warn('str string')
after
1import logging
2logger = logging.getLogger()
3logger.warning('str string')

Output

stdout beforeexit 0
(no stdout)
/w/prog.py:3: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
stdout afterexit 0
(no stdout)
str string
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 `logger.warn` call to `logger.warning` as documented. The stderr difference is exactly the removal of the DeprecationWarning that the rule exists to eliminate; the program's actual output ('str string') is unchanged, confirming functional equivalence.

Explanation Nemotron 3 Super unverified

The original call to `logger.warn` triggers a deprecation warning because the method is outdated; this warning appears on stderr before any other output. After rewriting to `logger.warning`, the deprecated method is no longer invoked, so the deprecation warning is suppressed. Although both methods log the same message ('str string') to the log output, the absence of the deprecation warning changes the program’s observable behavior—specifically, what is printed to stderr—making the transformation not semantics-preserving under strict behavioral equivalence that includes side effects like warnings.

Reproduce

file
prog.py (the before program)
minimized program
r2-p008.py
evidence sheet
r2-p008.md
regression fixture
r2-p008.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.warn deprecation fix · Oracle warning method replacement

Details

program
Bytes vs str in warn argument encoding handling
hazard
bytes vs str, encoding and newline handling, text vs binary modes
oracle
stderr before: /w/prog.py:3: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead stderr after: str string
run
2026-10-17T20-24-12-113Z-iye4-ruff-G010
generated program (9 lines) and the fix's diff
1import logging
2import io
3logger = logging.getLogger()
4logger.setLevel(logging.INFO)
5handler = io.StringIO()
6logger.addHandler(logging.StreamHandler(handler))
7logger.warn(b'byte string')
8logger.warn('str string')
9print(handler.getvalue())
--- orig.py	2026-10-17 16:24:38.071869714 -0400
+++ fixed.py	2026-10-17 16:24:38.323869081 -0400
@@ -4,6 +4,6 @@
 logger.setLevel(logging.INFO)
 handler = io.StringIO()
 logger.addHandler(logging.StreamHandler(handler))
-logger.warn(b'byte string')
-logger.warn('str string')
+logger.warning(b'byte string')
+logger.warning('str string')
 print(handler.getvalue())
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)