Skip to content

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

Draft
youknowone with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-subclass-getattribute-issue
Draft

youknowone with Copilot wants to merge 2 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): when no __getattr__ is in the MRO, always resolve the slot through lookup_slot_in_mro on __getattribute__, for both add and remove. Previously this happened only on add, and it used the changed name rather than __getattribute__. The inherit_from_mro fallback on removal is gone, so this now matches how TpSetattro resolves __setattr__/__delattr__.
  • extra_tests/snippets/builtin_object.py: regression test for the add-then-delete sequence above.

@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

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
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
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