O06: what property actually is - #136
Merged
Merged
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.
O06, the sixth lesson of the object model part. O05 said a data descriptor beats the instance dict and left it at that. This one says what a descriptor is.
The angle is that four things people learn as four separate features are one protocol, and three of them are under ten lines of C.
staticmethodis six lines that hand the callable back.classmethodis eight that call the samePyMethod_Newa plain function does, with the class instead of the instance.func_descr_getis seven, and it is whereselfcomes from.propertyis the long one at about thirty, and most of that is error messages.Thirteen code cells, all of them run identically on 3.14, on 3.15.0rc1 and on Pyodide 3.14.2, so the only version note in the lesson is the banner.
What it covers:
__get__,__set__and__set_name__get calledPyDescr_IsData, the one line that asks whethertp_descr_setis non null, and the whole precedence rule falling out of itraw.__get__(g, Greeter)doing by hand what the dot does, and a fresh bound method on every readclassmethodbinding to the class the lookup started from, which is whySub.cm()getsSubdescr_setcheckdoes before writing at a fixed offset_PyObject_GenericGetAttrWithDictthat explains whytype_new_set_nameswalking a copy of the class dict, and the descriptor added after the class statement that never learns its nameSixteen citations, all resolving against the pin. Six diagrams, all under 950 px. Two new glossary terms,
descriptorandbound method, which brings GLOSSARY.md to 118.Checked with the full
just checkand withjust versions.