Skip to content

O06: what property actually is - #136

Merged
tamnd merged 1 commit into
mainfrom
o06-descriptors
Aug 31, 2026
Merged

O06: what property actually is#136
tamnd merged 1 commit into
mainfrom
o06-descriptors

Conversation

@tamnd

@tamnd tamnd commented Aug 31, 2026

Copy link
Copy Markdown
Owner

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. staticmethod is six lines that hand the callable back. classmethod is eight that call the same PyMethod_New a plain function does, with the class instead of the instance. func_descr_get is seven, and it is where self comes from. property is 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:

  • a descriptor written by hand, so you can watch __get__, __set__ and __set_name__ get called
  • PyDescr_IsData, the one line that asks whether tp_descr_set is non null, and the whole precedence rule falling out of it
  • functions as non data descriptors, raw.__get__(g, Greeter) doing by hand what the dot does, and a fresh bound method on every read
  • classmethod binding to the class the lookup started from, which is why Sub.cm() gets Sub
  • a property with a value sitting in the instance dict being ignored, and the two error messages that name which of the three functions is missing
  • the five descriptor types C code builds, which two of them are data descriptors, and the type check descr_setcheck does before writing at a fixed offset
  • a descriptor in an instance dict doing nothing, and the branch in _PyObject_GenericGetAttrWithDict that explains why
  • type_new_set_names walking a copy of the class dict, and the descriptor added after the class statement that never learns its name

Sixteen citations, all resolving against the pin. Six diagrams, all under 950 px. Two new glossary terms, descriptor and bound method, which brings GLOSSARY.md to 118.

Checked with the full just check and with just versions.

@tamnd tamnd added kind/lesson A chapter: prose, notebook, experiments, boss fight area/objects The object model, types, slots and the builtin types labels Aug 31, 2026
@tamnd
tamnd merged commit 136aa00 into main Aug 31, 2026
16 checks passed
@tamnd
tamnd deleted the o06-descriptors branch August 31, 2026 17:05
@tamnd tamnd mentioned this pull request Aug 31, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/objects The object model, types, slots and the builtin types kind/lesson A chapter: prose, notebook, experiments, boss fight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant