Repository navigation
Conversation
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.
Fixes mypyc/mypyc#1242
An assignment to an attribute of a native class that has no
__setattr__is compiled to a direct write. The object can be an instance of a subclass that defines__setattr__, and then the method wasn't called:Now, if a subclass of the class defines
__setattr__, the assignment checks whether the type of the object overrides attribute assignment (tp_setattro). If it does, the value is set withPyObject_SetAttr, which calls__setattr__. Otherwise the attribute is written directly as before. Nothing changes for classes that have no subclass with__setattr__.I used a runtime check instead of always calling
PyObject_SetAttr, because that would make every such assignment 10 to 20 times slower for objects that have no__setattr__(about 2 ns to 26-47 ns per assignment in a loop). With the check, the difference for those objects is under 0.5 ns per assignment.