# ruff UP004: 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: UP004 (tool labels the fix: unknown, this fix reported as safe)
- Oracle: fix-changes-behavior
- Judge (Nemotron 3 Ultra, advisory): real, severity high. The fix removes 'object' from the base class list of a class that also inherits from Mixin and Base, changing the MRO and resolving a previously unresolvable diamond inheritance conflict. The documentation presents the rewrite as equivalent for all classes, but here the explicit 'object' was required to make the MRO consistent, so the fix silently changes a crashing program into a working one.
- Program: minimized from 14 to 9 lines

## Reproducer

```python
class Mixin:
    def ping(self):
        return 'from Mixin'
class Base:
    def ping(self):
        return 'from Base'
class C(object, Mixin, Base):
    def ping(self):
        return super().ping()
```

## Commands

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

## Observed

```
exit 1 → 0
stderr before: TypeError: Cannot create a consistent method resolution
stderr after: (none)
```

## Diff applied by the fix

```diff
--- orig.py	2026-10-22 13:37:14.257847180 -0400
+++ fixed.py	2026-10-22 13:37:16.800890166 -0400
@@ -4,6 +4,6 @@
 class Base:
     def ping(self):
         return 'from Base'
-class C(object, Mixin, Base):
+class C(Mixin, Base):
     def ping(self):
         return super().ping()
```

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

The original inheritance order `object, Mixin, Base` creates an inconsistent MRO because `object` precedes both parents but they conflict in their own hierarchy; Python cannot linearize this. Removing `object` yields `Mixin, Base`, which has a consistent MRO (`C → Mixin → Base → object`), allowing `super().ping()` to resolve to `Mixin.ping`. Thus the fix changes behavior by enabling a previously invalid class definition, altering method resolution and eliminating the TypeError. This is not semantics‑preserving because the original program was invalid and raised an error, while the rewritten version executes successfully with a different return value. The safety label assumes validity, but the fix changes the program’s dynamic semantics by correcting an illegitimate inheritance list. (119 words)

## Upstream search

Queries: "UP004 fix", "UP004 redundant base classes", "unnecessary object inheritance Python 3", "super call MRO error removal"

- related: https://github.com/astral-sh/ruff/issues/18387
  Issue 18387 is another UP-rule (UP050) fix-safety report involving class base manipulation, same rule family but different construct.
- related: https://github.com/astral-sh/ruff/issues/15584
  Issue 15584 requests fix-safety documentation for rules including UP004, same rule but a documentation task not a defect report.

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

- [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, open] Implement Pylint — https://github.com/astral-sh/ruff/issues/970
- [github, closed] UP050 fix should be unsafe when it deletes a comment — https://github.com/astral-sh/ruff/issues/18387
- [github, closed] Formatter: Bug with Pragma Comment for pyright being moved to invalid position — https://github.com/astral-sh/ruff/issues/8481
- [github, closed] Fixed code unformatted — https://github.com/astral-sh/ruff/issues/8619
- [github, closed] Autofix errors from extended ecosystem checks — https://github.com/astral-sh/ruff/issues/4523
- [github, closed] Add option to disable preview warnings — https://github.com/astral-sh/ruff/issues/8620
- [github, closed] Implement support for SIM120 — https://github.com/astral-sh/ruff/issues/3712
- [github, closed] Implement pyupgrade — https://github.com/astral-sh/ruff/issues/827
- [github, closed] Implement flake8-pyi — https://github.com/astral-sh/ruff/issues/848
- [github, open] Document fix safety — https://github.com/astral-sh/ruff/issues/15584

</details>
