Skip to content

gh-136843: Document how multiple inheritance works #136844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Jul 20, 2025

@rhettinger
Copy link
Contributor

This all looks good to me except for the final section about "solid bases". That last section should be checked by another reviewer with a stronger understanding of the details.

Copy link
Contributor

@ilovelinux ilovelinux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it fits this PR but describing how super() works with multiple inheritance may be interesting!

@brianschubert
Copy link
Member

@ilovelinux super() follows the class' MRO. How lookups work in the presence of multiple inheritance is already documented (though if anything is unclear, suggestions are always welcome!). This issue is about documenting when multiple inheritance isn't possible to begin with.

@JelleZijlstra
Copy link
Member Author

The docs of super() already mention this: https://docs.python.org/3.14/library/functions.html#super

@JelleZijlstra JelleZijlstra requested a review from sobolevn July 22, 2025 00:35
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I am not an expert in the "solid base" part in C :)
So, can't review that part.

Comment on lines 1557 to 1558
possible to compute a *solid base* for the class. A class is a solid base if it has a
nonempty :attr:`~object.__slots__` definition; some other classes may also be solid bases,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also consider the __slots__ behaviour a CPython implementation detail?
IMO, it would be good if alternate implementations -- or even future versions of CPython -- could drop the limitation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but this behavior is already documented in the __slots__ docs without any "implementation detail" warning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That note was added in #1819; it looks like a note on current behaviour rather than documenting design intent.
IMO, several of the notes are simply implementation limitations that we should be allowed to lift if the internals change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the mention of __slots__ into the implementation detail section.

JelleZijlstra and others added 2 commits July 22, 2025 07:04
Co-authored-by: Petr Viktorin <encukou@gmail.com>
description of how Python determines the MRO for a class.

Multiple inheritance is not always allowed. Attempting to define a class with multiple
inheritance will raise an error if one of the bases is invalid, if a consistent MRO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about "one of the bases is invalid" part. Some class is not acceptable to be base class. Is it correct to call this class "invalid"? I'd suggest little rewording.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I was also thinking of trying to inherit from something that isn't a class. I'll reword.

all other candidate metaclasses. If no such metaclass exists among the candidates,
the class cannot be created, as explained in :ref:`metaclass-determination`.

Finally, the memory layouts of the bases must be compatible. This means that it must be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it "memory layout" or "instance layout"? Or those are fully equivalent? This is not very obvious now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We debated how to describe this concept while writing the docs for the relevant ty rule. I think the clearest way to describe the concept is "the memory layout instances of the class will have", but that's a bit wordy 😄 "instance memory layout" is probably next best?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll go with "instance layout" since that's what the TypeError says.

Co-authored-by: Akuli <akuviljanen17@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting merge docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

9 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy