Declare d as nonlocal. This will make the cell "writable" from within the inner function.
c works because you're mutating the object in-place, however Python's "implicit declaration" (assigning to a variable) always declares names in the local scope. So when you try to update a non-local or global variable, what happens instead is that a variable of the same name is declared as a function local.
The global and nonlocal statements override this implicit declaration, and instead declare that the variable(s) of the specified name(s) are respectively global to the module or in some enclosing function scope rather than local to the function. Assignments will then "carry over" to the proper scope rather than implicitly cause the declaration of a local variable.
canddattributes of this class. Then any method would be allowed to updatecanddwithout any "magic trick".