Add warning to old/classic class inheritance problem#48
Open
Eddy114514 wants to merge 7 commits intosoftdevteam:migrationfrom
Open
Add warning to old/classic class inheritance problem#48Eddy114514 wants to merge 7 commits intosoftdevteam:migrationfrom
Eddy114514 wants to merge 7 commits intosoftdevteam:migrationfrom
Conversation
added 7 commits
April 7, 2026 18:43
due to some problem.....
so it contain not relevant chanegs
Member
|
Can you fix the PR description (the formatting has gone wrong) and squash the commits to remove the ones that aren't relevant for review (note: I'm not necessarily saying squash down to one commit!). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Python 2 classic classes use depth-first, left-to-right method lookup. Python 3 only has new-style classes, which use C3 MRO. In classic multiple inheritance, this can silently change which base class provides an attribute after migration.
Example:
In Python 2 classic classes, D().do_this() resolves to A.
Under Python 3 / C3 MRO, the same hierarchy resolves to C.
Behavior Difference:
Python 2 classic lookup:
D -> B -> A -> CPython 3 / C3 lookup:
D -> B -> C -> ASo the same attribute name can resolve to a different provider.
To implement the warning I only consider the classic classes and classes with multiple inheritance. The code compare class MRO against hypothetical C3 MRO, and warn only when a real existing attribute would resolve to a different provider. It also warns when the hierarchy has no valid C3 linearization and would fail in python3.