Skip to content

Fix subclass __getattribute__ being dropped after del Base.__getattr__ - #9800

Merged
youknowone merged 3 commits into
mainfrom
copilot/fix-subclass-getattribute-issue
Nov 13, 2026
Merged

youknowone merged 3 commits into
mainfrom
copilot/fix-subclass-getattribute-issue

Conversation

Copilot AI commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

__getattribute__ and __getattr__ share the getattro slot. When one of them was removed from a class, the slot update re-inherited from the first base with a getattro slot. It never looked at a __getattribute__ in the class's own dict, so a subclass's override was silently lost. This is what happens to subclasses after mock.patch.object(Base, "__getattr__", ..., create=True) exits.

class Base: pass
class Proxy(Base):
    def __getattribute__(self, name):
        print("Proxy.__getattribute__", name)
        return object.__getattribute__(self, name)

p = Proxy(); p.x = 1
Base.__getattr__ = lambda self, name: "fallback"
del Base.__getattr__
p.x  # CPython: calls Proxy.__getattribute__; RustPython (before): skipped it

Changes

  • crates/vm/src/types/slot.rs (SlotAccessor::TpGetattro): on both add and remove, look up __getattribute__ and __getattr__ through the MRO and pick the slot from the pair, in the same way TpSetattro resolves __setattr__/__delattr__:

    • either name resolves to a Python-level method → getattro_wrapper
    • both resolve to the same native slot → that slot
    • only one resolves to a native slot → that slot
    • neither is found → inherit from the MRO

    __getattr__ has no native wrapper descriptor, so finding it anywhere in the MRO always selects getattro_wrapper. Previously the slot was re-resolved only on add, and removal always fell back to inherit_from_mro.

  • extra_tests/snippets/builtin_object.py: regression test for the add-then-delete sequence above.

  • Fixes Deleting __getattr__ from a base class stops a subclass's own __getattribute__ from being called #9796

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI changed the title [WIP] Fix subclass __getattribute__ not being called after deleting __getattr__ Fix subclass __getattribute__ being dropped after del Base.__getattr__ Nov 11, 2026
Copilot AI requested a review from youknowone November 11, 2026 14:38
Copilot AI and others added 3 commits November 13, 2026 17:53
Co-authored-by: youknowone <[email protected]>
update_slot for TpGetattro now looks up __getattribute__ and __getattr__
through the MRO on both add and remove, and picks the slot from the pair
the same way TpSetattro does for __setattr__/__delattr__.

Assisted-by: Claude:claude-opus-5-5
@youknowone
youknowone force-pushed the copilot/fix-subclass-getattribute-issue branch from 8cc118f to e4e2305 Compare November 13, 2026 08:53
@youknowone
youknowone marked this pull request as ready for review November 13, 2026 09:30
@youknowone
youknowone enabled auto-merge (squash) November 13, 2026 09:30
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-13T09:30:09.610917Z
We couldn’t complete this review. Comment @codex review to try again.
e4e2305 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@youknowone
youknowone disabled auto-merge November 13, 2026 09:51
@youknowone
youknowone merged commit 9a82f61 into main Nov 13, 2026
23 checks passed
@youknowone
youknowone deleted the copilot/fix-subclass-getattribute-issue branch November 13, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleting __getattr__ from a base class stops a subclass's own __getattribute__ from being called

2 participants