Your audit proxy, view, logs every read of the desk’s settings, and it forwards with Reflect.get(target, key, receiver). So far you’ve passed the receiver along on trust. Now the team’s Python class has one more piece to port, a label that isn’t stored anymore. During the port, label is a plain alias for level, so every label read is really a level read.
If the audit logs label but misses the level read inside it, the log says nobody touched level. In this lesson, you’ll see which object a getter runs on when a proxy forwards a read and why the receiver keeps that read inside the audit.
Follow a Getter Past the Audit
The Python class audits its instances with __getattribute__(), which runs on every attribute read you write out, such as self.level. The label property is a descriptor whose getter reads self.level:
class Settings:
def __init__(self):
self.level = 2
@property
def label(self):
return self.level
def __getattribute__(self, name):
print("read:", name)
return super().__getattribute__(name)
settings = Settings()
print(settings.label)
Reading settings.label logs two reads before the value:
read: label
read: level
2
Python hands the property the object the lookup started on, so inside the getter self is settings, and self.level passes through __getattribute__() a second time.
In JavaScript, get label() in an object literal defines a getter. Reading .label runs the function. Much like self, this inside it is the object you read .label through, the one before the dot or bracket. The receiver looks like baggage. super().__getattribute__(name) takes only the name because super() already carries self, and target[key] returns the same 2 for level. So a Pythonista’s port drops the receiver:
const settings = {
level: 2,
get label() {
return this.level;
},
};
const view = new Proxy(settings, {
get(target, key) {
console.log("read:", key);
return target[key];
},
});
console.log(view.label);
The getter reads this.level. Does that inner read reach the trap? Predict how many read: lines appear before the 2, then run it:
read: label
2
Only label is logged. target[key] reads .label through target, so the getter runs with this set to target. Its this.level reads the target directly and never passes through the proxy. Two-argument Reflect.get(target, key) logs the same single line for the same reason.
Pass the Receiver Along
The trap’s third parameter, the receiver, is the object the read goes through, here view. Reflect.get() takes it as an optional third argument and uses it as this whenever the property turns out to be a getter. Restore it:
const settings = {
level: 2,
get label() {
return this.level;
},
};
const view = new Proxy(settings, {
get(target, key, receiver) {
console.log("read:", key);
return Reflect.get(target, key, receiver);
},
});
console.log(view.label);
Now the audit logs both keys:
read: label
read: level
2
Trace the two lines. view.label starts at the proxy, so the trap logs label and calls Reflect.get() with view as the receiver. Reflect.get() finds the getter on the target and runs it with this set to view. So this.level is a read on the proxy, the trap runs again and logs level, and only then does 2 come back.
Python got both reads for free because its audit lives on the class, so the getter runs on the audited object itself. A proxy is a separate wrapper, and a Python wrapper that forwards with getattr(self._target, name) misses level the same way. The receiver gives the proxy what that wrapper lacks: a way to run the getter on the wrapper instead of the target.
That’s why you declare all three parameters in a get trap and forward with Reflect.get(target, key, receiver) by default. Plain values come back unchanged. Getters run on the receiver, which is view whenever the read starts there, so their this reads reach the audit. A getter that names settings directly still skips it.
Know Where the Receiver Stops
The receiver doesn’t make a proxy a stand-in for every object. This is a glimpse beyond the course’s flat settings.
A class can declare a private field with a leading #, such as #level. Unlike Python’s _level or __level, which are ordinary attributes under another name, it isn’t a property: it stays on the object it was created on, and a proxy never shares it.
Built-ins such as Map keep their entries in internal slots, hidden storage tied to the real object. A getter or method that needs that data throws a TypeError when this is the proxy.
For such getters, you can pass target as Reflect.get()’s third argument, accepting that their inner reads skip the audit. Methods still fail because a method call takes its this from the call, not from the trap. Usually you leave such objects out of the proxy. The desk settings are a flat object literal, so receiver is right for every read.
In the next exercise, Audit a Derived Setting, you’ll get a fresh settings record with a retry count, a derived setting computed from it, and an audit that already keeps the receiver. Your task is to decide which reads belong in the team’s log.