import gc

class Replacement:
    def __init__(self, name, value):
        self.name = name
        self.value = value

    def __del__(self):
        globals()[self.name] = self.value

def dec(method):
    method.decorated = True
    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()
A.m.decorated

Traceback (most recent call last):
  File "tmp6.py", line 27, in <module>
    A.m.decorated
AttributeError: 'function' object has no attribute 'm'