Repository navigation
Conversation
…ribute assumptions Signed-off-by: Sungmin Park <ryan040@korea.ac.kr>
This branch has not been deployed
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.
Description
Fixes #1342
LookupAttributeInMRONode.lookupConstantMROCachedgets its value fromfindAttrAndAssumptionInMRO, which stores the result in the MRO's final attribute assumption for the key. Every lookup of that key on the class shares it. A node created withcreateForLookupOfUnmanagedClassesskips the non-static bases, so its result can differ from a normal lookup, but it went through the same specialization and stored or read the same entry.__class__assignment uses such a node for__new__(CheckCompatibleForAssigmentNode). Afterobj.__class__ = C, the shared entry for__new__onCheldobject.__new__, and normal lookups returned it.C(arg)for a class with a non-default metatype (which gets__new__withPyObject_GetAttr) then calledobject.__new__with the argument and raisedTypeError. The other way round, aftertype.__getattribute__(C, "__new__"), the compatibility check readBase.__new__forCfrom the shared entry butobject.__new__forBase, andBase().__class__ = Craised "__class__assignment: 'C' object layout differs from 'Base'".AS-IS
TO-BE
(matching CPython)
Changes
lookupConstantMROCachedonly for nodes that do not skip non-static bases. Nodes that skip them use the slow path, whose caches belong to the node.test_class_assignment_keeps_new_lookuptotests/test_mro.py: after__class__assignment to a class with a non-default metatype,__new__lookups and instance creation keep finding the base's__new__, andtype.__getattribute__(D, "__new__")before an assignment does not make it fail. Each half fails on its own without the change. It passes on CPython 3.12, 3.13 and 3.14.Testing
mx buildon darwin-aarch64 (master 3176851), thenmx graalpytest test_mro(12 passed) and--taggedtest_descr(134 passed, 2 expected failures),test_abc(72),test_class(19) andtest_types(107). The reproducer in #1342 printsCfor all four rounds. Without the change, the new test fails at the firsttype.__getattribute__(C, "__new__").mx checkstyle --primaryandmx eclipseformat --primaryreport nothing.