# 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 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.
- Program: minimized from 5 to 3 lines

## Reproducer

```python
import logging
my_logger = logging.getLogger()
my_logger.warn('test')
```

## 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: test
```

## Diff applied by the fix

```diff
--- orig.py	2026-10-22 13:29:10.319709053 -0400
+++ fixed.py	2026-10-22 13:29:12.973753374 -0400
@@ -1,3 +1,3 @@
 import logging
 my_logger = logging.getLogger()
-my_logger.warn('test')
+my_logger.warning('test')
```

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

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.

## Upstream search

Queries: "G010 fix", "ruff G010 warn method", "logging logger warning call", "deprecated warn to warning"

- duplicate: https://github.com/astral-sh/ruff/issues/12295
  same G010 rule rewriting logging.Logger.warn to warning
- related: https://github.com/astral-sh/ruff/issues/7248
  tracks flake8-logging rules including G010 but not the autofix behavior change
- related: https://github.com/astral-sh/ruff/issues/2186
  documents G010 alias PGH002 but not the autofix defect
- related: https://github.com/astral-sh/ruff/issues/13673
  about G rules not working with loguru, different logger library
- duplicate: https://github.com/astral-sh/ruff/issues/17219
  closed as duplicate of issue 12295 about logging.Logger.warn access
- related: https://github.com/astral-sh/ruff/issues/28407
  extends TRY401 for log levels, different rule
- related: https://github.com/astral-sh/ruff/issues/15555
  requests autofix for G rules including G010
- related: https://github.com/astral-sh/ruff/issues/4136
  TRY400 flags log.error vs log.exception, different rule
- related: https://github.com/astral-sh/ruff/issues/4692
  feature request for G101 logging-extra-attr-clash
- related: https://github.com/astral-sh/ruff/issues/21889
  BLE001 false positive with logging.warning, different rule
- related: https://github.com/astral-sh/ruff/issues/11031
  G004 doesn't work with inline instantiated logger, different G rule
- related: https://github.com/astral-sh/ruff/issues/11854
  new rule for formatted string passed to logging module
- related: https://github.com/astral-sh/ruff/issues/14221
  warn about deprecated API usage, general deprecation detection
- related: https://github.com/astral-sh/ruff/issues/1507
  use banned-api for deprecation checks including warn->warning
- related: https://github.com/astral-sh/ruff/issues/18349
  warn about errors from deprecated rules
- related: https://github.com/astral-sh/ruff/issues/9770
  deprecation discussion for ANN001 and ANN002 rules

<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
- [github, open] Add an extended version of TRY401 for all log levels — https://github.com/astral-sh/ruff/issues/28407
- [github, open] Autofix for flake8-logging-format (G) rules — https://github.com/astral-sh/ruff/issues/15555
- [github, open] TRY400 flags log.error() + raise/sys.exit() — https://github.com/astral-sh/ruff/issues/4136
- [github, open] Feature request: G101 logging-extra-attr-clash (or a new, similar rule) to detect (potentially) unsafe dict unpacking — https://github.com/astral-sh/ruff/issues/4692
- [github, open] Feature: Port Sonar's Python scanner checks — https://github.com/astral-sh/ruff/issues/4935
- [github, closed] Callable compared with is True not flagged — https://github.com/astral-sh/ruff/issues/25145
- [github, closed] BLE001 (blind-except): false positive when logging via `warning` — https://github.com/astral-sh/ruff/issues/21889
- [github, closed] Rule G004 doesn't work with inline instantiated logger — https://github.com/astral-sh/ruff/issues/11031
- [github, closed] Is it possible to auto-fix a multi-line string `format` call with a single-line string template? — https://github.com/astral-sh/ruff/issues/5531
- [tavily] New Rule: Formatted string passed to logging module PYL-W1203 · Issue #11854 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/11854
- [github, open] Warn if anything marked as deprecated is used — https://github.com/astral-sh/ruff/issues/14221
- [github, open] Preview: Prevent duplicate warnings for repeated selections — https://github.com/astral-sh/ruff/issues/7367
- [github, open] Use `banned-api` for deprecation checks in general — https://github.com/astral-sh/ruff/issues/1507
- [github, open] Ignoring `import-private-name (PLC2701)` for `_typeshed` import — https://github.com/astral-sh/ruff/issues/15295
- [github, open] D417 Argument descriptions only required if there is an "Args" section — https://github.com/astral-sh/ruff/issues/2310
- [github, open] Server doesn't detect ruff config for files not under working directory of server — https://github.com/astral-sh/ruff/issues/17944
- [github, open] Seeking improved pytest rules, as `flake8-pytest-style` doesn't align with best practices — https://github.com/astral-sh/ruff/issues/8796
- [github, open] Unified command for linting and formatting — https://github.com/astral-sh/ruff/issues/8232
- [github, closed] Duplication and inconsistency between pep585 annotation rules: UP006, UP035 — https://github.com/astral-sh/ruff/issues/15246
- [tavily] Warn about error being related to a deprecated rule · Issue #18349 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/18349
- [tavily] Deprecation of ANN 001 and 002 Discussion · Issue #9770 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/9770

</details>
