# ruff G010: fix changes program behavior

Internal evidence sheet generated by fixhunt. Not an issue text. A human re-verifies, checks the duplicates
below, and writes the upstream report in their own words following the project's AI policy.

- Tool: ruff ruff 0.17.1
- Rule: G010 (tool labels the fix: unknown, this fix reported as safe)
- Oracle: fix-changes-behavior
- Judge (Nemotron 3 Ultra, advisory): intended-change, severity low. The rule replaces the deprecated `logger.warn` with `logger.warning`, which the documentation states are functionally equivalent. The observed difference is the removal of the DeprecationWarning on stderr, which is exactly the semantic change the rule intends to make.
- Program: minimized from 6 to 4 lines

## Reproducer

```python
import logging
logger = logging.getLogger()
gen = (logger.warn(f'Processing {x}') for x in range(2))
print('Second consumption:', list(gen))
```

## Commands

```sh
python3 prog.py
ruff check --preview --isolated --select G010 --fix prog.py
python3 prog.py
```

## Observed

```
stderr before: /w/prog.py:3: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
stderr after: Processing 0
```

## Diff applied by the fix

```diff
--- orig.py	2026-10-22 13:28:56.675481278 -0400
+++ fixed.py	2026-10-22 13:28:59.331525608 -0400
@@ -1,4 +1,4 @@
 import logging
 logger = logging.getLogger()
-gen = (logger.warn(f'Processing {x}') for x in range(2))
+gen = (logger.warning(f'Processing {x}') for x in range(2))
 print('Second consumption:', list(gen))
```

## Why the rewrite is not equivalent (model draft, verify before use)

The original generator expression uses `logger.warn`, which emits a deprecation warning to stderr when called; this occurs during each iteration of the generator. After rewriting to `logger.warning`, the deprecated method is replaced with its non-deprecated counterpart, so no warning is emitted. Since the first consumption of the generator (implicit in printing) now produces no stderr output, while the second consumption still yields the same list, the overall program behavior differs—specifically, the absence of the deprecation warning in stderr changes the observable output. Thus, the rewrite alters side effects and is not semantics-preserving.

## Upstream search

Queries: "G010 fix", "ruff G010 warn generator expression", "Oracle warning deprecation logger usage", "fix changes behavior logger.warn to warning"

- duplicate: https://github.com/astral-sh/ruff/issues/12295
  same rule G010 and same construct: accessing the deprecated `Logger.warn` method which should be rewritten to `Logger.warning`
- related: https://github.com/astral-sh/ruff/issues/7248
  tracks implementation of flake8-logging rules including G010 but is a meta-issue not a specific defect report
- related: https://github.com/astral-sh/ruff/issues/2186
  documents rule aliasing where G010 is an alias of PGH002 but does not describe a defect
- related: https://github.com/astral-sh/ruff/issues/13673
  reports G rules not working with loguru, same rule family but different logger library
- duplicate: https://github.com/astral-sh/ruff/issues/17219
  explicitly closed as duplicate of issue 12295 which is the same Logger.warn access defect
- related: https://github.com/astral-sh/ruff/issues/21889
  BLE001 false positive with logging.warning call, same logging method but different rule and defect type
- related: https://github.com/astral-sh/ruff/issues/6972
  G004 false positive with imported logger instances, same rule family but different construct and rule

<details><summary>All hits</summary>

- [github, open] No error on `logging.Logger.warn` access [G010] — https://github.com/astral-sh/ruff/issues/12295
- [github, open] Implement `flake8-logging` — https://github.com/astral-sh/ruff/issues/7248
- [github, open] Add support for rule aliasing — https://github.com/astral-sh/ruff/issues/2186
- [github, closed] unused-function-argument not silenced by prefixed underscore if variable name is "次" — https://github.com/astral-sh/ruff/issues/28721
- [github, closed] G rules seems not working with loguru. — https://github.com/astral-sh/ruff/issues/13673
- [github, closed] Ord violation panic when fixing file with nightly compiler — https://github.com/astral-sh/ruff/issues/12469
- [github, closed] Pack of fuzzer Autofix/Infinite loop errors [2] — https://github.com/astral-sh/ruff/issues/8402
- [github, closed] Rule RUF027 cause panic — https://github.com/astral-sh/ruff/issues/9895
- [github, closed] Fixed code unformatted — https://github.com/astral-sh/ruff/issues/8619
- [github, closed] Add option to disable preview warnings — https://github.com/astral-sh/ruff/issues/8620
- [tavily] Importing a logger circumvents "logging-f-string (G004)" · Issue #17219 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/17219
- [tavily] Deprecation of ANN 001 and 002 Discussion · Issue #9770 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/9770
- [tavily] BLE001 (blind-except): false positive when logging via `warning` · Issue #21889 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/21889
- [tavily] Add rule deprecation infrastructure by zanieb · Pull Request #9689 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/pull/9689
- [tavily] JSON Schema invalid when using previous ruff version · Issue #14810 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/14810
- [tavily] Instances of logging.Logger falsely pass G004 when imported from another module · Issue #6972 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/6972
- [tavily] RUF065 should not apply to the combination of `%r` and `repr` · Issue #20583 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/20583
- [tavily] Feature request: Support a "warning" level for linting · Issue #1256 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/1256

</details>
