import gc

class Replacement:
    def __init__(self, class_name, method):
        self.class_name = class_name
        self.method = method

    def __del__(self):

        cls = globals()[self.class_name]
        cls.attr = True

def dec(method):

    class_name = method.__qualname__.rsplit('.', maxsplit=1)[0]
    globals()[class_name] = Replacement(class_name, method)
    return method


class A:

    @dec
    def m(self):
        pass



gc.collect()
print(A.attr)