For an example of taboo runtime changes, suppose you have one module which operates on a tree of data, like converting to JSON, and another type of object within that tree which does not have a built-in serialization to JSON, like DateTime. (there is really no way to universally serialize a DateTime to JSON because JSON only supports strings arrays and objects, and representation of dates will be application-specific). Perl lets you temporarily inject a method into a class for the duration of a scope, in this case the TO_JSON method which the JSON module looks for:
sub export_as_json($data) {
local *DateTime::TO_JSON= sub($date) { $date->ymd };
JSON->new->convert_blessed->encode($data);
}
After that scope, the DateTime package is restored to normal, without a TO_JSON method. How would Python solve this problem?