Pixel with __slots__ = ('x', 'y') and a constructor setting both. Slots remove the per-instance __dict__ (saving memory across millions of instances) and make assigning any *other* attribute raise AttributeError — write try_extra(pixel) returning 'rejected' when setting pixel.z = 1 fails.try_extra(Pixel(1, 2))
'rejected'
z is not in __slots__, so assignment raises.
Slots are declared in the class body as a tuple of names.
try/except AttributeError around the assignment.